Merge pull request #3768 from thaJeztah/http_consts
use http consts for request methodspull/3770/head
commit
ebfa2a0ac0
|
@ -14,7 +14,7 @@ func TestWithRequest(t *testing.T) {
|
|||
var req http.Request
|
||||
|
||||
start := time.Now()
|
||||
req.Method = "GET"
|
||||
req.Method = http.MethodGet
|
||||
req.Host = "example.com"
|
||||
req.RequestURI = "/test-test"
|
||||
req.Header = make(http.Header)
|
||||
|
@ -253,7 +253,7 @@ func TestRemoteAddr(t *testing.T) {
|
|||
|
||||
// X-Forwarded-For set by proxy
|
||||
expectedRemote = "127.0.0.1"
|
||||
proxyReq, err := http.NewRequest("GET", frontend.URL, nil)
|
||||
proxyReq, err := http.NewRequest(http.MethodGet, frontend.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ func TestRemoteAddr(t *testing.T) {
|
|||
}
|
||||
|
||||
// RemoteAddr in X-Real-Ip
|
||||
getReq, err := http.NewRequest("GET", backend.URL, nil)
|
||||
getReq, err := http.NewRequest(http.MethodGet, backend.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@ func main() {
|
|||
}
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.Path("/token/").Methods("GET").Handler(handlerWithContext(ctx, ts.getToken))
|
||||
router.Path("/token/").Methods("POST").Handler(handlerWithContext(ctx, ts.postToken))
|
||||
router.Path("/token/").Methods(http.MethodGet).Handler(handlerWithContext(ctx, ts.getToken))
|
||||
router.Path("/token/").Methods(http.MethodPost).Handler(handlerWithContext(ctx, ts.postToken))
|
||||
|
||||
if cert == "" {
|
||||
err = http.ListenAndServe(addr, router)
|
||||
|
|
|
@ -13,7 +13,7 @@ var (
|
|||
|
||||
// DownHandler registers a manual_http_status that always returns an Error
|
||||
func DownHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
if r.Method == http.MethodPost {
|
||||
updater.Update(errors.New("manual Check"))
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
@ -22,7 +22,7 @@ func DownHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// UpHandler registers a manual_http_status that always returns nil
|
||||
func UpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "POST" {
|
||||
if r.Method == http.MethodPost {
|
||||
updater.Update(nil)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
func TestGETDownHandlerDoesNotChangeStatus(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", "https://fakeurl.com/debug/health/down", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "https://fakeurl.com/debug/health/down", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestGETDownHandlerDoesNotChangeStatus(t *testing.T) {
|
|||
func TestGETUpHandlerDoesNotChangeStatus(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", "https://fakeurl.com/debug/health/up", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "https://fakeurl.com/debug/health/up", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func TestGETUpHandlerDoesNotChangeStatus(t *testing.T) {
|
|||
func TestPOSTDownHandlerChangeStatus(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("POST", "https://fakeurl.com/debug/health/down", nil)
|
||||
req, err := http.NewRequest(http.MethodPost, "https://fakeurl.com/debug/health/down", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func TestPOSTDownHandlerChangeStatus(t *testing.T) {
|
|||
func TestPOSTUpHandlerChangeStatus(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("POST", "https://fakeurl.com/debug/health/up", nil)
|
||||
req, err := http.NewRequest(http.MethodPost, "https://fakeurl.com/debug/health/up", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func HTTPChecker(r string, statusCode int, timeout time.Duration, headers http.H
|
|||
client := http.Client{
|
||||
Timeout: timeout,
|
||||
}
|
||||
req, err := http.NewRequest("HEAD", r, nil)
|
||||
req, err := http.NewRequest(http.MethodHead, r, nil)
|
||||
if err != nil {
|
||||
return errors.New("error creating request: " + r)
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ func RegisterPeriodicThresholdFunc(name string, period time.Duration, threshold
|
|||
// and their corresponding status.
|
||||
// Returns 503 if any Error status exists, 200 otherwise
|
||||
func StatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
if r.Method == http.MethodGet {
|
||||
checks := CheckStatus()
|
||||
status := http.StatusOK
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
func TestReturns200IfThereAreNoChecks(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", "https://fakeurl.com/debug/health", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "https://fakeurl.com/debug/health", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ func TestReturns200IfThereAreNoChecks(t *testing.T) {
|
|||
func TestReturns503IfThereAreErrorChecks(t *testing.T) {
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
req, err := http.NewRequest("GET", "https://fakeurl.com/debug/health", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "https://fakeurl.com/debug/health", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create request.")
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
func TestHTTPSink(t *testing.T) {
|
||||
serverHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
if r.Method != "POST" {
|
||||
if r.Method != http.MethodPost {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
t.Fatalf("unexpected request method: %v", r.Method)
|
||||
return
|
||||
|
|
|
@ -381,7 +381,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: `Base V2 API route. Typically, this can be used for lightweight version checks and to validate registry authentication.`,
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Check that the endpoint implements Docker Registry API V2.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -415,7 +415,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "Retrieve information about tags.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Fetch the tags under the repository identified by `name`.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -519,7 +519,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "Create, update, delete and retrieve manifests.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Fetch the manifest identified by `name` and `reference` where `reference` can be a tag or digest. A `HEAD` request can also be issued to this endpoint to obtain resource information without receiving all data.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -566,7 +566,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Description: "Put the manifest identified by `name` and `reference` where `reference` can be a tag or digest.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -654,7 +654,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Description: "Delete the manifest or tag identified by `name` and `reference` where `reference` can be a tag or digest. Note that a manifest can _only_ be deleted by digest.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -724,7 +724,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "Operations on blobs identified by `name` and `digest`. Used to fetch or delete layers by digest.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Retrieve the blob from the registry identified by `digest`. A `HEAD` request can also be issued to this endpoint to obtain resource information without receiving all data.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -878,7 +878,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Description: "Delete the blob identified by `name` and `digest`",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -958,7 +958,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "Initiate a blob upload. This endpoint can be used to create resumable uploads or monolithic uploads.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Description: "Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the `digest` parameter is present, the request body will be used to complete the upload in a single request.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -1151,7 +1151,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "Interact with blob uploads. Clients should never assemble URLs for this endpoint and should only take it through the `Location` header on related API requests. The `Location` header and its parameters should be preserved by clients, using the latest value returned via upload related API calls.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Retrieve status of upload identified by `uuid`. The primary purpose of this endpoint is to resolve the current status of a resumable upload.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -1215,7 +1215,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Description: "Upload a chunk of data for the specified upload.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -1376,7 +1376,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Description: "Complete the upload specified by `uuid`, optionally appending the body as the final chunk.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -1467,7 +1467,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
},
|
||||
},
|
||||
{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Description: "Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
@ -1532,7 +1532,7 @@ var routeDescriptors = []RouteDescriptor{
|
|||
Description: "List a set of available repositories in the local registry cluster. Does not provide any indication of what may be available upstream. Applications can only determine if a repository is available but not if it is not available.",
|
||||
Methods: []MethodDescriptor{
|
||||
{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Description: "Retrieve a sorted, json list of repositories available in the registry.",
|
||||
Requests: []RequestDescriptor{
|
||||
{
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestBasicAccessController(t *testing.T) {
|
|||
CheckRedirect: nil,
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", server.URL, nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, server.URL, nil)
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
|
@ -94,7 +94,7 @@ func TestBasicAccessController(t *testing.T) {
|
|||
|
||||
for i := 0; i < len(testUsers); i++ {
|
||||
userNumber = i
|
||||
req, err := http.NewRequest("GET", server.URL, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error allocating new request: %v", err)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func TestSillyAccessController(t *testing.T) {
|
|||
t.Fatalf("unexpected response status: %v != %v", resp.StatusCode, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", server.URL, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, server.URL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating new request: %v", err)
|
||||
}
|
||||
|
|
|
@ -342,7 +342,7 @@ func TestAccessController(t *testing.T) {
|
|||
}
|
||||
|
||||
// 1. Make a mock http.Request with no token.
|
||||
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
req, err := http.NewRequest(http.MethodGet, "http://example.com/foo", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func TestEndpointAuthorizeToken(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?scope=%s&service=%s", url.QueryEscape(scope1), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -119,7 +119,7 @@ func TestEndpointAuthorizeToken(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?scope=%s&service=%s", url.QueryEscape(scope2), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -134,7 +134,7 @@ func TestEndpointAuthorizeToken(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -164,7 +164,7 @@ func TestEndpointAuthorizeToken(t *testing.T) {
|
|||
transport1 := transport.NewTransport(nil, NewAuthorizer(challengeManager1, NewTokenHandler(nil, nil, repo1, "pull", "push")))
|
||||
client := &http.Client{Transport: transport1}
|
||||
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -197,7 +197,7 @@ func TestEndpointAuthorizeToken(t *testing.T) {
|
|||
transport2 := transport.NewTransport(nil, NewAuthorizer(challengeManager2, NewTokenHandler(nil, nil, repo2, "pull", "push")))
|
||||
client2 := &http.Client{Transport: transport2}
|
||||
|
||||
req, _ = http.NewRequest("GET", e2+"/v2/hello", nil)
|
||||
req, _ = http.NewRequest(http.MethodGet, e2+"/v2/hello", nil)
|
||||
resp, err = client2.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -219,7 +219,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/token",
|
||||
Body: []byte(fmt.Sprintf("client_id=registry-client&grant_type=refresh_token&refresh_token=%s&scope=%s&service=%s", refreshToken1, url.QueryEscape(scope1), service)),
|
||||
},
|
||||
|
@ -231,7 +231,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
{
|
||||
// In the future this test may fail and require using basic auth to get a different refresh token
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/token",
|
||||
Body: []byte(fmt.Sprintf("client_id=registry-client&grant_type=refresh_token&refresh_token=%s&scope=%s&service=%s", refreshToken1, url.QueryEscape(scope2), service)),
|
||||
},
|
||||
|
@ -242,7 +242,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/token",
|
||||
Body: []byte(fmt.Sprintf("client_id=registry-client&grant_type=refresh_token&refresh_token=%s&scope=%s&service=%s", refreshToken2, url.QueryEscape(scope2), service)),
|
||||
},
|
||||
|
@ -258,7 +258,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -293,7 +293,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
transport1 := transport.NewTransport(nil, NewAuthorizer(challengeManager1, NewTokenHandler(nil, creds, repo1, "pull", "push")))
|
||||
client := &http.Client{Transport: transport1}
|
||||
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -322,7 +322,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
transport2 := transport.NewTransport(nil, NewAuthorizer(challengeManager2, NewTokenHandler(nil, creds, repo2, "pull", "push")))
|
||||
client2 := &http.Client{Transport: transport2}
|
||||
|
||||
req, _ = http.NewRequest("GET", e2+"/v2/hello", nil)
|
||||
req, _ = http.NewRequest(http.MethodGet, e2+"/v2/hello", nil)
|
||||
resp, err = client2.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -352,7 +352,7 @@ func TestEndpointAuthorizeRefreshToken(t *testing.T) {
|
|||
transport3 := transport.NewTransport(nil, NewAuthorizer(challengeManager3, NewTokenHandler(nil, creds, repo2, "pull", "push")))
|
||||
client3 := &http.Client{Transport: transport3}
|
||||
|
||||
req, _ = http.NewRequest("GET", e3+"/v2/hello", nil)
|
||||
req, _ = http.NewRequest(http.MethodGet, e3+"/v2/hello", nil)
|
||||
resp, err = client3.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -370,7 +370,7 @@ func TestEndpointAuthorizeV2RefreshToken(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/token",
|
||||
Body: []byte(fmt.Sprintf("client_id=registry-client&grant_type=refresh_token&refresh_token=%s&scope=%s&service=%s", refreshToken1, url.QueryEscape(scope1), service)),
|
||||
},
|
||||
|
@ -386,7 +386,7 @@ func TestEndpointAuthorizeV2RefreshToken(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v1/search",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -430,7 +430,7 @@ func TestEndpointAuthorizeV2RefreshToken(t *testing.T) {
|
|||
transport1 := transport.NewTransport(nil, NewAuthorizer(challengeManager1, NewTokenHandlerWithOptions(tho)))
|
||||
client := &http.Client{Transport: transport1}
|
||||
|
||||
req, _ := http.NewRequest("GET", e+"/v1/search", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v1/search", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -456,7 +456,7 @@ func TestEndpointAuthorizeTokenBasic(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?account=%s&scope=%s&service=%s", username, url.QueryEscape(scope), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -476,7 +476,7 @@ func TestEndpointAuthorizeTokenBasic(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -505,7 +505,7 @@ func TestEndpointAuthorizeTokenBasic(t *testing.T) {
|
|||
transport1 := transport.NewTransport(nil, NewAuthorizer(challengeManager, NewTokenHandler(nil, creds, repo, "pull", "push"), NewBasicHandler(creds)))
|
||||
client := &http.Client{Transport: transport1}
|
||||
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -526,7 +526,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?account=%s&scope=%s&service=%s", username, url.QueryEscape(scope), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -536,7 +536,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?account=%s&scope=%s&service=%s", username, url.QueryEscape(scope), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -558,7 +558,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -567,7 +567,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -576,7 +576,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -585,7 +585,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -594,7 +594,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -640,7 +640,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
// Subsequent calls should recycle the token from the first request, until the expiration has lapsed.
|
||||
timeIncrement := 1000 * time.Second
|
||||
for i := 0; i < 4; i++ {
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -655,7 +655,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresIn(t *testing.T) {
|
|||
}
|
||||
|
||||
// After we've exceeded the expiration, we should see a second token exchange.
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -686,7 +686,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
tokenMap := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?account=%s&scope=%s&service=%s", username, url.QueryEscape(scope), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -696,7 +696,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: fmt.Sprintf("/token?account=%s&scope=%s&service=%s", username, url.QueryEscape(scope), service),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -718,7 +718,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -727,7 +727,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -736,7 +736,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -745,7 +745,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -792,7 +792,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
// We shaved one increment off of the equivalent logic in TestEndpointAuthorizeTokenBasicWithExpiresIn
|
||||
// so this loop should have one fewer iteration.
|
||||
for i := 0; i < 3; i++ {
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -807,7 +807,7 @@ func TestEndpointAuthorizeTokenBasicWithExpiresInAndIssuedAt(t *testing.T) {
|
|||
}
|
||||
|
||||
// After we've exceeded the expiration, we should see a second token exchange.
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
@ -824,7 +824,7 @@ func TestEndpointAuthorizeBasic(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/hello",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -854,7 +854,7 @@ func TestEndpointAuthorizeBasic(t *testing.T) {
|
|||
transport1 := transport.NewTransport(nil, NewAuthorizer(challengeManager, NewBasicHandler(creds)))
|
||||
client := &http.Client{Transport: transport1}
|
||||
|
||||
req, _ := http.NewRequest("GET", e+"/v2/hello", nil)
|
||||
req, _ := http.NewRequest(http.MethodGet, e+"/v2/hello", nil)
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Error sending get request: %s", err)
|
||||
|
|
|
@ -38,7 +38,7 @@ func (hbu *httpBlobUpload) handleErrorResponse(resp *http.Response) error {
|
|||
}
|
||||
|
||||
func (hbu *httpBlobUpload) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, "PATCH", hbu.location, ioutil.NopCloser(r))
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, http.MethodPatch, hbu.location, ioutil.NopCloser(r))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (hbu *httpBlobUpload) ReadFrom(r io.Reader) (n int64, err error) {
|
|||
}
|
||||
|
||||
func (hbu *httpBlobUpload) Write(p []byte) (n int, err error) {
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, "PATCH", hbu.location, bytes.NewReader(p))
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, http.MethodPatch, hbu.location, bytes.NewReader(p))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ func (hbu *httpBlobUpload) StartedAt() time.Time {
|
|||
|
||||
func (hbu *httpBlobUpload) Commit(ctx context.Context, desc distribution.Descriptor) (distribution.Descriptor, error) {
|
||||
// TODO(dmcgowan): Check if already finished, if so just fetch
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, "PUT", hbu.location, nil)
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, http.MethodPut, hbu.location, nil)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func (hbu *httpBlobUpload) Commit(ctx context.Context, desc distribution.Descrip
|
|||
}
|
||||
|
||||
func (hbu *httpBlobUpload) Cancel(ctx context.Context) error {
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, "DELETE", hbu.location, nil)
|
||||
req, err := http.NewRequestWithContext(hbu.ctx, http.MethodDelete, hbu.location, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -37,7 +37,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test Valid case
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -53,7 +53,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test invalid range
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -69,7 +69,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test 404
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -80,7 +80,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test 400 valid json
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -101,7 +101,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test 400 invalid json
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -113,7 +113,7 @@ func TestUploadReadFrom(t *testing.T) {
|
|||
// Test 500
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -220,7 +220,7 @@ func TestUploadSize(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -232,7 +232,7 @@ func TestUploadSize(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: readFromLocationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -247,7 +247,7 @@ func TestUploadSize(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: writeLocationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -310,7 +310,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
m := testutil.RequestResponseMap([]testutil.RequestResponseMapping{
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -323,7 +323,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test Valid case
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -339,7 +339,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test invalid range
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -355,7 +355,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test 404
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -366,7 +366,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test 400 valid json
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -387,7 +387,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test 400 invalid json
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
@ -399,7 +399,7 @@ func TestUploadWrite(t *testing.T) {
|
|||
// Test 500
|
||||
{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: locationPath,
|
||||
Body: b,
|
||||
},
|
||||
|
|
|
@ -98,7 +98,7 @@ func (r *registry) Repositories(ctx context.Context, entries []string, last stri
|
|||
return 0, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ func (t *tags) All(ctx context.Context) ([]string, error) {
|
|||
}
|
||||
|
||||
for {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", listURL.String(), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, listURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -268,11 +268,11 @@ func descriptorFromResponse(response *http.Response) (distribution.Descriptor, e
|
|||
|
||||
digestHeader := headers.Get("Docker-Content-Digest")
|
||||
if digestHeader == "" {
|
||||
bytes, err := ioutil.ReadAll(response.Body)
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
_, desc, err := distribution.UnmarshalManifest(ctHeader, bytes)
|
||||
_, desc, err := distribution.UnmarshalManifest(ctHeader, data)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ func (t *tags) Get(ctx context.Context, tag string) (distribution.Descriptor, er
|
|||
return resp, err
|
||||
}
|
||||
|
||||
resp, err := newRequest("HEAD")
|
||||
resp, err := newRequest(http.MethodHead)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ func (t *tags) Get(ctx context.Context, tag string) (distribution.Descriptor, er
|
|||
// Issue a GET request:
|
||||
// - for data from a server that does not handle HEAD
|
||||
// - to get error details in case of a failure
|
||||
resp, err = newRequest("GET")
|
||||
resp, err = newRequest(http.MethodGet)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ func (t *tags) Untag(ctx context.Context, tag string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -405,7 +405,7 @@ func (ms *manifests) Exists(ctx context.Context, dgst digest.Digest) (bool, erro
|
|||
return false, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "HEAD", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, u, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ func (ms *manifests) Get(ctx context.Context, dgst digest.Digest, options ...dis
|
|||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ func (ms *manifests) Put(ctx context.Context, m distribution.Manifest, options .
|
|||
return "", err
|
||||
}
|
||||
|
||||
putRequest, err := http.NewRequestWithContext(ctx, "PUT", manifestURL, bytes.NewReader(p))
|
||||
putRequest, err := http.NewRequestWithContext(ctx, http.MethodPut, manifestURL, bytes.NewReader(p))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -620,7 +620,7 @@ func (ms *manifests) Delete(ctx context.Context, dgst digest.Digest) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -790,7 +790,7 @@ func (bs *blobs) Create(ctx context.Context, options ...distribution.BlobCreateO
|
|||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -873,7 +873,7 @@ func (bs *blobStatter) Stat(ctx context.Context, dgst digest.Digest) (distributi
|
|||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "HEAD", u, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodHead, u, nil)
|
||||
if err != nil {
|
||||
return distribution.Descriptor{}, err
|
||||
}
|
||||
|
@ -929,7 +929,7 @@ func (bs *blobStatter) Clear(ctx context.Context, dgst digest.Digest) error {
|
|||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, "DELETE", blobURL, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, blobURL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func newRandomBlob(size int) (digest.Digest, []byte) {
|
|||
func addTestFetch(repo string, dgst digest.Digest, content []byte, m *testutil.RequestResponseMap) {
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -66,7 +66,7 @@ func addTestFetch(repo string, dgst digest.Digest, content []byte, m *testutil.R
|
|||
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -91,7 +91,7 @@ func addTestCatalog(route string, content []byte, link string, m *testutil.Reque
|
|||
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: route,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -119,7 +119,7 @@ func TestBlobServeBlob(t *testing.T) {
|
|||
l := r.Blobs(ctx)
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
|
||||
err = l.ServeBlob(ctx, resp, req, dgst)
|
||||
if err != nil {
|
||||
|
@ -168,7 +168,7 @@ func TestBlobServeBlobHEAD(t *testing.T) {
|
|||
l := r.Blobs(ctx)
|
||||
|
||||
resp := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("HEAD", "/", nil)
|
||||
req := httptest.NewRequest(http.MethodHead, "/", nil)
|
||||
|
||||
err = l.ServeBlob(ctx, resp, req, dgst)
|
||||
if err != nil {
|
||||
|
@ -207,7 +207,7 @@ func TestBlobResume(t *testing.T) {
|
|||
repo, _ := reference.WithName("test.example.com/repo1")
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + id,
|
||||
Body: b1,
|
||||
},
|
||||
|
@ -221,7 +221,7 @@ func TestBlobResume(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + id,
|
||||
QueryParams: map[string][]string{
|
||||
"digest": {dgst.String()},
|
||||
|
@ -237,7 +237,7 @@ func TestBlobResume(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -295,7 +295,7 @@ func TestBlobDelete(t *testing.T) {
|
|||
repo, _ := reference.WithName("test.example.com/repo1")
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -356,7 +356,7 @@ func TestBlobExistsNoContentLength(t *testing.T) {
|
|||
dgst, content := newRandomBlob(1024)
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -371,7 +371,7 @@ func TestBlobExistsNoContentLength(t *testing.T) {
|
|||
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -447,7 +447,7 @@ func TestBlobUploadChunked(t *testing.T) {
|
|||
uuids := []string{uuid.Generate().String()}
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -466,7 +466,7 @@ func TestBlobUploadChunked(t *testing.T) {
|
|||
newOffset := offset + len(chunk)
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uuids[i],
|
||||
Body: chunk,
|
||||
},
|
||||
|
@ -484,7 +484,7 @@ func TestBlobUploadChunked(t *testing.T) {
|
|||
}
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uuids[len(uuids)-1],
|
||||
QueryParams: map[string][]string{
|
||||
"digest": {dgst.String()},
|
||||
|
@ -501,7 +501,7 @@ func TestBlobUploadChunked(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -562,7 +562,7 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
|||
uploadID := uuid.Generate().String()
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -577,7 +577,7 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uploadID,
|
||||
Body: b1,
|
||||
},
|
||||
|
@ -594,7 +594,7 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uploadID,
|
||||
QueryParams: map[string][]string{
|
||||
"digest": {dgst.String()},
|
||||
|
@ -611,7 +611,7 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -670,7 +670,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) {
|
|||
uploadID := uuid.Generate().String()
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -684,7 +684,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uploadID,
|
||||
Body: b1,
|
||||
},
|
||||
|
@ -700,7 +700,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/" + uploadID,
|
||||
QueryParams: map[string][]string{
|
||||
"digest": {dgst.String()},
|
||||
|
@ -717,7 +717,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -775,7 +775,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) {
|
|||
repo, _ := reference.WithName("test.example.com/uploadrepo")
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -789,7 +789,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PATCH",
|
||||
Method: http.MethodPatch,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
Body: b1,
|
||||
},
|
||||
|
@ -805,7 +805,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
QueryParams: map[string][]string{
|
||||
"digest": {dgst.String()},
|
||||
|
@ -822,7 +822,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -865,7 +865,7 @@ func TestBlobMount(t *testing.T) {
|
|||
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "POST",
|
||||
Method: http.MethodPost,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/uploads/",
|
||||
QueryParams: map[string][]string{"from": {sourceRepo.Name()}, "mount": {dgst.String()}},
|
||||
},
|
||||
|
@ -880,7 +880,7 @@ func TestBlobMount(t *testing.T) {
|
|||
})
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/blobs/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -958,7 +958,7 @@ func newRandomSchemaV1Manifest(name reference.Named, tag string, blobCount int)
|
|||
func addTestManifestWithEtag(repo reference.Named, reference string, content []byte, m *testutil.RequestResponseMap, dgst string) {
|
||||
actualDigest := digest.FromBytes(content)
|
||||
getReqWithEtag := testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + reference,
|
||||
Headers: http.Header(map[string][]string{
|
||||
"If-None-Match": {fmt.Sprintf(`"%s"`, dgst)},
|
||||
|
@ -1002,7 +1002,7 @@ func contentDigestString(mediatype string, content []byte) string {
|
|||
func addTestManifest(repo reference.Named, reference string, mediatype string, content []byte, m *testutil.RequestResponseMap) {
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + reference,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1018,7 +1018,7 @@ func addTestManifest(repo reference.Named, reference string, mediatype string, c
|
|||
})
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + reference,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1036,7 +1036,7 @@ func addTestManifest(repo reference.Named, reference string, mediatype string, c
|
|||
func addTestManifestWithoutDigestHeader(repo reference.Named, reference string, mediatype string, content []byte, m *testutil.RequestResponseMap) {
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + reference,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1051,7 +1051,7 @@ func addTestManifestWithoutDigestHeader(repo reference.Named, reference string,
|
|||
})
|
||||
*m = append(*m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "HEAD",
|
||||
Method: http.MethodHead,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + reference,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1265,7 +1265,7 @@ func TestManifestDelete(t *testing.T) {
|
|||
var m testutil.RequestResponseMap
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + dgst1.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1310,7 +1310,7 @@ func TestManifestPut(t *testing.T) {
|
|||
var m testutil.RequestResponseMap
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/other",
|
||||
Body: payload,
|
||||
},
|
||||
|
@ -1326,7 +1326,7 @@ func TestManifestPut(t *testing.T) {
|
|||
putDgst := digest.FromBytes(m1.Canonical)
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "PUT",
|
||||
Method: http.MethodPut,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + putDgst.String(),
|
||||
Body: payload,
|
||||
},
|
||||
|
@ -1379,7 +1379,7 @@ func TestManifestTags(t *testing.T) {
|
|||
for i := 0; i < 3; i++ {
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/tags/list",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1433,7 +1433,7 @@ func TestTagDelete(t *testing.T) {
|
|||
var m testutil.RequestResponseMap
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "DELETE",
|
||||
Method: http.MethodDelete,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + tag,
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1474,7 +1474,7 @@ func TestObtainsErrorForMissingTag(t *testing.T) {
|
|||
}
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/1.0.0",
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
@ -1578,7 +1578,7 @@ func TestManifestTagsPaginated(t *testing.T) {
|
|||
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/tags/list",
|
||||
QueryParams: queryParams,
|
||||
},
|
||||
|
@ -1628,7 +1628,7 @@ func TestManifestUnauthorized(t *testing.T) {
|
|||
|
||||
m = append(m, testutil.RequestResponseMapping{
|
||||
Request: testutil.Request{
|
||||
Method: "GET",
|
||||
Method: http.MethodGet,
|
||||
Route: "/v2/" + repo.Name() + "/manifests/" + dgst.String(),
|
||||
},
|
||||
Response: testutil.Response{
|
||||
|
|
|
@ -171,7 +171,7 @@ func (hrs *httpReadSeeker) reader() (io.Reader, error) {
|
|||
return hrs.rc, nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(hrs.ctx, "GET", hrs.url, nil)
|
||||
req, err := http.NewRequestWithContext(hrs.ctx, http.MethodGet, hrs.url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -613,7 +613,7 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|||
"Docker-Upload-UUID": []string{uploadUUID},
|
||||
})
|
||||
|
||||
req, err := http.NewRequest("DELETE", uploadURLBase, nil)
|
||||
req, err := http.NewRequest(http.MethodDelete, uploadURLBase, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating delete request: %v", err)
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|||
|
||||
// Matching etag, gives 304
|
||||
etag := resp.Header.Get("Etag")
|
||||
req, err = http.NewRequest("GET", layerURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, layerURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -800,7 +800,7 @@ func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|||
checkResponse(t, "fetching layer with etag", resp, http.StatusNotModified)
|
||||
|
||||
// Non-matching etag, gives 200
|
||||
req, err = http.NewRequest("GET", layerURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, layerURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -972,7 +972,7 @@ func TestStartPushReadOnly(t *testing.T) {
|
|||
}
|
||||
|
||||
func httpDelete(url string) (*http.Response, error) {
|
||||
req, err := http.NewRequest("DELETE", url, nil)
|
||||
req, err := http.NewRequest(http.MethodDelete, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1490,7 +1490,7 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name
|
|||
|
||||
// Get by name with etag, gives 304
|
||||
etag := resp.Header.Get("Etag")
|
||||
req, err := http.NewRequest("GET", manifestURL, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, manifestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1503,7 +1503,7 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name
|
|||
checkResponse(t, "fetching manifest by name with etag", resp, http.StatusNotModified)
|
||||
|
||||
// Get by digest with etag, gives 304
|
||||
req, err = http.NewRequest("GET", manifestDigestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1732,7 +1732,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
|
||||
// ------------------
|
||||
// Fetch by tag name
|
||||
req, err := http.NewRequest("GET", manifestURL, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, manifestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1767,7 +1767,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
|
||||
// ---------------
|
||||
// Fetch by digest
|
||||
req, err = http.NewRequest("GET", manifestDigestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1799,7 +1799,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
|
||||
// Get by name with etag, gives 304
|
||||
etag := resp.Header.Get("Etag")
|
||||
req, err = http.NewRequest("GET", manifestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1812,7 +1812,7 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name
|
|||
checkResponse(t, "fetching manifest by name with etag", resp, http.StatusNotModified)
|
||||
|
||||
// Get by digest with etag, gives 304
|
||||
req, err = http.NewRequest("GET", manifestDigestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -1992,7 +1992,7 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
|
|||
|
||||
// ------------------
|
||||
// Fetch by tag name
|
||||
req, err := http.NewRequest("GET", manifestURL, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, manifestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -2029,7 +2029,7 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
|
|||
|
||||
// ---------------
|
||||
// Fetch by digest
|
||||
req, err = http.NewRequest("GET", manifestDigestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -2061,7 +2061,7 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
|
|||
|
||||
// Get by name with etag, gives 304
|
||||
etag := resp.Header.Get("Etag")
|
||||
req, err = http.NewRequest("GET", manifestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -2074,7 +2074,7 @@ func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs)
|
|||
checkResponse(t, "fetching manifest by name with etag", resp, http.StatusNotModified)
|
||||
|
||||
// Get by digest with etag, gives 304
|
||||
req, err = http.NewRequest("GET", manifestDigestURL, nil)
|
||||
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing request: %s", err)
|
||||
}
|
||||
|
@ -2383,7 +2383,7 @@ func putManifest(t *testing.T, msg, url, contentType string, v interface{}) *htt
|
|||
}
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("PUT", url, bytes.NewReader(body))
|
||||
req, err := http.NewRequest(http.MethodPut, url, bytes.NewReader(body))
|
||||
if err != nil {
|
||||
t.Fatalf("error creating request for %s: %v", msg, err)
|
||||
}
|
||||
|
@ -2457,7 +2457,7 @@ func doPushLayer(t *testing.T, ub *v2.URLBuilder, name reference.Named, dgst dig
|
|||
uploadURL := u.String()
|
||||
|
||||
// Just do a monolithic upload
|
||||
req, err := http.NewRequest("PUT", uploadURL, body)
|
||||
req, err := http.NewRequest(http.MethodPut, uploadURL, body)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating new request: %v", err)
|
||||
}
|
||||
|
@ -2560,7 +2560,7 @@ func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader, options chu
|
|||
|
||||
uploadURL := u.String()
|
||||
|
||||
req, err := http.NewRequest("PATCH", uploadURL, body)
|
||||
req, err := http.NewRequest(http.MethodPatch, uploadURL, body)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error creating new request: %v", err)
|
||||
}
|
||||
|
|
|
@ -838,7 +838,7 @@ func (app *App) authorized(w http.ResponseWriter, r *http.Request, context *Cont
|
|||
if fromRepo := r.FormValue("from"); fromRepo != "" {
|
||||
// mounting a blob from one repository to another requires pull (GET)
|
||||
// access to the source repository.
|
||||
accessRecords = appendAccessRecords(accessRecords, "GET", fromRepo)
|
||||
accessRecords = appendAccessRecords(accessRecords, http.MethodGet, fromRepo)
|
||||
}
|
||||
} else {
|
||||
// Only allow the name not to be set on the base route.
|
||||
|
@ -927,13 +927,13 @@ func appendAccessRecords(records []auth.Access, method string, repo string) []au
|
|||
}
|
||||
|
||||
switch method {
|
||||
case "GET", "HEAD":
|
||||
case http.MethodGet, http.MethodHead:
|
||||
records = append(records,
|
||||
auth.Access{
|
||||
Resource: resource,
|
||||
Action: "pull",
|
||||
})
|
||||
case "POST", "PUT", "PATCH":
|
||||
case http.MethodPost, http.MethodPut, http.MethodPatch:
|
||||
records = append(records,
|
||||
auth.Access{
|
||||
Resource: resource,
|
||||
|
@ -943,7 +943,7 @@ func appendAccessRecords(records []auth.Access, method string, repo string) []au
|
|||
Resource: resource,
|
||||
Action: "push",
|
||||
})
|
||||
case "DELETE":
|
||||
case http.MethodDelete:
|
||||
records = append(records,
|
||||
auth.Access{
|
||||
Resource: resource,
|
||||
|
|
|
@ -235,42 +235,42 @@ func TestAppendAccessRecords(t *testing.T) {
|
|||
}
|
||||
|
||||
records := []auth.Access{}
|
||||
result := appendAccessRecords(records, "GET", repo)
|
||||
result := appendAccessRecords(records, http.MethodGet, repo)
|
||||
expectedResult := []auth.Access{expectedPullRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
}
|
||||
|
||||
records = []auth.Access{}
|
||||
result = appendAccessRecords(records, "HEAD", repo)
|
||||
result = appendAccessRecords(records, http.MethodHead, repo)
|
||||
expectedResult = []auth.Access{expectedPullRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
}
|
||||
|
||||
records = []auth.Access{}
|
||||
result = appendAccessRecords(records, "POST", repo)
|
||||
result = appendAccessRecords(records, http.MethodPost, repo)
|
||||
expectedResult = []auth.Access{expectedPullRecord, expectedPushRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
}
|
||||
|
||||
records = []auth.Access{}
|
||||
result = appendAccessRecords(records, "PUT", repo)
|
||||
result = appendAccessRecords(records, http.MethodPut, repo)
|
||||
expectedResult = []auth.Access{expectedPullRecord, expectedPushRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
}
|
||||
|
||||
records = []auth.Access{}
|
||||
result = appendAccessRecords(records, "PATCH", repo)
|
||||
result = appendAccessRecords(records, http.MethodPatch, repo)
|
||||
expectedResult = []auth.Access{expectedPullRecord, expectedPushRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
}
|
||||
|
||||
records = []auth.Access{}
|
||||
result = appendAccessRecords(records, "DELETE", repo)
|
||||
result = appendAccessRecords(records, http.MethodDelete, repo)
|
||||
expectedResult = []auth.Access{expectedDeleteRecord}
|
||||
if ok := reflect.DeepEqual(result, expectedResult); !ok {
|
||||
t.Fatalf("Actual access record differs from expected")
|
||||
|
|
|
@ -33,12 +33,12 @@ func blobDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
}
|
||||
|
||||
mhandler := handlers.MethodHandler{
|
||||
"GET": http.HandlerFunc(blobHandler.GetBlob),
|
||||
"HEAD": http.HandlerFunc(blobHandler.GetBlob),
|
||||
http.MethodGet: http.HandlerFunc(blobHandler.GetBlob),
|
||||
http.MethodHead: http.HandlerFunc(blobHandler.GetBlob),
|
||||
}
|
||||
|
||||
if !ctx.readOnly {
|
||||
mhandler["DELETE"] = http.HandlerFunc(blobHandler.DeleteBlob)
|
||||
mhandler[http.MethodDelete] = http.HandlerFunc(blobHandler.DeleteBlob)
|
||||
}
|
||||
|
||||
return mhandler
|
||||
|
|
|
@ -25,15 +25,15 @@ func blobUploadDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
}
|
||||
|
||||
handler := handlers.MethodHandler{
|
||||
"GET": http.HandlerFunc(buh.GetUploadStatus),
|
||||
"HEAD": http.HandlerFunc(buh.GetUploadStatus),
|
||||
http.MethodGet: http.HandlerFunc(buh.GetUploadStatus),
|
||||
http.MethodHead: http.HandlerFunc(buh.GetUploadStatus),
|
||||
}
|
||||
|
||||
if !ctx.readOnly {
|
||||
handler["POST"] = http.HandlerFunc(buh.StartBlobUpload)
|
||||
handler["PATCH"] = http.HandlerFunc(buh.PatchBlobData)
|
||||
handler["PUT"] = http.HandlerFunc(buh.PutBlobUploadComplete)
|
||||
handler["DELETE"] = http.HandlerFunc(buh.CancelBlobUpload)
|
||||
handler[http.MethodPost] = http.HandlerFunc(buh.StartBlobUpload)
|
||||
handler[http.MethodPatch] = http.HandlerFunc(buh.PatchBlobData)
|
||||
handler[http.MethodPut] = http.HandlerFunc(buh.PutBlobUploadComplete)
|
||||
handler[http.MethodDelete] = http.HandlerFunc(buh.CancelBlobUpload)
|
||||
}
|
||||
|
||||
if buh.UUID != "" {
|
||||
|
|
|
@ -21,7 +21,7 @@ func catalogDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
}
|
||||
|
||||
return handlers.MethodHandler{
|
||||
"GET": http.HandlerFunc(catalogHandler.GetCatalog),
|
||||
http.MethodGet: http.HandlerFunc(catalogHandler.GetCatalog),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ func TestHTTPHealthCheck(t *testing.T) {
|
|||
stopFailing := make(chan struct{})
|
||||
|
||||
checkedServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "HEAD" {
|
||||
if r.Method != http.MethodHead {
|
||||
t.Fatalf("expected HEAD request, got %s", r.Method)
|
||||
}
|
||||
select {
|
||||
|
|
|
@ -49,23 +49,23 @@ func manifestDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
manifestHandler := &manifestHandler{
|
||||
Context: ctx,
|
||||
}
|
||||
reference := getReference(ctx)
|
||||
dgst, err := digest.Parse(reference)
|
||||
ref := getReference(ctx)
|
||||
dgst, err := digest.Parse(ref)
|
||||
if err != nil {
|
||||
// We just have a tag
|
||||
manifestHandler.Tag = reference
|
||||
manifestHandler.Tag = ref
|
||||
} else {
|
||||
manifestHandler.Digest = dgst
|
||||
}
|
||||
|
||||
mhandler := handlers.MethodHandler{
|
||||
"GET": http.HandlerFunc(manifestHandler.GetManifest),
|
||||
"HEAD": http.HandlerFunc(manifestHandler.GetManifest),
|
||||
http.MethodGet: http.HandlerFunc(manifestHandler.GetManifest),
|
||||
http.MethodHead: http.HandlerFunc(manifestHandler.GetManifest),
|
||||
}
|
||||
|
||||
if !ctx.readOnly {
|
||||
mhandler["PUT"] = http.HandlerFunc(manifestHandler.PutManifest)
|
||||
mhandler["DELETE"] = http.HandlerFunc(manifestHandler.DeleteManifest)
|
||||
mhandler[http.MethodPut] = http.HandlerFunc(manifestHandler.PutManifest)
|
||||
mhandler[http.MethodDelete] = http.HandlerFunc(manifestHandler.DeleteManifest)
|
||||
}
|
||||
|
||||
return mhandler
|
||||
|
|
|
@ -19,7 +19,7 @@ func tagsDispatcher(ctx *Context, r *http.Request) http.Handler {
|
|||
}
|
||||
|
||||
return handlers.MethodHandler{
|
||||
"GET": http.HandlerFunc(tagsHandler.GetTags),
|
||||
http.MethodGet: http.HandlerFunc(tagsHandler.GetTags),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -337,7 +337,7 @@ func testProxyStoreServe(t *testing.T, te *testEnv, numClients int) {
|
|||
defer wg.Done()
|
||||
for _, remoteBlob := range te.inRemote {
|
||||
w := httptest.NewRecorder()
|
||||
r, err := http.NewRequest("GET", "", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "", nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -383,7 +383,7 @@ func testProxyStoreServe(t *testing.T, te *testEnv, numClients int) {
|
|||
// Serveblob - blobs come from local
|
||||
for _, dr := range te.inRemote {
|
||||
w := httptest.NewRecorder()
|
||||
r, err := http.NewRequest("GET", "", nil)
|
||||
r, err := http.NewRequest(http.MethodGet, "", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ func getObject(client *http.Client, bucket string, name string, offset int64) (*
|
|||
Host: "storage.googleapis.com",
|
||||
Path: fmt.Sprintf("/%s/%s", bucket, name),
|
||||
}
|
||||
req, err := http.NewRequest("GET", u.String(), nil)
|
||||
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -808,11 +808,11 @@ func (d *driver) URLFor(context context.Context, path string, options map[string
|
|||
}
|
||||
|
||||
name := d.pathToKey(path)
|
||||
methodString := "GET"
|
||||
methodString := http.MethodGet
|
||||
method, ok := options["method"]
|
||||
if ok {
|
||||
methodString, ok = method.(string)
|
||||
if !ok || (methodString != "GET" && methodString != "HEAD") {
|
||||
if !ok || (methodString != http.MethodGet && methodString != http.MethodHead) {
|
||||
return "", storagedriver.ErrUnsupportedMethod{}
|
||||
}
|
||||
}
|
||||
|
@ -849,7 +849,7 @@ func startSession(client *http.Client, bucket string, name string) (uri string,
|
|||
RawQuery: fmt.Sprintf("uploadType=resumable&name=%v", name),
|
||||
}
|
||||
err = retry(func() error {
|
||||
req, err := http.NewRequest("POST", u.String(), nil)
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -873,7 +873,7 @@ func startSession(client *http.Client, bucket string, name string) (uri string,
|
|||
func putChunk(client *http.Client, sessionURI string, chunk []byte, from int64, totalSize int64) (int64, error) {
|
||||
bytesPut := int64(0)
|
||||
err := retry(func() error {
|
||||
req, err := http.NewRequest("PUT", sessionURI, bytes.NewReader(chunk))
|
||||
req, err := http.NewRequest(http.MethodPut, sessionURI, bytes.NewReader(chunk))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -465,11 +465,11 @@ func (d *driver) Delete(ctx context.Context, path string) error {
|
|||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
methodString := "GET"
|
||||
methodString := http.MethodGet
|
||||
method, ok := options["method"]
|
||||
if ok {
|
||||
methodString, ok = method.(string)
|
||||
if !ok || (methodString != "GET") {
|
||||
if !ok || (methodString != http.MethodGet) {
|
||||
return "", storagedriver.ErrUnsupportedMethod{}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1005,11 +1005,11 @@ ListLoop:
|
|||
// URLFor returns a URL which may be used to retrieve the content stored at the given path.
|
||||
// May return an UnsupportedMethodErr in certain StorageDriver implementations.
|
||||
func (d *driver) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
|
||||
methodString := "GET"
|
||||
methodString := http.MethodGet
|
||||
method, ok := options["method"]
|
||||
if ok {
|
||||
methodString, ok = method.(string)
|
||||
if !ok || (methodString != "GET" && methodString != "HEAD") {
|
||||
if !ok || (methodString != http.MethodGet && methodString != http.MethodHead) {
|
||||
return "", storagedriver.ErrUnsupportedMethod{}
|
||||
}
|
||||
}
|
||||
|
@ -1026,12 +1026,12 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
|
|||
var req *request.Request
|
||||
|
||||
switch methodString {
|
||||
case "GET":
|
||||
case http.MethodGet:
|
||||
req, _ = d.S3.GetObjectRequest(&s3.GetObjectInput{
|
||||
Bucket: aws.String(d.Bucket),
|
||||
Key: aws.String(d.s3Path(path)),
|
||||
})
|
||||
case "HEAD":
|
||||
case http.MethodHead:
|
||||
req, _ = d.S3.HeadObjectRequest(&s3.HeadObjectInput{
|
||||
Bucket: aws.String(d.Bucket),
|
||||
Key: aws.String(d.s3Path(path)),
|
||||
|
|
|
@ -608,7 +608,7 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
|
|||
return "", storagedriver.ErrUnsupportedMethod{}
|
||||
}
|
||||
|
||||
methodString := "GET"
|
||||
methodString := http.MethodGet
|
||||
method, ok := options["method"]
|
||||
if ok {
|
||||
if methodString, ok = method.(string); !ok {
|
||||
|
@ -616,10 +616,10 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int
|
|||
}
|
||||
}
|
||||
|
||||
if methodString == "HEAD" {
|
||||
if methodString == http.MethodHead {
|
||||
// A "HEAD" request on a temporary URL is allowed if the
|
||||
// signature was generated with "GET", "POST" or "PUT"
|
||||
methodString = "GET"
|
||||
methodString = http.MethodGet
|
||||
}
|
||||
|
||||
supported := false
|
||||
|
|
|
@ -645,7 +645,7 @@ func (suite *DriverSuite) TestURLFor(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
c.Assert(read, check.DeepEquals, contents)
|
||||
|
||||
url, err = suite.StorageDriver.URLFor(suite.ctx, filename, map[string]interface{}{"method": "HEAD"})
|
||||
url, err = suite.StorageDriver.URLFor(suite.ctx, filename, map[string]interface{}{"method": http.MethodHead})
|
||||
if _, ok := err.(storagedriver.ErrUnsupportedMethod); ok {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue