move response status into a struct

parent 448109bc
...@@ -251,7 +251,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -251,7 +251,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
struct tus_concat *c; struct tus_concat *c;
VCL_BLOB hash; VCL_BLOB hash;
AZ(r->status); AZ(r->s.status);
AZ(r->fcore); AZ(r->fcore);
if (http_GetHdr(ctx->http_req, hdr_method, &p)) { if (http_GetHdr(ctx->http_req, hdr_method, &p)) {
...@@ -264,18 +264,18 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -264,18 +264,18 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
(void) http_GetHdr(ctx->http_req, hdr_origin, &r->origin); (void) http_GetHdr(ctx->http_req, hdr_origin, &r->origin);
if (m == _INVALID) { if (m == _INVALID) {
r->status = 405; r->s.status = 405;
return (0); return (0);
} }
if (m == OPTIONS) { if (m == OPTIONS) {
r->status = 204 + (s_OPTIONS * s_MULT); r->s.status = 204 + (s_OPTIONS * s_MULT);
return (0); return (0);
} }
if (m != GET && if (m != GET &&
(! http_GetHdr(ctx->http_req, hdr_resum, &p) || (! http_GetHdr(ctx->http_req, hdr_resum, &p) ||
strcmp(p, "1.0.0") != 0)) { strcmp(p, "1.0.0") != 0)) {
r->status = 412; r->s.status = 412;
return (0); return (0);
} }
...@@ -286,21 +286,21 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -286,21 +286,21 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
type = TUS_FINAL; type = TUS_FINAL;
concat += 6; concat += 6;
} else { } else {
r->status = 400; r->s.status = 400;
return (0); return (0);
} }
} }
if (m == POST && type == TUS_FINAL) { if (m == POST && type == TUS_FINAL) {
if (tus_file_final_concat(tussrv, &embryo, concat) == NULL) { if (tus_file_final_concat(tussrv, &embryo, concat) == NULL) {
r->status = 400; r->s.status = 400;
return (0); return (0);
} }
hash = tus_concat_hash(ctx, embryo.srv, embryo.concat); hash = tus_concat_hash(ctx, embryo.srv, embryo.concat);
if (hash != NULL) { if (hash != NULL) {
id = tus_hex(ctx, hash); id = tus_hex(ctx, hash);
if (id == NULL) { if (id == NULL) {
r->status = 503; r->s.status = 503;
return (0); return (0);
} }
} }
...@@ -310,7 +310,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -310,7 +310,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
tus_metadata_validate(metadata, NULL) == 0) { tus_metadata_validate(metadata, NULL) == 0) {
VSLb(ctx->vsl, SLT_Error, "%s: bad metadata format", VSLb(ctx->vsl, SLT_Error, "%s: bad metadata format",
tus_server_name(tussrv)); tus_server_name(tussrv));
r->status = 400; r->s.status = 400;
return (0); return (0);
} }
...@@ -330,7 +330,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -330,7 +330,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if (lock == EBUSY) { if (lock == EBUSY) {
AZ(r->fcore); AZ(r->fcore);
r->status = 423; r->s.status = 423;
return (0); return (0);
} }
...@@ -352,45 +352,45 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -352,45 +352,45 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
tus_file_final_abort(&embryo); tus_file_final_abort(&embryo);
} else { } else {
tus_file_final_birth(&r->fcore, &embryo); tus_file_final_birth(&r->fcore, &embryo);
r->status = r->fcore ? 201 : 500; r->s.status = r->fcore ? 201 : 500;
} }
} }
if (m == DELETE) { if (m == DELETE) {
if (r->fcore == NULL) { if (r->fcore == NULL) {
r->status = 404; r->s.status = 404;
return (0); return (0);
} }
tus_file_del(&r->fcore); tus_file_del(&r->fcore);
AZ(r->fcore); AZ(r->fcore);
r->status = 204; r->s.status = 204;
} }
if (m == GET) { if (m == GET) {
if (r->fcore == NULL) { if (r->fcore == NULL) {
r->status = 404; r->s.status = 404;
return (0); return (0);
} }
AN(r->fcore); AN(r->fcore);
AN(fdisk); AN(fdisk);
if (fdisk->location_length > 0) { if (fdisk->location_length > 0) {
r->status = 301; /* done file */ r->s.status = 301; /* done file */
} else { } else {
tus_file_unlock(&r->fcore); tus_file_unlock(&r->fcore);
AZ(r->fcore); AZ(r->fcore);
r->status = 400; r->s.status = 400;
} }
return (0); return (0);
} }
if (m == HEAD) { if (m == HEAD) {
r->status = r->fcore ? 200 : 404; r->s.status = r->fcore ? 200 : 404;
return (0); return (0);
} }
if (r->fcore == NULL) { if (r->fcore == NULL) {
r->status = (m == POST) ? 409 : 404; r->s.status = (m == POST) ? 409 : 404;
return (0); return (0);
} }
...@@ -408,7 +408,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -408,7 +408,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if (http_GetHdr(ctx->http_req, hdr_len, &p)) { if (http_GetHdr(ctx->http_req, hdr_len, &p)) {
if (type == TUS_FINAL) { if (type == TUS_FINAL) {
r->status = 400; r->s.status = 400;
return (0); return (0);
} }
...@@ -418,11 +418,11 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -418,11 +418,11 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
} }
if (http_GetHdr(ctx->http_req, hdr_defer, &p)) { if (http_GetHdr(ctx->http_req, hdr_defer, &p)) {
if (len != UINTMAX_MAX || type == TUS_FINAL) { if (len != UINTMAX_MAX || type == TUS_FINAL) {
r->status = 400; r->s.status = 400;
return (0); return (0);
} }
if (strcmp(p, "1") != 0) { if (strcmp(p, "1") != 0) {
r->status = 409; // or 400 ? r->s.status = 409; // or 400 ?
return (0); return (0);
} }
} }
...@@ -431,14 +431,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -431,14 +431,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if (fdisk->upload_length == -1) if (fdisk->upload_length == -1)
fdisk->upload_length = len; fdisk->upload_length = len;
else if (len != fdisk->upload_length) { else if (len != fdisk->upload_length) {
r->status = 409; // or 400 ? r->s.status = 409; // or 400 ?
return (0); return (0);
} }
} }
if (type == TUS_FINAL) { if (type == TUS_FINAL) {
if (m != POST) { if (m != POST) {
r->status = 403; r->s.status = 403;
tus_file_unlock(&r->fcore); tus_file_unlock(&r->fcore);
AZ(r->fcore); AZ(r->fcore);
return (0); return (0);
...@@ -451,14 +451,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -451,14 +451,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
switch (m) { switch (m) {
case PATCH: { case PATCH: {
if (! ct_ok) { if (! ct_ok) {
r->status = 415; r->s.status = 415;
return (0); return (0);
} }
if (off != fdisk->upload_offset) { if (off != fdisk->upload_offset) {
r->status = 409; r->s.status = 409;
return (0); return (0);
} }
r->status = tus_body_to_file(ctx, r->fcore); r->s.status = tus_body_to_file(ctx, r->fcore);
break; break;
} }
case POST: { case POST: {
...@@ -470,26 +470,26 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv, ...@@ -470,26 +470,26 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
cl = 1; cl = 1;
if (cl && ! ct_ok) { if (cl && ! ct_ok) {
r->status = 415; r->s.status = 415;
return (0); return (0);
} }
AZ(fdisk->upload_offset); AZ(fdisk->upload_offset);
if (cl == 0) { if (cl == 0) {
r->status = 201; r->s.status = 201;
break; break;
} }
r->status = tus_body_to_file(ctx, r->fcore); r->s.status = tus_body_to_file(ctx, r->fcore);
if (r->status != 204) if (r->s.status != 204)
break; break;
r->status = 201; r->s.status = 201;
break; break;
} }
default: default:
INCOMPL(); INCOMPL();
} }
if (r->status == 413) { if (r->s.status == 413) {
tus_file_del(&r->fcore); tus_file_del(&r->fcore);
AZ(r->fcore); AZ(r->fcore);
return (0); return (0);
......
...@@ -130,16 +130,16 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, ...@@ -130,16 +130,16 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
loc = fdisk->location; loc = fdisk->location;
} }
http_ForceHeader(r, http_ForceHeader(r,
resp->status == 301 ? hdr_loc : hdr_cloc, resp->s.status == 301 ? hdr_loc : hdr_cloc,
loc); loc);
} }
if (resp->status == 301) { if (resp->s.status == 301) {
VRT_l_resp_status(ctx, resp->status); VRT_l_resp_status(ctx, resp->s.status);
return; return;
} }
VRT_l_resp_status(ctx, resp->status); VRT_l_resp_status(ctx, resp->s.status);
if (resp->status == 405) { if (resp->s.status == 405) {
http_ForceHeader(r, hdr_allow, allow); http_ForceHeader(r, hdr_allow, allow);
return; return;
} }
...@@ -156,7 +156,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, ...@@ -156,7 +156,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
} }
if (resp->origin != NULL && *resp->origin != '\0') if (resp->origin != NULL && *resp->origin != '\0')
tus_cors(r, resp->status, resp->origin); tus_cors(r, resp->s.status, resp->origin);
http_PrintfHeader(r, "Tus-Max-Size: %ju", http_PrintfHeader(r, "Tus-Max-Size: %ju",
tus_upload_length(tussrv, fcore)); tus_upload_length(tussrv, fcore));
...@@ -178,7 +178,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv, ...@@ -178,7 +178,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
http_ForceHeader(r, hdr_meta, fdisk->metadata); http_ForceHeader(r, hdr_meta, fdisk->metadata);
VTIM_format(fdisk->upload_expires, t); VTIM_format(fdisk->upload_expires, t);
http_ForceHeader(r, hdr_exp, t); http_ForceHeader(r, hdr_exp, t);
if (resp->status == 201) { if (resp->s.status == 201) {
AN(resp->schemeauth); AN(resp->schemeauth);
http_PrintfHeader(r, "Location: %s%s", resp->schemeauth, http_PrintfHeader(r, "Location: %s%s", resp->schemeauth,
fdisk->url_path); fdisk->url_path);
......
...@@ -26,10 +26,15 @@ ...@@ -26,10 +26,15 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
struct tus_status {
unsigned status;
const char *reason;
};
struct tus_response { struct tus_response {
unsigned magic; unsigned magic;
#define VMOD_TUS_RESPONSE_MAGIC 0x1054e570 #define VMOD_TUS_RESPONSE_MAGIC 0x1054e570
unsigned status; struct tus_status s;
const char *schemeauth; // from tussrv const char *schemeauth; // from tussrv
const char *origin; // CORS const char *origin; // CORS
// if set, mtx is helt // if set, mtx is helt
......
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