enum http_request_parser_state state;
+ struct http_url *default_base_url;
+
uoff_t max_target_length;
enum http_request_parse_error error_code;
struct http_request_parser *
http_request_parser_init(struct istream *input,
- const struct http_request_limits *limits,
- enum http_request_parse_flags flags)
+ const struct http_url *default_base_url,
+ const struct http_request_limits *limits,
+ enum http_request_parse_flags flags)
{
struct http_request_parser *parser;
pool_t pool;
pool = pool_alloconly_create("http request parser", 512);
parser = p_new(pool, struct http_request_parser, 1);
parser->pool = pool;
-
+
+ if (default_base_url != NULL) {
+ parser->default_base_url =
+ http_url_clone_authority(pool, default_base_url);
+ }
+
if (limits != NULL) {
hdr_limits = limits->header;
max_payload_size = limits->max_payload_size;
pool = http_message_parser_get_pool(&parser->parser);
if (http_url_request_target_parse(parser->request_target, hdr->value,
- NULL, pool, &request->target, &error) < 0) {
+ parser->default_base_url, pool, &request->target, &error) < 0) {
*error_code_r = HTTP_REQUEST_PARSE_ERROR_BAD_REQUEST;
*error_r = t_strdup_printf("Bad request target `%s': %s",
parser->request_target, error);
struct http_request_parser *
http_request_parser_init(struct istream *input,
- const struct http_request_limits *limits,
- enum http_request_parse_flags flags) ATTR_NULL(2);
+ const struct http_url *default_base_url,
+ const struct http_request_limits *limits,
+ enum http_request_parse_flags flags) ATTR_NULL(2);
void http_request_parser_deinit(struct http_request_parser **_parser);
int http_request_parse_finish_payload(
&conn->conn.input, &conn->conn.output);
}
- conn->http_parser = http_request_parser_init
- (conn->conn.input, &conn->server->set.request_limits,
- HTTP_REQUEST_PARSE_FLAG_STRICT);
+ conn->http_parser = http_request_parser_init(
+ conn->conn.input, NULL, &conn->server->set.request_limits,
+ HTTP_REQUEST_PARSE_FLAG_STRICT);
o_stream_set_flush_callback(conn->conn.output,
http_server_connection_output, conn);
}
enum http_request_parse_flags flags;
};
+static const struct http_url default_base_url = {
+ .host = { .name = "example.org" },
+};
+
static const struct http_request_valid_parse_test
valid_request_parse_tests[] = {
{ .request =
.url = { .host = { .name = "example.com" } }
},
.version_major = 1, .version_minor = 1,
+ },{ .request =
+ "GET / HTTP/1.1\r\n"
+ "Host: \r\n"
+ "\r\n",
+ .method = "GET",
+ .target_raw = "/",
+ .target = {
+ .format = HTTP_REQUEST_TARGET_FORMAT_ORIGIN,
+ .url = { .host = { .name = "example.org" } }
+ },
+ .version_major = 1, .version_minor = 1,
},{ .request =
"OPTIONS * HTTP/1.0\r\n"
"Host: example.com\r\n"
request_text = test->request;
request_text_len = strlen(request_text);
input = test_istream_create_data(request_text, request_text_len);
- parser = http_request_parser_init(input, NULL, test->flags);
+ parser = http_request_parser_init(input, &default_base_url,
+ NULL, test->flags);
test_begin(t_strdup_printf("http request valid [%d]", i));
test = &invalid_request_parse_tests[i];
request_text = test->request;
input = i_stream_create_from_data(request_text, strlen(request_text));
- parser = http_request_parser_init(input, NULL, test->flags);
+ parser = http_request_parser_init(input, &default_base_url,
+ NULL, test->flags);
i_stream_unref(&input);
test_begin(t_strdup_printf("http request invalid [%d]", i));
test_begin("http request with NULs (strict)");
input = i_stream_create_from_data(bad_request_with_nuls,
sizeof(bad_request_with_nuls)-1);
- parser = http_request_parser_init(input, NULL,
- HTTP_REQUEST_PARSE_FLAG_STRICT);
+ parser = http_request_parser_init(input, &default_base_url, NULL,
+ HTTP_REQUEST_PARSE_FLAG_STRICT);
i_stream_unref(&input);
while ((ret=http_request_parse_next
test_begin("http request with NULs (lenient)");
input = i_stream_create_from_data(bad_request_with_nuls,
sizeof(bad_request_with_nuls)-1);
- parser = http_request_parser_init(input, NULL, 0);
+ parser = http_request_parser_init(input, &default_base_url, NULL, 0);
i_stream_unref(&input);
ret = http_request_parse_next