Browse code

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)

Jessica Frazelle authored on 2014/09/18 09:53:04
Showing 5 changed files
... ...
@@ -167,7 +167,7 @@ func (cli *DockerCli) streamHelper(method, path string, setRawTerminal bool, in
167 167
 		return fmt.Errorf("Error: %s", bytes.TrimSpace(body))
168 168
 	}
169 169
 
170
-	if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") {
170
+	if api.MatchesContentType(resp.Header.Get("Content-Type"), "application/json") || api.MatchesContentType(resp.Header.Get("Content-Type"), "application/x-json-stream") {
171 171
 		return utils.DisplayJSONMessagesStream(resp.Body, stdout, cli.terminalFd, cli.isTerminal)
172 172
 	}
173 173
 	if stdout != nil || stderr != nil {
... ...
@@ -102,6 +102,10 @@ func writeJSON(w http.ResponseWriter, code int, v engine.Env) error {
102 102
 
103 103
 func streamJSON(job *engine.Job, w http.ResponseWriter, flush bool) {
104 104
 	w.Header().Set("Content-Type", "application/json")
105
+	if job.GetenvBool("lineDelim") {
106
+		w.Header().Set("Content-Type", "application/x-json-stream")
107
+	}
108
+
105 109
 	if flush {
106 110
 		job.Stdout.Add(utils.NewWriteFlusher(w))
107 111
 	} else {
... ...
@@ -976,6 +980,7 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
976 976
 	job.Setenv("q", r.FormValue("q"))
977 977
 	job.Setenv("nocache", r.FormValue("nocache"))
978 978
 	job.Setenv("forcerm", r.FormValue("forcerm"))
979
+	job.SetenvBool("lineDelim", version.GreaterThanOrEqualTo("1.15"))
979 980
 	job.SetenvJson("authConfig", authConfig)
980 981
 	job.SetenvJson("configFile", configFile)
981 982
 
... ...
@@ -275,7 +275,7 @@ func TestGetEvents(t *testing.T) {
275 275
 	if !called {
276 276
 		t.Fatal("handler was not called")
277 277
 	}
278
-	assertContentType(r, "application/json", t)
278
+	assertContentType(r, "application/x-json-stream", t)
279 279
 	var stdout_json struct {
280 280
 		Since int
281 281
 		Until int
... ...
@@ -37,6 +37,12 @@ You can still call an old version of the API using
37 37
 
38 38
 ### What's new
39 39
 
40
+`POST /build`
41
+`GET /events`
42
+
43
+**New!**
44
+Now has header: `Content-Type: application/x-json-stream`.
45
+
40 46
 ## v1.14
41 47
 
42 48
 ### Full Documentation
... ...
@@ -77,7 +83,7 @@ the `tag` parameter at the same time will return an error.
77 77
 The `HostConfig.Links` field is now filled correctly
78 78
 
79 79
 **New!**
80
-`Sockets` parameter added to the `/info` endpoint listing all the sockets the 
80
+`Sockets` parameter added to the `/info` endpoint listing all the sockets the
81 81
 daemon is configured to listen on.
82 82
 
83 83
 `POST /containers/(name)/start`
... ...
@@ -405,7 +411,7 @@ Builder (/build):
405 405
    intermediary buffers
406 406
  - Simpler, less memory usage, less disk usage and faster
407 407
 
408
-> **Warning**: 
408
+> **Warning**:
409 409
 > The /build improvements are not reverse-compatible. Pre 1.3 clients will
410 410
 > break on /build.
411 411
 
... ...
@@ -1093,7 +1093,7 @@ Build an image from Dockerfile via stdin
1093 1093
 **Example response**:
1094 1094
 
1095 1095
         HTTP/1.1 200 OK
1096
-        Content-Type: application/json
1096
+        Content-Type: application/x-json-stream
1097 1097
 
1098 1098
         {"stream":"Step 1..."}
1099 1099
         {"stream":"..."}
... ...
@@ -1328,7 +1328,7 @@ via polling (using since)
1328 1328
 **Example response**:
1329 1329
 
1330 1330
         HTTP/1.1 200 OK
1331
-        Content-Type: application/json
1331
+        Content-Type: application/x-json-stream
1332 1332
 
1333 1333
         {"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
1334 1334
         {"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}