Browse code

client: Client.buildRequest: don't set content-header if not set

This function was setting `text/plain` as default content-type for any
request that had a non-nil body.

However, this would also set the content-type if (e.g.) `http.NoBody` was set,
or if an empty reader was used, which would result in the daemon potentialy
rejecting the request, as it validates request to be using `application/json`;
https://github.com/moby/moby/blob/d9ee22d1ab67c3dd88eb49dc9c0ff6f61a344f9d/daemon/server/httputils/httputils.go#L47-L58

=== RUN TestCommitInheritsEnv
commit_test.go:30: assertion failed: error is not nil: Error response from daemon: unsupported Content-Type header (text/plain): must be 'application/json'
--- FAIL: TestCommitInheritsEnv (0.02s)

This patch removes setting the default content-type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/11/15 07:43:40
Showing 2 changed files
... ...
@@ -110,9 +110,6 @@ func (cli *Client) buildRequest(ctx context.Context, method, path string, body i
110 110
 		req.Host = DummyHost
111 111
 	}
112 112
 
113
-	if body != nil && req.Header.Get("Content-Type") == "" {
114
-		req.Header.Set("Content-Type", "text/plain")
115
-	}
116 113
 	return req, nil
117 114
 }
118 115
 
... ...
@@ -110,9 +110,6 @@ func (cli *Client) buildRequest(ctx context.Context, method, path string, body i
110 110
 		req.Host = DummyHost
111 111
 	}
112 112
 
113
-	if body != nil && req.Header.Get("Content-Type") == "" {
114
-		req.Header.Set("Content-Type", "text/plain")
115
-	}
116 113
 	return req, nil
117 114
 }
118 115