Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for canceling resumable uploads #1813

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fakestorage/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,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 @@ -630,6 +630,10 @@ func parseContentRange(r string) (parsed contentRange, err error) {
return parsed, nil
}

func (s *Server) deleteResumableUpload(r *http.Request) jsonResponse {
return jsonResponse{status: 499}
}
Comment on lines +633 to +635
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, if a non-existent session URI is specified, the server should return a 404, and a PUT request for a deleted session URI should respond with 499. However, since the upload process did not seem to specifically check whether the session URI actually exists, I decided to follow that approach and not pursue this level of reality.


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
Loading