Commit 69600783 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Minor polishing in http space, to get them out of substantial change

to follow shortly.
parent b3562068
......@@ -89,15 +89,10 @@ enum sess_close {
#undef SESS_CLOSE
};
/*--------------------------------------------------------------------*/
/*
* NB: HDR_STATUS is only used in cache_http.c, everybody else uses the
* http->status integer field.
/*--------------------------------------------------------------------
* Indicies into http->hd[]
*/
enum {
/* Fields from the first line of HTTP proto */
#define SLTH(tag, ind, req, resp, sdesc, ldesc) ind,
#include "tbl/vsl_tags_http.h"
#undef SLTH
......
......@@ -193,6 +193,39 @@ HTTP_Copy(struct http *to, const struct http * const fm)
memcpy(to->hdf, fm->hdf, fm->nhd * sizeof *to->hdf);
}
/*--------------------------------------------------------------------*/
void
http_SetH(const struct http *to, unsigned n, const char *fm)
{
assert(n < to->shd);
AN(fm);
to->hd[n].b = TRUST_ME(fm);
to->hd[n].e = strchr(to->hd[n].b, '\0');
to->hdf[n] = 0;
http_VSLH(to, n);
}
/*--------------------------------------------------------------------*/
static void
http_PutField(struct http *to, int field, const char *string)
{
char *p;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
p = WS_Copy(to->ws, string, -1);
if (p == NULL) {
http_fail(to);
VSLb(to->vsl, SLT_LostHeader, "%s", string);
return;
}
to->hd[field].b = p;
to->hd[field].e = strchr(p, '\0');
to->hdf[field] = 0;
http_VSLH(to, field);
}
/*--------------------------------------------------------------------*/
......@@ -515,6 +548,7 @@ uint16_t
http_GetStatus(const struct http *hp)
{
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
return (hp->status);
}
......@@ -522,44 +556,11 @@ const char *
http_GetReq(const struct http *hp)
{
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
Tcheck(hp->hd[HTTP_HDR_METHOD]);
return (hp->hd[HTTP_HDR_METHOD].b);
}
/*--------------------------------------------------------------------*/
static void
http_PutField(struct http *to, int field, const char *string)
{
char *p;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
p = WS_Copy(to->ws, string, -1);
if (p == NULL) {
http_fail(to);
VSLb(to->vsl, SLT_LostHeader, "%s", string);
return;
}
to->hd[field].b = p;
to->hd[field].e = strchr(p, '\0');
to->hdf[field] = 0;
http_VSLH(to, field);
}
/*--------------------------------------------------------------------*/
void
http_SetH(const struct http *to, unsigned n, const char *fm)
{
assert(n < to->shd);
AN(fm);
to->hd[n].b = TRUST_ME(fm);
to->hd[n].e = strchr(to->hd[n].b, '\0');
to->hdf[n] = 0;
http_VSLH(to, n);
}
/*--------------------------------------------------------------------
* Force a particular header field to a particular value
*/
......
......@@ -312,6 +312,9 @@ htc_splitline(struct http *hp, const struct http_conn *htc, int req)
h2 = HTTP_HDR_STATUS;
h3 = HTTP_HDR_REASON;
}
AZ(hp->hd[h1].b);
AZ(hp->hd[h2].b);
AZ(hp->hd[h3].b);
/* Skip leading LWS */
for (p = htc->rxbuf.b ; vct_islws(*p); p++)
......@@ -339,7 +342,6 @@ htc_splitline(struct http *hp, const struct http_conn *htc, int req)
return (400);
}
hp->hd[h2].e = p;
if (!Tlen(hp->hd[h2]))
return (400);
......@@ -364,8 +366,6 @@ htc_splitline(struct http *hp, const struct http_conn *htc, int req)
*hp->hd[h1].e = '\0';
*hp->hd[h2].e = '\0';
if (hp->hd[h3].e != NULL)
*hp->hd[h3].e = '\0';
return (htc_dissect_hdrs(hp, p, htc));
......
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