Browse code

Merge pull request #8101 from jfrazelle/6974-correct-ct-json-stream

Change content-type for json stream to application/x-json-stream.

Victor Vieux authored on 2014/09/24 03:24:31
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
... ...
@@ -1052,7 +1052,7 @@ Build an image from Dockerfile via stdin
1052 1052
 **Example response**:
1053 1053
 
1054 1054
         HTTP/1.1 200 OK
1055
-        Content-Type: application/json
1055
+        Content-Type: application/x-json-stream
1056 1056
 
1057 1057
         {"stream":"Step 1..."}
1058 1058
         {"stream":"..."}
... ...
@@ -1279,7 +1279,7 @@ via polling (using since)
1279 1279
 **Example response**:
1280 1280
 
1281 1281
         HTTP/1.1 200 OK
1282
-        Content-Type: application/json
1282
+        Content-Type: application/x-json-stream
1283 1283
 
1284 1284
         {"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
1285 1285
         {"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}