Commit 97392645 authored by Sergey Lyubka's avatar Sergey Lyubka

Refactored read_request()

parent 995d7bd1
...@@ -2648,18 +2648,15 @@ static int parse_http_request(char *buf, struct mg_request_info *ri) { ...@@ -2648,18 +2648,15 @@ static int parse_http_request(char *buf, struct mg_request_info *ri) {
// Upon every read operation, increase nread by the number of bytes read. // Upon every read operation, increase nread by the number of bytes read.
static int read_request(FILE *fp, SOCKET sock, SSL *ssl, char *buf, int bufsiz, static int read_request(FILE *fp, SOCKET sock, SSL *ssl, char *buf, int bufsiz,
int *nread) { int *nread) {
int n, request_len; int request_len, n = 0;
request_len = 0; do {
while (*nread < bufsiz && request_len == 0) {
n = pull(fp, sock, ssl, buf + *nread, bufsiz - *nread);
if (n <= 0) {
break;
} else {
*nread += n;
request_len = get_request_len(buf, *nread); request_len = get_request_len(buf, *nread);
if (request_len == 0 &&
(n = pull(fp, sock, ssl, buf + *nread, bufsiz - *nread)) > 0) {
*nread += n;
} }
} } while (*nread < bufsiz && request_len == 0 && n > 0);
return request_len; return request_len;
} }
...@@ -3892,12 +3889,9 @@ static void process_new_connection(struct mg_connection *conn) { ...@@ -3892,12 +3889,9 @@ static void process_new_connection(struct mg_connection *conn) {
do { do {
reset_per_request_attributes(conn); reset_per_request_attributes(conn);
// If next request is not pipelined, read it in
if ((conn->request_len = get_request_len(conn->buf, conn->data_len)) == 0) {
conn->request_len = read_request(NULL, conn->client.sock, conn->ssl, conn->request_len = read_request(NULL, conn->client.sock, conn->ssl,
conn->buf, conn->buf_size, &conn->data_len); conn->buf, conn->buf_size,
} &conn->data_len);
assert(conn->data_len >= conn->request_len); assert(conn->data_len >= conn->request_len);
if (conn->request_len == 0 && conn->data_len == conn->buf_size) { if (conn->request_len == 0 && conn->data_len == conn->buf_size) {
send_http_error(conn, 413, "Request Too Large", ""); send_http_error(conn, 413, "Request Too Large", "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment