Fix url path parsing

The url parser had two bugs:
- `http://example.com` -> `GET // HTTP/1.1`
- `foo://bar/baz` -> path is `"baz"` instead of `"/baz"`

Now the path returned by  `mg_http_common_url_parse` always
starts with `/`.

Closes cesanta/mongoose#631

PUBLISHED_FROM=f56ed97361ca14ee31d6ed26cf7afe5cd11e0dc5
This commit is contained in:
Marko Mikulicic 2016-03-17 12:52:07 +01:00
parent 8148b6d037
commit 29d6c4ac04

View File

@ -7540,7 +7540,6 @@ static int mg_http_common_url_parse(const char *url, const char *schema,
return -1;
}
if (*url == '/') {
url++;
break;
}
if (*url == ':') *port_i = addr_len;
@ -7632,7 +7631,7 @@ struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
/* If the port was addred by us, restore the original host. */
if (port_i >= 0) addr[port_i] = '\0';
mg_printf(nc, "%s /%s HTTP/1.1\r\nHost: %s\r\nContent-Length: %" SIZE_T_FMT
mg_printf(nc, "%s %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %" SIZE_T_FMT
"\r\n%s\r\n%s",
post_data == NULL ? "GET" : "POST", path, addr,
post_data == NULL ? 0 : strlen(post_data),