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,
r->s.status = 409;
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);
break;
}
......
......@@ -83,6 +83,26 @@ client c1 {
expect resp.http.Upload-Expires ~ "GMT$"
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
txreq -method HEAD -url "/id" \
-hdr "Tus-Resumable: 1.0.0"
......
......@@ -12,10 +12,16 @@ server s1 {
server s2 {
rxreq
expect req.method == PUT
expect req.url == /vtc
expect req.bodylen == 10240
txresp
rxreq
expect req.method == PUT
expect req.url == /vtc
expect req.bodylen == 10240
txresp
} -start
server s3 {
......@@ -41,7 +47,7 @@ varnish v1 -vcl+backend {
new test = tus.server("https://my.origin");
new tmp = tus.server("http://localhost",
basedir="/tmp/tus", max = 314500B,
multipart = 8192B);
multipart = 10240B);
}
sub vcl_backend_fetch {
if (bereq.url ~ "^/tus") {
......@@ -56,6 +62,9 @@ varnish v1 -vcl+backend {
return (abandon);
}
}
sub vcl_backend_error {
return (retry);
}
sub vcl_recv {
if (tmp.recv(id=req.http.id)) {
return(pass);
......@@ -80,6 +89,7 @@ varnish v1 -vcl+backend {
}
sub vcl_deliver {
call meta;
tmp.done(req.url);
tmp.deliver();
}
} -start
......@@ -220,12 +230,31 @@ client c2 {
txreq -method PATCH -url "/vtc" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Upload-Length: 2048" \
-hdr "Upload-Length: 10240" \
-hdr "Upload-Offset: 8192" \
-bodylen 2048
rxresp
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
# part1
......
......@@ -534,7 +534,19 @@ varnish v1 -start
# check that objects are still present
server s2 -start
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" \
-hdr "Tus-Resumable: 1.0.0"
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