mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #8482 from jfrazelle/8481-content-type-bump-v
Revert #8101 and #7886 (content-type:x-json-stream/line delimited json)
This commit is contained in:
commit
917529e45e
7 changed files with 6 additions and 93 deletions
|
@ -167,7 +167,7 @@ func (cli *DockerCli) streamHelper(method, path string, setRawTerminal bool, in
|
|||
return fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
||||
}
|
||||
|
||||
if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") || api.MatchesContentType(resp.Header.Get("Content-Type"), "application/x-json-stream") {
|
||||
if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") {
|
||||
return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.outFd, cli.isTerminalOut)
|
||||
}
|
||||
if stdout != nil || stderr != nil {
|
||||
|
|
|
@ -120,10 +120,6 @@ func writeJSON(w http.ResponseWriter, code int, v engine.Env) error {
|
|||
|
||||
func streamJSON(job *engine.Job, w http.ResponseWriter, flush bool) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if job.GetenvBool("lineDelim") {
|
||||
w.Header().Set("Content-Type", "application/x-json-stream")
|
||||
}
|
||||
|
||||
if flush {
|
||||
job.Stdout.Add(utils.NewWriteFlusher(w))
|
||||
} else {
|
||||
|
@ -301,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"))
|
||||
|
@ -993,9 +987,6 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
|
|||
}
|
||||
}
|
||||
|
||||
// This needs to be set before calls to streamJSON
|
||||
job.SetenvBool("lineDelim", version.GreaterThanOrEqualTo("1.15"))
|
||||
|
||||
if version.GreaterThanOrEqualTo("1.8") {
|
||||
job.SetenvBool("json", true)
|
||||
streamJSON(job, w, true)
|
||||
|
|
|
@ -275,7 +275,7 @@ func TestGetEvents(t *testing.T) {
|
|||
if !called {
|
||||
t.Fatal("handler was not called")
|
||||
}
|
||||
assertContentType(r, "application/x-json-stream", t)
|
||||
assertContentType(r, "application/json", t)
|
||||
var stdout_json struct {
|
||||
Since int
|
||||
Until int
|
||||
|
|
|
@ -41,22 +41,6 @@ You can still call an old version of the API using
|
|||
|
||||
### What's new
|
||||
|
||||
`POST /build`
|
||||
`GET /events`
|
||||
|
||||
**New!**
|
||||
Now has header: `Content-Type: application/x-json-stream`.
|
||||
|
||||
`POST /containers/(id)/exec`
|
||||
|
||||
**New!**
|
||||
Setup an exec command in a running container `id`.
|
||||
|
||||
`POST /exec/(id)/start`
|
||||
|
||||
**New!**
|
||||
Start an exec command.
|
||||
|
||||
## v1.14
|
||||
|
||||
### Full Documentation
|
||||
|
@ -97,7 +81,7 @@ the `tag` parameter at the same time will return an error.
|
|||
The `HostConfig.Links` field is now filled correctly
|
||||
|
||||
**New!**
|
||||
`Sockets` parameter added to the `/info` endpoint listing all the sockets the
|
||||
`Sockets` parameter added to the `/info` endpoint listing all the sockets the
|
||||
daemon is configured to listen on.
|
||||
|
||||
`POST /containers/(name)/start`
|
||||
|
@ -425,7 +409,7 @@ Builder (/build):
|
|||
intermediary buffers
|
||||
- Simpler, less memory usage, less disk usage and faster
|
||||
|
||||
> **Warning**:
|
||||
> **Warning**:
|
||||
> The /build improvements are not reverse-compatible. Pre 1.3 clients will
|
||||
> break on /build.
|
||||
|
||||
|
|
|
@ -1082,7 +1082,7 @@ Build an image from Dockerfile via stdin
|
|||
**Example response**:
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/x-json-stream
|
||||
Content-Type: application/json
|
||||
|
||||
{"stream":"Step 1..."}
|
||||
{"stream":"..."}
|
||||
|
@ -1317,7 +1317,7 @@ and Docker images will report:
|
|||
**Example response**:
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/x-json-stream
|
||||
Content-Type: application/json
|
||||
|
||||
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
||||
{"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
Loading…
Reference in a new issue