Revert "Fix line delimited JSON response"

This reverts commit d2f75a3040.

Conflicts:
	integration-cli/docker_api_events_test.go

Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
Jessica Frazelle 2014-10-09 13:20:38 -07:00
parent 4c6b7cd1b5
commit b66ac6a809
4 changed files with 1 additions and 65 deletions

View file

@ -168,7 +168,7 @@ func (cli *DockerCli) streamHelper(method, path string, setRawTerminal bool, in
}
if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") {
return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.terminalFd, cli.isTerminal)
return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.outFd, cli.isTerminalOut)
}
if stdout != nil || stderr != nil {
// When TTY is ON, use regular copy

View file

@ -297,8 +297,6 @@ func getEvents(eng *engine.Engine, version version.Version, w http.ResponseWrite
}
var job = eng.Job("events")
// lineDelimited JSON events was added #7047
job.SetenvBool("lineDelim", version.GreaterThanOrEqualTo("1.15"))
streamJSON(job, w, true)
job.Setenv("since", r.Form.Get("since"))
job.Setenv("until", r.Form.Get("until"))

View file

@ -101,11 +101,6 @@ func writeEvent(job *engine.Job, event *utils.JSONMessage) error {
// When sending an event JSON serialization errors are ignored, but all
// other errors lead to the eviction of the listener.
if b, err := json.Marshal(event); err == nil {
if job.GetenvBool("lineDelim") {
b = append(b, []byte("\r\n")...)
}
if _, err = job.Stdout.Write(b); err != nil {
return err
}

View file

@ -1,57 +0,0 @@
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"testing"
"time"
)
func TestEventsApiGetLineDelim(t *testing.T) {
name := "testimageevents"
defer deleteImages(name)
_, err := buildImage(name,
`FROM scratch
MAINTAINER "docker"`,
true)
if err != nil {
t.Fatal(err)
}
if err := deleteImages(name); err != nil {
t.Fatal(err)
}
endpoint := fmt.Sprintf("/events?since=1&until=%d", time.Now().Unix())
body, err := sockRequest("GET", endpoint)
if err != nil {
t.Fatal(err)
}
linesRead := 0
scanner := bufio.NewScanner(bytes.NewReader(body))
for scanner.Scan() && linesRead < 2 {
line := scanner.Bytes()
if len(line) == 0 {
continue
}
// make sure line delimited json
res := make(map[string]interface{})
if err := json.Unmarshal(line, &res); err != nil {
t.Fatalf("Unmarshaling the line as JSON failed: %v", err)
}
linesRead++
}
if err := scanner.Err(); err != nil {
t.Fatalf("Scanner failed: %v", err)
}
if linesRead < 2 {
t.Fatalf("Only %d lines were read from the stream", linesRead)
}
logDone("events - test the api response is line delimited json")
}