Skip to content

Commit

Permalink
Add support for canceling resumable uploads (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawmra authored Jan 3, 2025
1 parent 314433e commit ab0a11a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fakestorage/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ func (s *Server) buildMuxer() {
handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.insertObject))
handler.Path("/upload/storage/v1/b/{bucketName}/o").Methods(http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent))
handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodPut).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent))
handler.Path("/upload/storage/v1/b/{bucketName}/o").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteResumableUpload))
handler.Path("/upload/storage/v1/b/{bucketName}/o/").Methods(http.MethodDelete).HandlerFunc(jsonToHTTPHandler(s.deleteResumableUpload))
handler.Path("/upload/resumable/{uploadId}").Methods(http.MethodPut, http.MethodPost).HandlerFunc(jsonToHTTPHandler(s.uploadFileContent))

// Batch endpoint
Expand Down
4 changes: 4 additions & 0 deletions fakestorage/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@ func parseContentRange(r string) (parsed contentRange, err error) {
return parsed, nil
}

func (s *Server) deleteResumableUpload(r *http.Request) jsonResponse {
return jsonResponse{status: 499}
}

func loadMetadata(rc io.ReadCloser) (*multipartMetadata, error) {
defer rc.Close()
var m multipartMetadata
Expand Down
24 changes: 24 additions & 0 deletions fakestorage/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,30 @@ func TestServerClientSimpleUploadNoName(t *testing.T) {
}
}

func TestServerClientDeleteResumableUpload(t *testing.T) {
server := NewServer(nil)
defer server.Stop()

req, err := http.NewRequest("DELETE", server.URL()+"/upload/storage/v1/b/other-bucket/o?uploadType=media&name=some/nice/object.txt", nil)
if err != nil {
t.Fatal(err)
}
client := http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
expectedStatus := 499
if resp.StatusCode != expectedStatus {
t.Errorf("wrong status code\nwant %d\ngot %d", expectedStatus, resp.StatusCode)
}
}

func TestServerInvalidUploadType(t *testing.T) {
server := NewServer(nil)
defer server.Stop()
Expand Down

0 comments on commit ab0a11a

Please sign in to comment.