Fix behavior for empty file with .done(url)

If we set a done url (which is sent in Content-Location or Location for
a 301) with an empty file (POST with Upload-Length: 0), we would trigger
the two removed assertions. They are bad because a zero sized upload
is legit and can have a Content-Location.
parent 8d87ecbc
......@@ -123,8 +123,6 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
http_Unset(r, hdr_cloc);
if (fdisk != NULL && fdisk->location_length > 0) {
/* cannot happen for creation */
assert(resp->status != 201);
if (fdisk->location[0] == '/' && fdisk->location[1] != '/') {
bprintf(buf, "%s%s", resp->schemeauth, fdisk->location);
loc = buf;
......@@ -181,7 +179,6 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
VTIM_format(fdisk->upload_expires, t);
http_ForceHeader(r, hdr_exp, t);
if (resp->status == 201) {
AZ(fdisk->location_length);
AN(resp->schemeauth);
http_PrintfHeader(r, "Location: %s%s", resp->schemeauth,
fdisk->url_path);
......
varnishtest "test vmod-tus set done redirect"
server s1 {
rxreq
txresp
expect req.method == PUT
expect req.bodylen == 0
} -start
server s2 {
rxreq
txresp
expect req.method == PUT
......@@ -15,8 +22,11 @@ varnish v1 -vcl+backend {
basedir="/tmp/tus", max = 4MB);
}
sub vcl_backend_fetch {
if (bereq.url ~ "^/id") {
if (bereq.url ~ "^/id-empty") {
set bereq.backend = s1;
} else
if (bereq.url ~ "^/id") {
set bereq.backend = s2;
} else {
return (abandon);
}
......@@ -35,8 +45,8 @@ varnish v1 -vcl+backend {
}
}
sub vcl_deliver {
tmp.deliver();
tmp.done(req.url);
tmp.deliver();
}
} -start
......@@ -94,4 +104,54 @@ client c1 {
expect resp.status == 301
expect resp.http.Location == "http://localhost/id"
} -run
} -start
# empty file
client c2 {
txreq -method "DELETE" -url "/id-empty" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
txreq -method POST \
-hdr "Upload-Length: 0" \
-hdr "Tus-Resumable: 1.0.0" \
-hdr "Content-Type: application/offset+octet-stream" \
-hdr "Id: id-empty"
rxresp
expect resp.status == 201
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 == 0
expect resp.http.Upload-Length == 0
expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Location == "http://localhost/id-empty"
# even for a done file, HEAD will return the correct metadata
txreq -method HEAD -url "/id-empty" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
expect resp.status == 200
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 == 0
expect resp.http.Upload-Length == 0
expect resp.http.Upload-Expires ~ "GMT$"
expect resp.http.Content-Location == "http://localhost/id-empty"
txreq -url "/id-empty" \
-hdr "Tus-Resumable: 1.0.0"
rxresp
expect resp.status == 301
expect resp.http.Location == "http://localhost/id-empty"
} -start
client c1 -wait
client c2 -wait
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