mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Change content-type for json stream to application/x-json-stream.
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
parent
ac75835931
commit
10ab2089ce
5 changed files with 17 additions and 6 deletions
|
@ -167,7 +167,7 @@ func (cli *DockerCli) streamHelper(method, path string, setRawTerminal bool, in
|
||||||
return fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
return fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") {
|
if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") || api.MatchesContentType(resp.Header.Get("Content-Type"), "application/x-json-stream") {
|
||||||
return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.terminalFd, cli.isTerminal)
|
return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.terminalFd, cli.isTerminal)
|
||||||
}
|
}
|
||||||
if stdout != nil || stderr != nil {
|
if stdout != nil || stderr != nil {
|
||||||
|
|
|
@ -102,6 +102,10 @@ func writeJSON(w http.ResponseWriter, code int, v engine.Env) error {
|
||||||
|
|
||||||
func streamJSON(job *engine.Job, w http.ResponseWriter, flush bool) {
|
func streamJSON(job *engine.Job, w http.ResponseWriter, flush bool) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if job.GetenvBool("lineDelim") {
|
||||||
|
w.Header().Set("Content-Type", "application/x-json-stream")
|
||||||
|
}
|
||||||
|
|
||||||
if flush {
|
if flush {
|
||||||
job.Stdout.Add(utils.NewWriteFlusher(w))
|
job.Stdout.Add(utils.NewWriteFlusher(w))
|
||||||
} else {
|
} else {
|
||||||
|
@ -976,6 +980,7 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
|
||||||
job.Setenv("q", r.FormValue("q"))
|
job.Setenv("q", r.FormValue("q"))
|
||||||
job.Setenv("nocache", r.FormValue("nocache"))
|
job.Setenv("nocache", r.FormValue("nocache"))
|
||||||
job.Setenv("forcerm", r.FormValue("forcerm"))
|
job.Setenv("forcerm", r.FormValue("forcerm"))
|
||||||
|
job.SetenvBool("lineDelim", version.GreaterThanOrEqualTo("1.15"))
|
||||||
job.SetenvJson("authConfig", authConfig)
|
job.SetenvJson("authConfig", authConfig)
|
||||||
job.SetenvJson("configFile", configFile)
|
job.SetenvJson("configFile", configFile)
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ func TestGetEvents(t *testing.T) {
|
||||||
if !called {
|
if !called {
|
||||||
t.Fatal("handler was not called")
|
t.Fatal("handler was not called")
|
||||||
}
|
}
|
||||||
assertContentType(r, "application/json", t)
|
assertContentType(r, "application/x-json-stream", t)
|
||||||
var stdout_json struct {
|
var stdout_json struct {
|
||||||
Since int
|
Since int
|
||||||
Until int
|
Until int
|
||||||
|
|
|
@ -37,6 +37,12 @@ You can still call an old version of the API using
|
||||||
|
|
||||||
### What's new
|
### What's new
|
||||||
|
|
||||||
|
`POST /build`
|
||||||
|
`GET /events`
|
||||||
|
|
||||||
|
**New!**
|
||||||
|
Now has header: `Content-Type: application/x-json-stream`.
|
||||||
|
|
||||||
## v1.14
|
## v1.14
|
||||||
|
|
||||||
### Full Documentation
|
### Full Documentation
|
||||||
|
|
|
@ -1093,7 +1093,7 @@ Build an image from Dockerfile via stdin
|
||||||
**Example response**:
|
**Example response**:
|
||||||
|
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Content-Type: application/json
|
Content-Type: application/x-json-stream
|
||||||
|
|
||||||
{"stream":"Step 1..."}
|
{"stream":"Step 1..."}
|
||||||
{"stream":"..."}
|
{"stream":"..."}
|
||||||
|
@ -1328,7 +1328,7 @@ via polling (using since)
|
||||||
**Example response**:
|
**Example response**:
|
||||||
|
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Content-Type: application/json
|
Content-Type: application/x-json-stream
|
||||||
|
|
||||||
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
||||||
{"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
{"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
|
||||||
|
|
Loading…
Add table
Reference in a new issue