Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Ben Brown | c24b5051c0 | |
Ben Brown | 23181d6f4f | |
Jyri J. Virkki | b720a89d55 |
14
src/client.c
14
src/client.c
|
@ -379,26 +379,24 @@ static uint8_t client_parse(Client *client, int size) {
|
||||||
str = &client->buffer[client->parser_offset];
|
str = &client->buffer[client->parser_offset];
|
||||||
//printf("checking header: '%s'\n", str);
|
//printf("checking header: '%s'\n", str);
|
||||||
|
|
||||||
if (strncmp(str, "Content-Length: ", sizeof("Content-Length: ")-1) == 0) {
|
if (strncasecmp(str, "Content-Length: ", sizeof("Content-Length: ")-1) == 0) {
|
||||||
/* content length header */
|
/* content length header */
|
||||||
client->content_length = str_to_uint64(str + sizeof("Content-Length: ") - 1);
|
client->content_length = str_to_uint64(str + sizeof("Content-Length: ") - 1);
|
||||||
} else if (strncmp(str, "Connection: ", sizeof("Connection: ")-1) == 0) {
|
} else if (strncasecmp(str, "Connection: ", sizeof("Connection: ")-1) == 0) {
|
||||||
/* connection header */
|
/* connection header */
|
||||||
str += sizeof("Connection: ") - 1;
|
str += sizeof("Connection: ") - 1;
|
||||||
|
|
||||||
if (strncmp(str, "close", sizeof("close")-1) == 0)
|
if (strncasecmp(str, "close", sizeof("close")-1) == 0)
|
||||||
client->keepalive = 0;
|
client->keepalive = 0;
|
||||||
else if (strncmp(str, "Keep-Alive", sizeof("Keep-Alive")-1) == 0)
|
else if (strncasecmp(str, "keep-alive", sizeof("keep-alive")-1) == 0)
|
||||||
client->keepalive = client->worker->config->keep_alive;
|
|
||||||
else if (strncmp(str, "keep-alive", sizeof("keep-alive")-1) == 0)
|
|
||||||
client->keepalive = client->worker->config->keep_alive;
|
client->keepalive = client->worker->config->keep_alive;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
} else if (strncmp(str, "Transfer-Encoding: ", sizeof("Transfer-Encoding: ")-1) == 0) {
|
} else if (strncasecmp(str, "Transfer-Encoding: ", sizeof("Transfer-Encoding: ")-1) == 0) {
|
||||||
/* transfer encoding header */
|
/* transfer encoding header */
|
||||||
str += sizeof("Transfer-Encoding: ") - 1;
|
str += sizeof("Transfer-Encoding: ") - 1;
|
||||||
|
|
||||||
if (strncmp(str, "chunked", sizeof("chunked")-1) == 0)
|
if (strncasecmp(str, "chunked", sizeof("chunked")-1) == 0)
|
||||||
client->chunked = 1;
|
client->chunked = 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -76,9 +76,11 @@ static char *forge_request(char *url, char keep_alive, char **host, uint16_t *po
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint8_t have_user_agent;
|
uint8_t have_user_agent;
|
||||||
|
char *header_host;
|
||||||
|
|
||||||
*host = NULL;
|
*host = NULL;
|
||||||
*port = 0;
|
*port = 0;
|
||||||
|
header_host = NULL;
|
||||||
|
|
||||||
if (strncmp(url, "http://", 7) == 0)
|
if (strncmp(url, "http://", 7) == 0)
|
||||||
url += 7;
|
url += 7;
|
||||||
|
@ -137,8 +139,27 @@ static char *forge_request(char *url, char keep_alive, char **host, uint16_t *po
|
||||||
|
|
||||||
have_user_agent = 0;
|
have_user_agent = 0;
|
||||||
for (i = 0; i < headers_num; i++) {
|
for (i = 0; i < headers_num; i++) {
|
||||||
|
if (strncmp(headers[i], "Host:", sizeof("Host:")-1) == 0) {
|
||||||
|
if (header_host) {
|
||||||
|
W_ERROR("%s", "Duplicate Host header");
|
||||||
|
free(*host);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
header_host = headers[i] + 5;
|
||||||
|
if (*header_host == ' ')
|
||||||
|
header_host++;
|
||||||
|
|
||||||
|
if (strlen(header_host) == 0) {
|
||||||
|
W_ERROR("%s", "Invalid Host header");
|
||||||
|
free(*host);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
len += strlen(header_host);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
len += strlen(headers[i]) + strlen("\r\n");
|
len += strlen(headers[i]) + strlen("\r\n");
|
||||||
if (strncmp(headers[i], "User-Agent: ", sizeof("User-Agent: ")-1) == 0)
|
if (strncmp(headers[i], "User-Agent:", sizeof("User-Agent:")-1) == 0)
|
||||||
have_user_agent = 1;
|
have_user_agent = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +171,13 @@ static char *forge_request(char *url, char keep_alive, char **host, uint16_t *po
|
||||||
strcpy(req, "GET ");
|
strcpy(req, "GET ");
|
||||||
strcat(req, url);
|
strcat(req, url);
|
||||||
strcat(req, " HTTP/1.1\r\nHost: ");
|
strcat(req, " HTTP/1.1\r\nHost: ");
|
||||||
strcat(req, *host);
|
if (header_host) {
|
||||||
if (*port != 80)
|
strcat(req, header_host);
|
||||||
sprintf(req + strlen(req), ":%"PRIu16, *port);
|
} else {
|
||||||
|
strcat(req, *host);
|
||||||
|
if (*port != 80)
|
||||||
|
sprintf(req + strlen(req), ":%"PRIu16, *port);
|
||||||
|
}
|
||||||
|
|
||||||
strcat(req, "\r\n");
|
strcat(req, "\r\n");
|
||||||
|
|
||||||
|
@ -160,6 +185,8 @@ static char *forge_request(char *url, char keep_alive, char **host, uint16_t *po
|
||||||
sprintf(req + strlen(req), "User-Agent: weighttp/" VERSION "\r\n");
|
sprintf(req + strlen(req), "User-Agent: weighttp/" VERSION "\r\n");
|
||||||
|
|
||||||
for (i = 0; i < headers_num; i++) {
|
for (i = 0; i < headers_num; i++) {
|
||||||
|
if (strncmp(headers[i], "Host:", sizeof("Host:")-1) == 0)
|
||||||
|
continue;
|
||||||
strcat(req, headers[i]);
|
strcat(req, headers[i]);
|
||||||
strcat(req, "\r\n");
|
strcat(req, "\r\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue