Skip to content

Commit

Permalink
Second attempt on req->host changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Petrov committed Apr 14, 2023
1 parent 63f5607 commit a54930c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
30 changes: 3 additions & 27 deletions fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,21 +752,7 @@ do { \
if (!cl_len)
return TFW_BLOCK;

if (req->host.len) {
host = req->host;
} else {
/* Invalid id value */
unsigned id = TFW_HTTP_HDR_NUM;

if (!TFW_STR_EMPTY(&req->h_tbl->tbl[TFW_HTTP_HDR_H2_AUTHORITY]))
id = TFW_HTTP_HDR_H2_AUTHORITY;
else if (!TFW_STR_EMPTY(&req->h_tbl->tbl[TFW_HTTP_HDR_HOST]))
id = TFW_HTTP_HDR_HOST;

if (id != TFW_HTTP_HDR_NUM)
tfw_http_msg_clnthdr_val(req, &req->h_tbl->tbl[id],
id, &host);
}
host = req->host;

remaining = RESP_BUF_LEN - SLEN(S_V_DATE) - cl_len;
len = host.len + req->uri_path.len + body_len;
Expand Down Expand Up @@ -1497,8 +1483,6 @@ tfw_http_req_redir(TfwHttpReq *req, int status, TfwHttpRedir *redir)
TfwStr *c, *end, *c2, *end2;
char *status_line;
size_t i = 0;
TfwStr *hdr;
TfwStr hdr_val;

tfw_http_prep_date(date_val);

Expand Down Expand Up @@ -1537,16 +1521,7 @@ do { \
TFW_STRCPY(&req->uri_path);
break;
case TFW_HTTP_REDIR_HOST:
if (req->host.len) {
hdr_val = req->host;
} else {
hdr = &req->h_tbl->tbl[TFW_HTTP_HDR_HOST];
tfw_http_msg_clnthdr_val(req, hdr,
TFW_HTTP_HDR_HOST,
&hdr_val);
}

TFW_STRCPY(&hdr_val);
TFW_STRCPY(&req->host);
break;
default:
BUG();
Expand Down Expand Up @@ -5774,6 +5749,7 @@ tfw_http_req_process(TfwConn *conn, TfwStream *stream, struct sk_buff *skb)
TfwHttpActionResult res;

BUG_ON(!stream->msg);
pr_info(">>> tfw_http_req_process");

T_DBG2("Received %u client data bytes on conn=%p msg=%p\n",
skb->len, conn, stream->msg);
Expand Down
6 changes: 5 additions & 1 deletion fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ typedef struct {
* @pit - iterator for tracking transformed data allocation (applicable
* for HTTP/2 mode only);
* @userinfo - userinfo in URI, not mandatory;
* @host - host in URI, may differ from Host header;
* @host - host that was picked from request URI, Host or HTTP/2
* authority header;
* @uri_host - points to host if request URI contained hostname, NULL
* otherwise;
* @uri_path - path + query + fragment from URI (RFC3986.3);
* @mark - special hash mark for redirects handling in session module;
* @multipart_boundary_raw - multipart boundary as is, maybe with escaped chars;
Expand Down Expand Up @@ -470,6 +473,7 @@ struct tfw_http_req_t {
TfwHttpCond cond;
TfwMsgParseIter pit;
TfwStr userinfo;
TfwStr *uri_host;
TfwStr host;
TfwStr uri_path;
TfwStr mark;
Expand Down
10 changes: 8 additions & 2 deletions fw/http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5870,6 +5870,7 @@ Req_Method_1CharStep: __attribute__((cold))
*/
__FSM_STATE(Req_UriAuthorityStart, cold) {
if (likely(isalnum(c) || c == '.' || c == '-')) {
req->uri_host = &req->host;
__msg_field_open(&req->host, p);
__FSM_MOVE_f(Req_UriAuthority, &req->host);
} else if (likely(c == '/')) {
Expand All @@ -5883,6 +5884,7 @@ Req_Method_1CharStep: __attribute__((cold))
req->host.flags |= TFW_STR_COMPLETE;
__FSM_JMP(Req_UriMark);
} else if (c == '[') {
req->uri_host = &req->host;
__msg_field_open(&req->host, p);
__FSM_MOVE_f(Req_UriAuthorityIPv6, &req->host);
}
Expand Down Expand Up @@ -10682,8 +10684,12 @@ tfw_h2_parse_req_finish(TfwHttpReq *req)
req->body.flags |= TFW_STR_COMPLETE;
__set_bit(TFW_HTTP_B_FULLY_PARSED, req->flags);

__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY],
&req->host);
if (!TFW_STR_EMPTY(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY]))
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_AUTHORITY],
&req->host);
else
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_HOST],
&req->host);
__h2_msg_hdr_val(&ht->tbl[TFW_HTTP_HDR_H2_PATH],
&req->uri_path);

Expand Down

0 comments on commit a54930c

Please sign in to comment.