Skip to content
Snippets Groups Projects
Unverified Commit 15b02047 authored by Luca Bruno's avatar Luca Bruno Committed by Luca Bruno
Browse files

registry: fix binary JSON content-type

This fixes registry endpoints to return the proper `application/json`
content-type for JSON content, also updating spec examples for that.

As per IETF specification and IANA registry [0], the `application/json`
type is a binary media, so the content-type label does not need any
text-charset selector. Additionally, the media type definition
explicitly states that it has no required nor optional parameters,
which makes the current registry headers non-compliant.

[0]: https://www.iana.org/assignments/media-types/application/json



Signed-off-by: default avatarLuca Bruno <lucab@debian.org>
parent 91b0f055
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -133,7 +133,7 @@ to the 1.0 registry. Requests from newer clients will route to the 2.0 registry.
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Content-Type: application/json
< Docker-Distribution-Api-Version: registry/2.0
< Date: Tue, 14 Apr 2015 22:34:13 GMT
< Content-Length: 39
Loading
Loading
This diff is collapsed.
Loading
Loading
@@ -60,7 +60,7 @@ return this response:
 
```
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Docker-Distribution-Api-Version: registry/2.0
Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:samalba/my-app:pull,push"
Date: Thu, 10 Sep 2015 19:32:31 GMT
Loading
Loading
Loading
Loading
@@ -291,7 +291,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m
}
}
 
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", fmt.Sprint(len(p)))
w.WriteHeader(status)
if _, err := w.Write(p); err != nil {
Loading
Loading
Loading
Loading
@@ -9,7 +9,7 @@ import (
// and sets the content-type header to 'application/json'. It will handle
// ErrorCoder and Errors, and if necessary will create an envelope.
func ServeJSON(w http.ResponseWriter, err error) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
var sc int
 
switch errs := err.(type) {
Loading
Loading
Loading
Loading
@@ -126,7 +126,7 @@ var (
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -147,7 +147,7 @@ var (
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -168,7 +168,7 @@ var (
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -189,7 +189,7 @@ var (
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -441,7 +441,7 @@ var routeDescriptors = []RouteDescriptor{
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: `{
"name": <name>,
"tags": [
Loading
Loading
@@ -478,7 +478,7 @@ var routeDescriptors = []RouteDescriptor{
linkHeader,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: `{
"name": <name>,
"tags": [
Loading
Loading
@@ -541,7 +541,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeTagInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -592,7 +592,7 @@ var routeDescriptors = []RouteDescriptor{
Description: "The received manifest was invalid in some way, as described by the error codes. The client should resolve the issue and retry the request.",
StatusCode: http.StatusBadRequest,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -615,7 +615,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: `{
"errors:" [{
"code": "BLOB_UNKNOWN",
Loading
Loading
@@ -669,7 +669,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeTagInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -686,7 +686,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeManifestUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -766,7 +766,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeDigestInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -774,7 +774,7 @@ var routeDescriptors = []RouteDescriptor{
Description: "The blob, identified by `name` and `digest`, is unknown to the registry.",
StatusCode: http.StatusNotFound,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -838,7 +838,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeDigestInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -849,7 +849,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -905,7 +905,7 @@ var routeDescriptors = []RouteDescriptor{
Description: "The blob, identified by `name` and `digest`, is unknown to the registry.",
StatusCode: http.StatusNotFound,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -917,7 +917,7 @@ var routeDescriptors = []RouteDescriptor{
Description: "Blob delete is not allowed because the registry is configured as a pull-through cache or `delete` has been disabled",
StatusCode: http.StatusMethodNotAllowed,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
ErrorCodes: []errcode.ErrorCode{
Loading
Loading
@@ -1179,7 +1179,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1190,7 +1190,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1254,7 +1254,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1265,7 +1265,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1336,7 +1336,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1347,7 +1347,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1431,7 +1431,7 @@ var routeDescriptors = []RouteDescriptor{
errcode.ErrorCodeUnsupported,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1442,7 +1442,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1488,7 +1488,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1499,7 +1499,7 @@ var routeDescriptors = []RouteDescriptor{
ErrorCodeBlobUploadUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: errorsBody,
},
},
Loading
Loading
@@ -1539,7 +1539,7 @@ var routeDescriptors = []RouteDescriptor{
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: `{
"repositories": [
<name>,
Loading
Loading
@@ -1558,7 +1558,7 @@ var routeDescriptors = []RouteDescriptor{
{
StatusCode: http.StatusOK,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
ContentType: "application/json",
Format: `{
"repositories": [
<name>,
Loading
Loading
Loading
Loading
@@ -80,7 +80,7 @@ func addTestFetch(repo string, dgst digest.Digest, content []byte, m *testutil.R
func addTestCatalog(route string, content []byte, link string, m *testutil.RequestResponseMap) {
headers := map[string][]string{
"Content-Length": {strconv.Itoa(len(content))},
"Content-Type": {"application/json; charset=utf-8"},
"Content-Type": {"application/json"},
}
if link != "" {
headers["Link"] = append(headers["Link"], link)
Loading
Loading
@@ -1062,7 +1062,7 @@ func TestObtainsErrorForMissingTag(t *testing.T) {
StatusCode: http.StatusNotFound,
Body: errBytes,
Headers: http.Header(map[string][]string{
"Content-Type": {"application/json; charset=utf-8"},
"Content-Type": {"application/json"},
}),
},
})
Loading
Loading
Loading
Loading
@@ -65,7 +65,7 @@ func TestCheckAPI(t *testing.T) {
 
checkResponse(t, "issuing api base check", resp, http.StatusOK)
checkHeaders(t, resp, http.Header{
"Content-Type": []string{"application/json; charset=utf-8"},
"Content-Type": []string{"application/json"},
"Content-Length": []string{"2"},
})
 
Loading
Loading
@@ -259,7 +259,7 @@ func TestURLPrefix(t *testing.T) {
 
checkResponse(t, "issuing api base check", resp, http.StatusOK)
checkHeaders(t, resp, http.Header{
"Content-Type": []string{"application/json; charset=utf-8"},
"Content-Type": []string{"application/json"},
"Content-Length": []string{"2"},
})
}
Loading
Loading
@@ -1180,7 +1180,7 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name
// charset.
resp = putManifest(t, "re-putting signed manifest", manifestDigestURL, schema1.MediaTypeSignedManifest, sm2)
checkResponse(t, "re-putting signed manifest", resp, http.StatusCreated)
resp = putManifest(t, "re-putting signed manifest", manifestDigestURL, "application/json; charset=utf-8", sm2)
resp = putManifest(t, "re-putting signed manifest", manifestDigestURL, "application/json", sm2)
checkResponse(t, "re-putting signed manifest", resp, http.StatusCreated)
resp = putManifest(t, "re-putting signed manifest", manifestDigestURL, "application/json", sm2)
checkResponse(t, "re-putting signed manifest", resp, http.StatusCreated)
Loading
Loading
@@ -2329,7 +2329,7 @@ func checkBodyHasErrorCodes(t *testing.T, msg string, resp *http.Response, error
 
// TODO(stevvooe): Shoot. The error setup is not working out. The content-
// type headers are being set after writing the status code.
// if resp.Header.Get("Content-Type") != "application/json; charset=utf-8" {
// if resp.Header.Get("Content-Type") != "application/json" {
// t.Fatalf("unexpected content type: %v != 'application/json'",
// resp.Header.Get("Content-Type"))
// }
Loading
Loading
Loading
Loading
@@ -898,7 +898,7 @@ func (app *App) nameRequired(r *http.Request) bool {
func apiBase(w http.ResponseWriter, r *http.Request) {
const emptyJSON = "{}"
// Provide a simple /v2/ 200 OK response with empty json response.
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", fmt.Sprint(len(emptyJSON)))
 
fmt.Fprint(w, emptyJSON)
Loading
Loading
Loading
Loading
@@ -188,8 +188,8 @@ func TestNewApp(t *testing.T) {
t.Fatalf("unexpected status code during request: %v", err)
}
 
if req.Header.Get("Content-Type") != "application/json; charset=utf-8" {
t.Fatalf("unexpected content-type: %v != %v", req.Header.Get("Content-Type"), "application/json; charset=utf-8")
if req.Header.Get("Content-Type") != "application/json" {
t.Fatalf("unexpected content-type: %v != %v", req.Header.Get("Content-Type"), "application/json")
}
 
expectedAuthHeader := "Bearer realm=\"realm-test\",service=\"service-test\""
Loading
Loading
Loading
Loading
@@ -55,7 +55,7 @@ func (ch *catalogHandler) GetCatalog(w http.ResponseWriter, r *http.Request) {
return
}
 
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
 
// Add a link header if there are more entries to retrieve
if moreEntries {
Loading
Loading
Loading
Loading
@@ -49,7 +49,7 @@ func (th *tagsHandler) GetTags(w http.ResponseWriter, r *http.Request) {
return
}
 
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
 
enc := json.NewEncoder(w)
if err := enc.Encode(tagsAPIResponse{
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment