Merge 991e47d8eb
into 05f6e4e000
This commit is contained in:
commit
af1c48daa7
@ -24,6 +24,12 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "hsearch.h"
|
#include "hsearch.h"
|
||||||
|
|
||||||
|
enum connect_method_e {
|
||||||
|
CM_FALSE = 0,
|
||||||
|
CM_TRUE = 1,
|
||||||
|
CM_UPGRADE = 2,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Connection Definition
|
* Connection Definition
|
||||||
*/
|
*/
|
||||||
@ -37,8 +43,9 @@ struct conn_s {
|
|||||||
/* The request line (first line) from the client */
|
/* The request line (first line) from the client */
|
||||||
char *request_line;
|
char *request_line;
|
||||||
|
|
||||||
|
enum connect_method_e connect_method;
|
||||||
|
|
||||||
/* Booleans */
|
/* Booleans */
|
||||||
unsigned int connect_method;
|
|
||||||
unsigned int show_stats;
|
unsigned int show_stats;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
36
src/reqs.c
36
src/reqs.c
@ -90,7 +90,7 @@
|
|||||||
* connections. The request line is allocated from the heap, but it must
|
* connections. The request line is allocated from the heap, but it must
|
||||||
* be freed in another function.
|
* be freed in another function.
|
||||||
*/
|
*/
|
||||||
static int read_request_line (struct conn_s *connptr)
|
static int read_request_line (struct conn_s *connptr, char** lines, size_t* lines_len)
|
||||||
{
|
{
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
|
|
||||||
@ -104,6 +104,12 @@ retry:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*lines = saferealloc(*lines, *lines_len + len + 1);
|
||||||
|
if(*lines) {
|
||||||
|
strcpy(*lines + *lines_len, connptr->request_line);
|
||||||
|
*lines_len += len;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Strip the new line and carriage return from the string.
|
* Strip the new line and carriage return from the string.
|
||||||
*/
|
*/
|
||||||
@ -450,7 +456,7 @@ BAD_REQUEST_ERROR:
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
connptr->connect_method = TRUE;
|
connptr->connect_method = CM_TRUE;
|
||||||
} else {
|
} else {
|
||||||
#ifdef TRANSPARENT_PROXY
|
#ifdef TRANSPARENT_PROXY
|
||||||
if (!skip_trans) {
|
if (!skip_trans) {
|
||||||
@ -676,7 +682,7 @@ add_header_to_connection (orderedmap hashofheaders, char *header, size_t len)
|
|||||||
/*
|
/*
|
||||||
* Read all the headers from the stream
|
* Read all the headers from the stream
|
||||||
*/
|
*/
|
||||||
static int get_all_headers (int fd, orderedmap hashofheaders)
|
static int get_all_headers (int fd, orderedmap hashofheaders, char** lines, size_t* lines_len)
|
||||||
{
|
{
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
char *header = NULL;
|
char *header = NULL;
|
||||||
@ -696,6 +702,14 @@ static int get_all_headers (int fd, orderedmap hashofheaders)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(lines) {
|
||||||
|
*lines = saferealloc(*lines, *lines_len + linelen + 1);
|
||||||
|
if(*lines) {
|
||||||
|
strcpy(*lines + *lines_len, line);
|
||||||
|
*lines_len += linelen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we received a CR LF or a non-continuation line, then add
|
* If we received a CR LF or a non-continuation line, then add
|
||||||
* the accumulated header field, if any, to the hashmap, and
|
* the accumulated header field, if any, to the hashmap, and
|
||||||
@ -1070,7 +1084,7 @@ retry:
|
|||||||
/*
|
/*
|
||||||
* Get all the headers from the remote server in a big hash
|
* Get all the headers from the remote server in a big hash
|
||||||
*/
|
*/
|
||||||
if (get_all_headers (connptr->server_fd, hashofheaders) < 0) {
|
if (get_all_headers (connptr->server_fd, hashofheaders, NULL, NULL) < 0) {
|
||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Could not retrieve all the headers from the remote server.");
|
"Could not retrieve all the headers from the remote server.");
|
||||||
orderedmap_destroy (hashofheaders);
|
orderedmap_destroy (hashofheaders);
|
||||||
@ -1599,6 +1613,8 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
|
|
||||||
char sock_ipaddr[IP_LENGTH];
|
char sock_ipaddr[IP_LENGTH];
|
||||||
char peer_ipaddr[IP_LENGTH];
|
char peer_ipaddr[IP_LENGTH];
|
||||||
|
char *lines = NULL;
|
||||||
|
size_t lines_len = 0;
|
||||||
|
|
||||||
getpeer_information (addr, peer_ipaddr, sizeof(peer_ipaddr));
|
getpeer_information (addr, peer_ipaddr, sizeof(peer_ipaddr));
|
||||||
|
|
||||||
@ -1642,7 +1658,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
HC_FAIL();
|
HC_FAIL();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_request_line (connptr) < 0) {
|
if (read_request_line (connptr, &lines, &lines_len) < 0) {
|
||||||
update_stats (STAT_BADCONN);
|
update_stats (STAT_BADCONN);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
@ -1664,7 +1680,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
/*
|
/*
|
||||||
* Get all the headers from the client in a big hash.
|
* Get all the headers from the client in a big hash.
|
||||||
*/
|
*/
|
||||||
if (get_all_headers (connptr->client_fd, hashofheaders) < 0) {
|
if (get_all_headers (connptr->client_fd, hashofheaders, &lines, &lines_len) < 0) {
|
||||||
log_message (LOG_WARNING,
|
log_message (LOG_WARNING,
|
||||||
"Could not retrieve all the headers from the client");
|
"Could not retrieve all the headers from the client");
|
||||||
indicate_http_error (connptr, 400, "Bad Request",
|
indicate_http_error (connptr, 400, "Bad Request",
|
||||||
@ -1746,6 +1762,11 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
"file descriptor %d.", request->host,
|
"file descriptor %d.", request->host,
|
||||||
connptr->server_fd);
|
connptr->server_fd);
|
||||||
|
|
||||||
|
if(orderedmap_find (hashofheaders, "upgrade")) {
|
||||||
|
connptr->connect_method = CM_UPGRADE;
|
||||||
|
safe_write (connptr->server_fd, lines, lines_len);
|
||||||
|
}
|
||||||
|
|
||||||
if (!connptr->connect_method)
|
if (!connptr->connect_method)
|
||||||
establish_http_connection (connptr, request);
|
establish_http_connection (connptr, request);
|
||||||
}
|
}
|
||||||
@ -1772,6 +1793,8 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
|
|
||||||
HC_FAIL();
|
HC_FAIL();
|
||||||
}
|
}
|
||||||
|
} else if (connptr->connect_method == CM_UPGRADE) {
|
||||||
|
/* NOP */ ;
|
||||||
} else {
|
} else {
|
||||||
if (send_connect_method_response (connptr) < 0) {
|
if (send_connect_method_response (connptr) < 0) {
|
||||||
log_message (LOG_ERR,
|
log_message (LOG_ERR,
|
||||||
@ -1790,6 +1813,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
connptr->client_fd, connptr->server_fd);
|
connptr->client_fd, connptr->server_fd);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
safefree(lines);
|
||||||
free_request_struct (request);
|
free_request_struct (request);
|
||||||
orderedmap_destroy (hashofheaders);
|
orderedmap_destroy (hashofheaders);
|
||||||
conn_destroy_contents (connptr);
|
conn_destroy_contents (connptr);
|
||||||
|
Loading…
Reference in New Issue
Block a user