diff --git a/plugin/protocol/http/include/internal/http_half.h b/plugin/protocol/http/include/internal/http_half.h index 2a61756..16bf5a8 100644 --- a/plugin/protocol/http/include/internal/http_half.h +++ b/plugin/protocol/http/include/internal/http_half.h @@ -51,6 +51,7 @@ struct http_half_private short minor; struct evbuffer * evbuf_uri; + char * url_storage; struct evbuffer * evbuf_header_field; struct evbuffer * evbuf_header_value; diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index 6a1058d..9b79fc2 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -131,11 +131,21 @@ void __hf_public_req_fill_from_private(struct http_half_private * hf_private, st /* uri is stored in underlay evbuffer, we need to append a terminal zero */ static const char __zero = 0; evbuffer_add(hf_private->evbuf_uri, &__zero, sizeof(__zero)); + hf_req_spec->uri = (char *) evbuffer_pullup(hf_private->evbuf_uri, evbuffer_get_length(hf_private->evbuf_uri)); - /* TODO: URL - * url is more complex. need to review RFC */ - hf_req_spec->url = hf_req_spec->uri; + /* TODO: url is more complex. need to review RFC */ + if (hf_req_spec->uri[0] != '\0' && hf_req_spec->uri[0] != '/') + { + asprintf(&hf_private->url_storage, "%s/%s", hf_req_spec->host, hf_req_spec->uri); + } + else + { + asprintf(&hf_private->url_storage, "%s%s", hf_req_spec->host, hf_req_spec->uri); + } + + hf_req_spec->url = hf_private->url_storage; + assert(hf_req_spec->url != NULL); } void __hf_public_resp_fill_from_private(struct http_half_private * hf_private, struct http_parser * parser) diff --git a/plugin/protocol/http/test/test_http_half.cpp b/plugin/protocol/http/test/test_http_half.cpp index dcbc637..86ad6ab 100644 --- a/plugin/protocol/http/test/test_http_half.cpp +++ b/plugin/protocol/http/test/test_http_half.cpp @@ -62,7 +62,7 @@ void __get_http_request_header_verify_helper(struct http_half_private * hf_priva /* PUBLIC FIELD */ EXPECT_EQ(hf_public_request->method, TFE_HTTP_GET); EXPECT_STREQ(hf_public_request->uri, "/gfwlist/gfwlist/master/gfwlist.txt"); - EXPECT_STREQ(hf_public_request->url, "/gfwlist/gfwlist/master/gfwlist.txt"); + EXPECT_STREQ(hf_public_request->url, "raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"); EXPECT_STREQ(hf_public_request->host, "raw.githubusercontent.com"); /* Header Field */ @@ -319,7 +319,7 @@ void __http_post_header_verify_helper(struct http_half_private * hf_private) /* PUBLIC FIELD */ EXPECT_EQ(hf_public_request->method, TFE_HTTP_POST); EXPECT_STREQ(hf_public_request->uri, "/"); - EXPECT_STREQ(hf_public_request->url, "/"); + EXPECT_STREQ(hf_public_request->url, "qbwup.imtt.qq.com/"); EXPECT_STREQ(hf_public_request->host, "qbwup.imtt.qq.com"); /* Header Field */