move response status into a struct

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