forked from TrueCloudLab/distribution
Allow conditional fetching of manifests with the registry client.
Add a functional argument to pass a digest to (ManifestService).GetByTag().
If the digest matches an empty manifest and nil error are returned.
See 1bc740b0d5
for server implementation.
Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
This commit is contained in:
parent
79a4ca2abe
commit
48a2010ac3
6 changed files with 116 additions and 24 deletions
|
@ -21,8 +21,6 @@ type RequestResponseMapping struct {
|
|||
Response Response
|
||||
}
|
||||
|
||||
// TODO(bbland): add support for request headers
|
||||
|
||||
// Request is a simplified http.Request object
|
||||
type Request struct {
|
||||
// Method is the http method of the request, for example GET
|
||||
|
@ -36,6 +34,9 @@ type Request struct {
|
|||
|
||||
// Body is the byte contents of the http request
|
||||
Body []byte
|
||||
|
||||
// Headers are the header for this request
|
||||
Headers http.Header
|
||||
}
|
||||
|
||||
func (r Request) String() string {
|
||||
|
@ -54,7 +55,22 @@ func (r Request) String() string {
|
|||
}
|
||||
queryString = "?" + strings.Join(queryParts, "&")
|
||||
}
|
||||
return fmt.Sprintf("%s %s%s\n%s", r.Method, r.Route, queryString, r.Body)
|
||||
var headers []string
|
||||
if len(r.Headers) > 0 {
|
||||
var headerKeys []string
|
||||
for k := range r.Headers {
|
||||
headerKeys = append(headerKeys, k)
|
||||
}
|
||||
sort.Strings(headerKeys)
|
||||
|
||||
for _, k := range headerKeys {
|
||||
for _, val := range r.Headers[k] {
|
||||
headers = append(headers, fmt.Sprintf("%s:%s", k, val))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return fmt.Sprintf("%s %s%s\n%s\n%s", r.Method, r.Route, queryString, headers, r.Body)
|
||||
}
|
||||
|
||||
// Response is a simplified http.Response object
|
||||
|
@ -101,6 +117,14 @@ func (app *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
Route: r.URL.Path,
|
||||
QueryParams: r.URL.Query(),
|
||||
Body: requestBody,
|
||||
Headers: make(map[string][]string),
|
||||
}
|
||||
|
||||
// Add headers of interest here
|
||||
for k, v := range r.Header {
|
||||
if k == "Etag" {
|
||||
request.Headers[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
responses, ok := app.responseMap[request.String()]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue