Fix handling of zero-size PATCH on an already completed upload

If .done() is _not_ used, we trigger another upload to the server - not
clear if this is the best behavior.

With .done(), we simply return the same metadata with a 204 which we
returned with the last PATCH.
parent e52fc9c4
...@@ -470,6 +470,10 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -470,6 +470,10 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
r->s.status = 409; r->s.status = 409;
return (0); return (0);
} }
if (fdisk->location_length > 0) {
r->s.status = 204; /* done file */
return (0);
}
r->s.status = tus_body_to_file(ctx, r->fcore); r->s.status = tus_body_to_file(ctx, r->fcore);
break; break;
} }
......
...@@ -83,6 +83,26 @@ client c1 { ...@@ -83,6 +83,26 @@ client c1 {
expect resp.http.Upload-Expires ~ "GMT$" expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Location == "http://localhost/id" expect resp.http.Location == "http://localhost/id"
# zero PATCH after completed
txreq -method PATCH -url "/id" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Id: id" \
-hdr "Upload-Length: 386550" \
-hdr "Upload-Offset: 386550"
rxresp
# XXX or 409 ?
expect resp.status == 204
expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation"
expect resp.http.Tus-Checksum-Algorithm == <undef>
expect resp.http.Tus-Max-Size == 4194304
expect resp.http.Upload-Offset == 386550
expect resp.http.Upload-Length == 386550
expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Content-Location == "http://localhost/id"
# even for a done file, HEAD will return the correct metadata # even for a done file, HEAD will return the correct metadata
txreq -method HEAD -url "/id" \ txreq -method HEAD -url "/id" \
-hdr "Tus-Resumable: 1.0.0" -hdr "Tus-Resumable: 1.0.0"
......
...@@ -12,10 +12,16 @@ server s1 { ...@@ -12,10 +12,16 @@ server s1 {
server s2 { server s2 {
rxreq rxreq
expect req.method == PUT
expect req.url == /vtc
expect req.bodylen == 10240
txresp txresp
rxreq
expect req.method == PUT expect req.method == PUT
expect req.url == /vtc expect req.url == /vtc
expect req.bodylen == 10240 expect req.bodylen == 10240
txresp
} -start } -start
server s3 { server s3 {
...@@ -41,7 +47,7 @@ varnish v1 -vcl+backend { ...@@ -41,7 +47,7 @@ varnish v1 -vcl+backend {
new test = tus.server("https://my.origin"); new test = tus.server("https://my.origin");
new tmp = tus.server("http://localhost", new tmp = tus.server("http://localhost",
basedir="/tmp/tus", max = 314500B, basedir="/tmp/tus", max = 314500B,
multipart = 8192B); multipart = 10240B);
} }
sub vcl_backend_fetch { sub vcl_backend_fetch {
if (bereq.url ~ "^/tus") { if (bereq.url ~ "^/tus") {
...@@ -56,6 +62,9 @@ varnish v1 -vcl+backend { ...@@ -56,6 +62,9 @@ varnish v1 -vcl+backend {
return (abandon); return (abandon);
} }
} }
sub vcl_backend_error {
return (retry);
}
sub vcl_recv { sub vcl_recv {
if (tmp.recv(id=req.http.id)) { if (tmp.recv(id=req.http.id)) {
return(pass); return(pass);
...@@ -80,6 +89,7 @@ varnish v1 -vcl+backend { ...@@ -80,6 +89,7 @@ varnish v1 -vcl+backend {
} }
sub vcl_deliver { sub vcl_deliver {
call meta; call meta;
tmp.done(req.url);
tmp.deliver(); tmp.deliver();
} }
} -start } -start
...@@ -220,12 +230,31 @@ client c2 { ...@@ -220,12 +230,31 @@ client c2 {
txreq -method PATCH -url "/vtc" \ txreq -method PATCH -url "/vtc" \
-hdr "Tus-Resumable: 1.0.0" \ -hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \ -hdr "Content-Type: application/offset+octet-stream" \
-hdr "Upload-Length: 2048" \ -hdr "Upload-Length: 10240" \
-hdr "Upload-Offset: 8192" \ -hdr "Upload-Offset: 8192" \
-bodylen 2048 -bodylen 2048
rxresp rxresp
expect resp.status == 409 expect resp.status == 409
# zero PATCH after completed
txreq -method PATCH -url "/vtc" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Upload-Length: 10240" \
-hdr "Upload-Offset: 10240"
rxresp
# XXX or 409 ?
expect resp.status == 204
expect resp.http.Tus-Resumable == "1.0.0"
expect resp.http.Tus-Version == "1.0.0"
expect resp.http.Tus-Extension == "creation,creation-with-upload,expiration,termination,concatenation"
expect resp.http.Tus-Checksum-Algorithm == <undef>
expect resp.http.Tus-Max-Size == 314500
expect resp.http.Upload-Offset == 10240
expect resp.http.Upload-Length == 10240
expect resp.http.Upload-Expires ~ "GMT$"
## XXX only for HEAD?
expect resp.http.Upload-Metadata == "filename d29ybGRfZG9taW5hdGlvbl9wbGFuLnBkZg==,is_confidential"
} -start } -start
# part1 # part1
......
...@@ -534,7 +534,19 @@ varnish v1 -start ...@@ -534,7 +534,19 @@ varnish v1 -start
# check that objects are still present # check that objects are still present
server s2 -start
client c2 { client c2 {
# triggers another upload, because .done() is not used
# XXX correct?
txreq -method PATCH -url "/vtc" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Upload-Length: 100" \
-hdr "Upload-Offset: 100"
rxresp
expect resp.status == 204
txreq -method HEAD -url "/vtc" \ txreq -method HEAD -url "/vtc" \
-hdr "Tus-Resumable: 1.0.0" -hdr "Tus-Resumable: 1.0.0"
rxresp rxresp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment