Skip to content

Commit

Permalink
WIP: migrating req->host to h_tbl
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Petrov authored and dmpetroff committed Apr 11, 2023
1 parent 9472012 commit de8d891
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ typedef enum {
TFW_HTTP_HDR_H2_METHOD = TFW_HTTP_HDR_H2_STATUS,
TFW_HTTP_HDR_H2_SCHEME,
TFW_HTTP_HDR_H2_AUTHORITY,
/* host part that is extractedd from the request uri.
* This field is only possible in HTTP/1.x, so it shares
* memory slot with the authority header. */
TFW_HTTP_HDR_URI_HOST = TFW_HTTP_HDR_H2_AUTHORITY,
TFW_HTTP_HDR_H2_PATH,
TFW_HTTP_HDR_REGULAR,
TFW_HTTP_HDR_HOST = TFW_HTTP_HDR_REGULAR,
Expand Down
22 changes: 11 additions & 11 deletions fw/t/unit/test_http1_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TEST(http1_parser, parses_req_uri)
#define TEST_URI_PATH(req_uri_path) \
FOR_REQ("GET " req_uri_path " HTTP/1.1\r\n\r\n") \
{ \
EXPECT_TFWSTR_EQ(&req->host, ""); \
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "");\
EXPECT_TFWSTR_EQ(&req->uri_path, req_uri_path); \
}

Expand All @@ -190,7 +190,7 @@ TEST(http1_parser, parses_req_uri)
#define TEST_FULL_REQ(req_host, req_uri_path) \
FOR_REQ("GET http://" req_host req_uri_path " HTTP/1.1\r\n\r\n")\
{ \
EXPECT_TFWSTR_EQ(&req->host, req_host); \
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], req_host);\
EXPECT_TFWSTR_EQ(&req->uri_path, req_uri_path); \
}

Expand All @@ -207,22 +207,22 @@ TEST(http1_parser, parses_req_uri)

FOR_REQ("GET http://[email protected] HTTP/1.1\r\n\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
}

FOR_REQ("GET https://[email protected] HTTP/1.1\r\n\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
}

FOR_REQ("GET ws://[email protected] HTTP/1.1\r\n\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
}

FOR_REQ("GET wss://[email protected] HTTP/1.1\r\n\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
}

FOR_REQ("OPTIONS * HTTP/1.1\r\n\r\n");
Expand Down Expand Up @@ -262,7 +262,7 @@ TEST(http1_parser, parses_enforce_ext_req)
"Accept: */*\r\n"
"\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->uri_path, "/");
}

Expand All @@ -272,7 +272,7 @@ TEST(http1_parser, parses_enforce_ext_req)
"Accept: */*\r\n"
"\r\n")
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com:8080");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com:8080");
EXPECT_TFWSTR_EQ(&req->uri_path, "/cgi-bin/show.pl");
}
}
Expand Down Expand Up @@ -320,19 +320,19 @@ TEST(http1_parser, parses_enforce_ext_req_rmark)
}

FOR_REQ("GET " AUTH RMARK URI_1 " HTTP/1.1\r\n\r\n") {
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_1);
}

FOR_REQ("GET " AUTH RMARK URI_3 " HTTP/1.1\r\n\r\n") {
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_3);
}

FOR_REQ("GET " AUTH RMARK URI_4 " HTTP/1.1\r\n\r\n") {
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_4);
}
Expand Down
14 changes: 7 additions & 7 deletions fw/t/unit/test_http2_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TEST(http2_parser, parses_req_uri)
HEADERS_FRAME_END(); \
) \
{ \
EXPECT_TFWSTR_EQ(&req->host, ""); \
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], ""); \
EXPECT_TFWSTR_EQ(&req->uri_path, req_uri_path); \
}

Expand All @@ -224,7 +224,7 @@ TEST(http2_parser, parses_req_uri)
HEADERS_FRAME_END(); \
) \
{ \
EXPECT_TFWSTR_EQ(&req->host, req_host); \
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], req_host);\
EXPECT_TFWSTR_EQ(&req->uri_path, req_uri_path); \
}

Expand Down Expand Up @@ -312,7 +312,7 @@ TEST(http2_parser, parses_enforce_ext_req)
HEADERS_FRAME_END();
)
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
EXPECT_TFWSTR_EQ(&req->uri_path, "/");
}

Expand All @@ -327,7 +327,7 @@ TEST(http2_parser, parses_enforce_ext_req)
HEADERS_FRAME_END();
)
{
EXPECT_TFWSTR_EQ(&req->host, "natsys-lab.com:8080");
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com:8080");
EXPECT_TFWSTR_EQ(&req->uri_path, "/cgi-bin/show.pl");
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ TEST(http2_parser, parses_enforce_ext_req_rmark)
HEADERS_FRAME_END();
)
{
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_1);
}
Expand All @@ -425,7 +425,7 @@ TEST(http2_parser, parses_enforce_ext_req_rmark)
HEADERS_FRAME_END();
)
{
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_3);
}
Expand All @@ -439,7 +439,7 @@ TEST(http2_parser, parses_enforce_ext_req_rmark)
HEADERS_FRAME_END();
)
{
EXPECT_TFWSTR_EQ(&req->host, HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], HOST ":" PORT);
EXPECT_TFWSTR_EQ(&req->mark, RMARK);
EXPECT_TFWSTR_EQ(&req->uri_path, URI_4);
}
Expand Down
16 changes: 8 additions & 8 deletions fw/t/unit/test_http_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ TEST(http_match, host_eq)
"natsys-lab");
test_chain_add_rule_str(3, TFW_HTTP_MATCH_F_HOST, NULL,
"NATSYS-LAB.COM");
set_tfw_str(&test_req->host, "natsys-lab.com");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "natsys-lab.com");
match_id = test_chain_match();
EXPECT_EQ(3, match_id);
}
Expand Down Expand Up @@ -413,7 +413,7 @@ TEST(http_match, hdr_host_prefix)
test_chain_add_rule_str(3, TFW_HTTP_MATCH_F_HDR,
"Host", "www.example.com*");

set_tfw_str(&test_req->host, "example.com");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "example.com");
match_id = test_chain_match();
EXPECT_EQ(-1, match_id);

Expand Down Expand Up @@ -463,7 +463,7 @@ TEST(http_match, hdr_host_suffix)
test_chain_add_rule_str(5, TFW_HTTP_MATCH_F_HDR,
"Host", "*.com");

set_tfw_str(&test_req->host, "example.com");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "example.com");
match_id = test_chain_match();
EXPECT_EQ(-1, match_id);

Expand Down Expand Up @@ -810,7 +810,7 @@ TEST(http_match, choose_host)
EXPECT_EQ(-1, match_id);

/* Host specified by URI. */
set_tfw_str(&test_req->host, "example.com");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "example.com");
match_id = test_chain_match();
EXPECT_EQ(1, match_id);

Expand All @@ -823,7 +823,7 @@ TEST(http_match, choose_host)
EXPECT_EQ(1, match_id);

/* Host specified by Host header */
set_tfw_str(&test_req->host, "");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "");
test_req->h_tbl->tbl[TFW_HTTP_HDR_HOST] = *hdr1;
match_id = test_chain_match();
EXPECT_EQ(2, match_id);
Expand All @@ -832,7 +832,7 @@ TEST(http_match, choose_host)
* Host specified by Host, Forwarded headers
* and URI. Host from uri must be matched.
*/
set_tfw_str(&test_req->host, "example.com");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "example.com");
test_req->h_tbl->tbl[TFW_HTTP_HDR_HOST] = *hdr1;
test_req->h_tbl->tbl[TFW_HTTP_HDR_FORWARDED] = hdr4;
match_id = test_chain_match();
Expand All @@ -842,7 +842,7 @@ TEST(http_match, choose_host)
* Host specified by Host and Forwarded headers.
* Host from Forwarded header must be matched.
*/
set_tfw_str(&test_req->host, "");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "");
test_req->h_tbl->tbl[TFW_HTTP_HDR_HOST] = *hdr2;
test_req->h_tbl->tbl[TFW_HTTP_HDR_FORWARDED] = hdr4;
match_id = test_chain_match();
Expand All @@ -854,7 +854,7 @@ TEST(http_match, choose_host)
* and :authority. Host from :authority must be matched.
*/
__set_bit(TFW_HTTP_B_H2, test_req->flags);
set_tfw_str(&test_req->host, "");
set_tfw_str(&test_req->h_tbl->tbl[TFW_HTTP_HDR_URI_HOST], "");
test_req->h_tbl->tbl[TFW_HTTP_HDR_H2_AUTHORITY] = hdr5;
test_req->h_tbl->tbl[TFW_HTTP_HDR_HOST] = *hdr3;
test_req->h_tbl->tbl[TFW_HTTP_HDR_FORWARDED] = hdr4;
Expand Down

0 comments on commit de8d891

Please sign in to comment.