Commit 9f1222ed authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

More http_ cleanup:

Move policy decisions out where they belong and let the http_Filter
function send the first like through unmolested.

Rather than value specific functions, make a generic
http_ForceField() function, because the name is cool.
parent d5affe57
......@@ -996,7 +996,7 @@ void http_PrintfHeader(struct http *to, const char *fmt, ...)
__printflike(2, 3);
void http_SetHeader(struct http *to, const char *hdr);
void http_SetH(const struct http *to, unsigned n, const char *fm);
void http_ForceGet(const struct http *to);
void http_ForceField(const struct http *to, unsigned n, const char *t);
void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum VSL_tag_e);
void http_Teardown(struct http *ht);
int http_GetHdr(const struct http *hp, const char *hdr, char **ptr);
......
......@@ -79,8 +79,12 @@ ved_include(struct req *preq, const char *src, const char *host)
http_SetHeader(req->http0, host);
}
http_ForceGet(req->http0);
http_ForceField(req->http0, HTTP_HDR_METHOD, "GET");
http_ForceField(req->http0, HTTP_HDR_PROTO, "HTTP/1.1");
/* Don't allow Conditions, we can't use a 304 */
http_Unset(req->http0, H_If_Modified_Since);
http_Unset(req->http0, H_If_None_Match);
/* Client content already taken care of */
http_Unset(req->http0, H_Content_Length);
......
......@@ -190,7 +190,8 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
bo->do_pass ? HTTPH_R_PASS : HTTPH_R_FETCH);
if (!bo->do_pass) {
http_ForceGet(bo->bereq0);
http_ForceField(bo->bereq0, HTTP_HDR_METHOD, "GET");
http_ForceField(bo->bereq0, HTTP_HDR_PROTO, "HTTP/1.1");
if (cache_param->http_gzip_support)
http_ForceHeader(bo->bereq0, H_Accept_Encoding, "gzip");
AN(bo->req);
......
......@@ -545,6 +545,7 @@ http_PutField(struct http *to, int field, const char *string)
to->hdf[field] = 0;
http_VSLH(to, field);
}
/*--------------------------------------------------------------------*/
void
......@@ -559,13 +560,22 @@ http_SetH(const struct http *to, unsigned n, const char *fm)
http_VSLH(to, n);
}
/*--------------------------------------------------------------------
* Force a particular header field to a particular value
*/
void
http_ForceGet(const struct http *to)
http_ForceField(const struct http *to, unsigned n, const char *t)
{
if (strcmp(http_GetReq(to), "GET"))
http_SetH(to, HTTP_HDR_METHOD, "GET");
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
assert(n < HTTP_HDR_FIRST);
AN(t);
if (to->hd[n].b == NULL || strcmp(to->hd[n].b, t))
http_SetH(to, n, t);
}
/*--------------------------------------------------------------------*/
void
http_PutResponse(struct http *to, const char *proto, uint16_t status,
const char *reason)
......@@ -671,10 +681,7 @@ http_FilterReq(struct http *to, const struct http *fm, unsigned how)
http_linkh(to, fm, HTTP_HDR_METHOD);
http_linkh(to, fm, HTTP_HDR_URL);
if (how == HTTPH_R_FETCH)
http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
else
http_linkh(to, fm, HTTP_HDR_PROTO);
http_linkh(to, fm, HTTP_HDR_PROTO);
http_filterfields(to, fm, how);
}
......@@ -686,8 +693,8 @@ http_FilterResp(const struct http *fm, struct http *to, unsigned how)
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
to->status = fm->status;
http_linkh(to, fm, HTTP_HDR_PROTO);
http_linkh(to, fm, HTTP_HDR_STATUS);
http_linkh(to, fm, HTTP_HDR_REASON);
http_filterfields(to, fm, how);
......@@ -706,9 +713,9 @@ http_Merge(const struct http *fm, struct http *to, int not_ce)
const char *p;
to->status = fm->status;
http_SetH(to, HTTP_HDR_PROTO, fm->hd[HTTP_HDR_PROTO].b);
http_SetH(to, HTTP_HDR_STATUS, fm->hd[HTTP_HDR_STATUS].b);
http_SetH(to, HTTP_HDR_REASON, fm->hd[HTTP_HDR_REASON].b);
http_linkh(to, fm, HTTP_HDR_PROTO);
http_linkh(to, fm, HTTP_HDR_STATUS);
http_linkh(to, fm, HTTP_HDR_REASON);
for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
fm->hdf[u] |= HDF_MARKER;
......
......@@ -103,6 +103,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
http_FilterResp(req->obj->http, req->resp, 0);
http_ForceField(req->resp, HTTP_HDR_PROTO, "HTTP/1.1");
if (req->wrk->stats.cache_hit)
http_PrintfHeader(req->resp,
......
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