Commit 49af0c1e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Convert htc->rxbuf from txt to dual char *

parent d53f0f7f
...@@ -247,7 +247,8 @@ struct http_conn { ...@@ -247,7 +247,8 @@ struct http_conn {
unsigned maxbytes; unsigned maxbytes;
unsigned maxhdr; unsigned maxhdr;
struct ws *ws; struct ws *ws;
txt rxbuf; char *rxbuf_b;
char *rxbuf_e;
char *pipeline_b; char *pipeline_b;
char *pipeline_e; char *pipeline_e;
ssize_t content_length; ssize_t content_length;
......
...@@ -165,7 +165,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo) ...@@ -165,7 +165,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
do { do {
hs = HTTP1_Rx(htc); hs = HTTP1_Rx(htc);
if (hs == HTTP1_OVERFLOW) { if (hs == HTTP1_OVERFLOW) {
bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf); bo->acct.beresp_hdrbytes +=
htc->rxbuf_e - htc->rxbuf_b;
VSLb(bo->vsl, SLT_FetchError, VSLb(bo->vsl, SLT_FetchError,
"http %sread error: overflow", "http %sread error: overflow",
first ? "first " : ""); first ? "first " : "");
...@@ -174,7 +175,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo) ...@@ -174,7 +175,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
return (-1); return (-1);
} }
if (hs == HTTP1_ERROR_EOF) { if (hs == HTTP1_ERROR_EOF) {
bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf); bo->acct.beresp_hdrbytes +=
htc->rxbuf_e - htc->rxbuf_b;
VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF", VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF",
first ? "first " : ""); first ? "first " : "");
VBE_CloseFd(&bo->vbc, &bo->acct); VBE_CloseFd(&bo->vbc, &bo->acct);
...@@ -188,7 +190,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo) ...@@ -188,7 +190,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
vc->between_bytes_timeout); vc->between_bytes_timeout);
} }
} while (hs != HTTP1_COMPLETE); } while (hs != HTTP1_COMPLETE);
bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf); bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b;
hp = bo->beresp; hp = bo->beresp;
......
...@@ -124,7 +124,8 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -124,7 +124,8 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
req->t_first = now; req->t_first = now;
if (isnan(req->t_req)) if (isnan(req->t_req))
req->t_req = now; req->t_req = now;
req->acct.req_hdrbytes += Tlen(req->htc->rxbuf); req->acct.req_hdrbytes +=
req->htc->rxbuf_e - req->htc->rxbuf_b;
return (REQ_FSM_MORE); return (REQ_FSM_MORE);
} else if (hs == HTTP1_ERROR_EOF) { } else if (hs == HTTP1_ERROR_EOF) {
why = SC_REM_CLOSE; why = SC_REM_CLOSE;
...@@ -160,7 +161,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -160,7 +161,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
} }
} }
} }
req->acct.req_hdrbytes += Tlen(req->htc->rxbuf); req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b;
CNT_AcctLogCharge(wrk->stats, req); CNT_AcctLogCharge(wrk->stats, req);
SES_ReleaseReq(req); SES_ReleaseReq(req);
assert(why != SC_NULL); assert(why != SC_NULL);
...@@ -240,10 +241,11 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -240,10 +241,11 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
AZ(req->vsl->wid); AZ(req->vsl->wid);
req->t_first = req->t_req = sp->t_idle; req->t_first = req->t_req = sp->t_idle;
wrk->stats->sess_pipeline++; wrk->stats->sess_pipeline++;
req->acct.req_hdrbytes += Tlen(req->htc->rxbuf); req->acct.req_hdrbytes +=
req->htc->rxbuf_e - req->htc->rxbuf_b;
return (SESS_DONE_RET_START); return (SESS_DONE_RET_START);
} else { } else {
if (Tlen(req->htc->rxbuf)) if (req->htc->rxbuf_e != req->htc->rxbuf_b)
wrk->stats->sess_readahead++; wrk->stats->sess_readahead++;
return (SESS_DONE_RET_WAIT); return (SESS_DONE_RET_WAIT);
} }
...@@ -286,7 +288,9 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -286,7 +288,9 @@ http1_dissect(struct worker *wrk, struct req *req)
/* If we could not even parse the request, just close */ /* If we could not even parse the request, just close */
if (req->err_code != 0) { if (req->err_code != 0) {
VSLbt(req->vsl, SLT_HttpGarbage, req->htc->rxbuf); VSLb(req->vsl, SLT_HttpGarbage, "%.*s",
(int)(req->htc->rxbuf_e - req->htc->rxbuf_b),
req->htc->rxbuf_b);
wrk->stats->client_req_400++; wrk->stats->client_req_400++;
r = write(req->sp->fd, r_400, strlen(r_400)); r = write(req->sp->fd, r_400, strlen(r_400));
if (r > 0) if (r > 0)
......
...@@ -72,9 +72,9 @@ HTTP1_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl, ...@@ -72,9 +72,9 @@ HTTP1_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
htc->maxhdr = maxhdr; htc->maxhdr = maxhdr;
(void)WS_Reserve(htc->ws, htc->maxbytes); (void)WS_Reserve(htc->ws, htc->maxbytes);
htc->rxbuf.b = ws->f; htc->rxbuf_b = ws->f;
htc->rxbuf.e = ws->f; htc->rxbuf_e = ws->f;
*htc->rxbuf.e = '\0'; *htc->rxbuf_e = '\0';
htc->pipeline_b = NULL; htc->pipeline_b = NULL;
htc->pipeline_e = NULL; htc->pipeline_e = NULL;
} }
...@@ -92,17 +92,17 @@ HTTP1_Reinit(struct http_conn *htc) ...@@ -92,17 +92,17 @@ HTTP1_Reinit(struct http_conn *htc)
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
(void)WS_Reserve(htc->ws, htc->maxbytes); (void)WS_Reserve(htc->ws, htc->maxbytes);
htc->rxbuf.b = htc->ws->f; htc->rxbuf_b = htc->ws->f;
htc->rxbuf.e = htc->ws->f; htc->rxbuf_e = htc->ws->f;
if (htc->pipeline_b != NULL) { if (htc->pipeline_b != NULL) {
l = htc->pipeline_e - htc->pipeline_b; l = htc->pipeline_e - htc->pipeline_b;
assert(l > 0); assert(l > 0);
memmove(htc->rxbuf.b, htc->pipeline_b, l); memmove(htc->rxbuf_b, htc->pipeline_b, l);
htc->rxbuf.e += l; htc->rxbuf_e += l;
htc->pipeline_b = NULL; htc->pipeline_b = NULL;
htc->pipeline_e = NULL; htc->pipeline_e = NULL;
} }
*htc->rxbuf.e = '\0'; *htc->rxbuf_e = '\0';
return (HTTP1_Complete(htc)); return (HTTP1_Complete(htc));
} }
...@@ -114,23 +114,21 @@ enum http1_status_e ...@@ -114,23 +114,21 @@ enum http1_status_e
HTTP1_Complete(struct http_conn *htc) HTTP1_Complete(struct http_conn *htc)
{ {
char *p; char *p;
txt *t;
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
AZ(htc->pipeline_b); AZ(htc->pipeline_b);
AZ(htc->pipeline_e); AZ(htc->pipeline_e);
t = &htc->rxbuf; assert(htc->rxbuf_e >= htc->rxbuf_b);
Tcheck(*t); assert(*htc->rxbuf_e == '\0');
assert(*t->e == '\0');
/* Skip any leading white space */ /* Skip any leading white space */
for (p = t->b ; vct_islws(*p); p++) for (p = htc->rxbuf_b ; vct_islws(*p); p++)
continue; continue;
if (p == t->e) { if (p == htc->rxbuf_e) {
/* All white space */ /* All white space */
t->e = t->b; htc->rxbuf_e = htc->rxbuf_b;
*t->e = '\0'; *htc->rxbuf_e = '\0';
return (HTTP1_ALL_WHITESPACE); return (HTTP1_ALL_WHITESPACE);
} }
while (1) { while (1) {
...@@ -144,11 +142,11 @@ HTTP1_Complete(struct http_conn *htc) ...@@ -144,11 +142,11 @@ HTTP1_Complete(struct http_conn *htc)
break; break;
} }
p++; p++;
WS_ReleaseP(htc->ws, t->e); WS_ReleaseP(htc->ws, htc->rxbuf_e);
if (p < t->e) { if (p < htc->rxbuf_e) {
htc->pipeline_b = p; htc->pipeline_b = p;
htc->pipeline_e = t->e; htc->pipeline_e = htc->rxbuf_e;
t->e = p; htc->rxbuf_e = p;
} }
return (HTTP1_COMPLETE); return (HTTP1_COMPLETE);
} }
...@@ -166,22 +164,22 @@ HTTP1_Rx(struct http_conn *htc) ...@@ -166,22 +164,22 @@ HTTP1_Rx(struct http_conn *htc)
AN(htc->ws->r); AN(htc->ws->r);
AZ(htc->pipeline_b); AZ(htc->pipeline_b);
AZ(htc->pipeline_e); AZ(htc->pipeline_e);
i = (htc->ws->r - htc->rxbuf.e) - 1; /* space for NUL */ i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */
if (i <= 0) { if (i <= 0) {
WS_ReleaseP(htc->ws, htc->rxbuf.b); WS_ReleaseP(htc->ws, htc->rxbuf_b);
return (HTTP1_OVERFLOW); return (HTTP1_OVERFLOW);
} }
i = read(htc->fd, htc->rxbuf.e, i); i = read(htc->fd, htc->rxbuf_e, i);
if (i <= 0) { if (i <= 0) {
/* /*
* We wouldn't come here if we had a complete HTTP header * We wouldn't come here if we had a complete HTTP header
* so consequently an EOF can not be OK * so consequently an EOF can not be OK
*/ */
WS_ReleaseP(htc->ws, htc->rxbuf.b); WS_ReleaseP(htc->ws, htc->rxbuf_b);
return (HTTP1_ERROR_EOF); return (HTTP1_ERROR_EOF);
} }
htc->rxbuf.e += i; htc->rxbuf_e += i;
*htc->rxbuf.e = '\0'; *htc->rxbuf_e = '\0';
return (HTTP1_Complete(htc)); return (HTTP1_Complete(htc));
} }
...@@ -230,24 +228,25 @@ static uint16_t ...@@ -230,24 +228,25 @@ static uint16_t
http1_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc) http1_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
{ {
char *q, *r; char *q, *r;
txt t = htc->rxbuf;
assert(p > htc->rxbuf_b);
assert(p < htc->rxbuf_e);
hp->nhd = HTTP_HDR_FIRST; hp->nhd = HTTP_HDR_FIRST;
hp->conds = 0; hp->conds = 0;
r = NULL; /* For FlexeLint */ r = NULL; /* For FlexeLint */
for (; p < t.e; p = r) { for (; p < htc->rxbuf_e; p = r) {
/* Find end of next header */ /* Find end of next header */
q = r = p; q = r = p;
while (r < t.e) { while (r < htc->rxbuf_e) {
if (!vct_iscrlf(r)) { if (!vct_iscrlf(r)) {
r++; r++;
continue; continue;
} }
q = r; q = r;
assert(r < t.e); assert(r < htc->rxbuf_e);
r += vct_skipcrlf(r); r += vct_skipcrlf(r);
if (r >= t.e) if (r >= htc->rxbuf_e)
break; break;
/* If line does not continue: got it. */ /* If line does not continue: got it. */
if (!vct_issp(*r)) if (!vct_issp(*r))
...@@ -316,14 +315,14 @@ http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf) ...@@ -316,14 +315,14 @@ http1_splitline(struct http *hp, const struct http_conn *htc, const int *hf)
assert(hf == HTTP1_Req || hf == HTTP1_Resp); assert(hf == HTTP1_Req || hf == HTTP1_Resp);
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
Tcheck(htc->rxbuf); assert(htc->rxbuf_e >= htc->rxbuf_b);
AZ(hp->hd[hf[0]].b); AZ(hp->hd[hf[0]].b);
AZ(hp->hd[hf[1]].b); AZ(hp->hd[hf[1]].b);
AZ(hp->hd[hf[2]].b); AZ(hp->hd[hf[2]].b);
/* Skip leading LWS */ /* Skip leading LWS */
for (p = htc->rxbuf.b ; vct_islws(*p); p++) for (p = htc->rxbuf_b ; vct_islws(*p); p++)
continue; continue;
hp->hd[hf[0]].b = p; hp->hd[hf[0]].b = p;
...@@ -536,7 +535,8 @@ HTTP1_DissectResponse(struct http *hp, struct http_conn *htc) ...@@ -536,7 +535,8 @@ HTTP1_DissectResponse(struct http *hp, struct http_conn *htc)
} }
if (retval != 0) { if (retval != 0) {
VSLbt(hp->vsl, SLT_HttpGarbage, htc->rxbuf); VSLb(hp->vsl, SLT_HttpGarbage, "%.*s",
(int)(htc->rxbuf_e - htc->rxbuf_b), htc->rxbuf_b);
assert(retval >= 100 && retval <= 999); assert(retval >= 100 && retval <= 999);
assert(retval == 503); assert(retval == 503);
hp->status = retval; hp->status = retval;
......
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