Lock down HTTP API error codes
This commit locks down the set of http error codes that will be part of the inital V2 specification, proposed in docker/docker#9015. The naming order has been slightly changed and there are few tweaks to ensure all conditions are captured but this will be set the docker core will be impleemnted against. To support this, the errors have been moved into an api/errors package. A new type, ErrorDescriptor, has been defined to centralize the code, message and definitions used with each type. The information therein can be used to generate documentation and response code mappings (yet to come...). In addition to the refactoring that came along with this change, several tests have been added to ensure serialization round trips are reliable. This allows better support for using these error types on the client and server side. This is coupled with some tweaks in the client code to fix issues with error reporting. Other fixes in the client include moving client-specific errors out of the base package and ensuring that we have correct parameters for finishing uploads.
This commit is contained in:
parent
33d89b4bca
commit
7b56d10076
14 changed files with 716 additions and 514 deletions
|
@ -58,7 +58,8 @@ func TestPush(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
manifestBytes, err := json.Marshal(manifest)
|
||||
var err error
|
||||
manifest.Raw, err = json.Marshal(manifest)
|
||||
|
||||
blobRequestResponseMappings := make([]testutil.RequestResponseMapping, 2*len(testBlobs))
|
||||
for i, blob := range testBlobs {
|
||||
|
@ -94,13 +95,25 @@ func TestPush(t *testing.T) {
|
|||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Route: "/v2/" + name + "/manifest/" + tag,
|
||||
Body: manifestBytes,
|
||||
Body: manifest.Raw,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
},
|
||||
}))
|
||||
server := httptest.NewServer(handler)
|
||||
var server *httptest.Server
|
||||
|
||||
// HACK(stevvooe): Super hack to follow: the request response map approach
|
||||
// above does not let us correctly format the location header to the
|
||||
// server url. This handler intercepts and re-writes the location header
|
||||
// to the server url.
|
||||
|
||||
hack := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w = &headerInterceptingResponseWriter{ResponseWriter: w, serverURL: server.URL}
|
||||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
server = httptest.NewServer(hack)
|
||||
client := New(server.URL)
|
||||
objectStore := &memoryObjectStore{
|
||||
mutex: new(sync.Mutex),
|
||||
|
@ -370,3 +383,19 @@ func TestPullResume(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// headerInterceptingResponseWriter is a hacky workaround to re-write the
|
||||
// location header to have the server url.
|
||||
type headerInterceptingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
serverURL string
|
||||
}
|
||||
|
||||
func (hirw *headerInterceptingResponseWriter) WriteHeader(status int) {
|
||||
location := hirw.Header().Get("Location")
|
||||
if location != "" {
|
||||
hirw.Header().Set("Location", hirw.serverURL+location)
|
||||
}
|
||||
|
||||
hirw.ResponseWriter.WriteHeader(status)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue