added content-length report on http body reading errors

This commit is contained in:
roberto@quantal64
2012-08-20 20:32:58 +02:00
parent 22c520043f
commit 7c09f294bf
2 changed files with 14 additions and 8 deletions
+10 -4
View File
@@ -1754,7 +1754,7 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) {
}
if (!ret) {
uwsgi_log("buffering POST data timed-out !!!\n");
uwsgi_log("buffering POST data to memory timed-out !!! (Content-Length: %llu received: %llu)\n", (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains);
return 0;
}
@@ -1765,10 +1765,16 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) {
len = read(wsgi_req->poll.fd, ptr, post_remains);
}
if (len <= 0) {
if (len < 0) {
uwsgi_error("read()");
return 0;
}
if (len == 0) {
uwsgi_log("client did not send the whole body: %s (Content-Length: %llu received: %llu)\n", strerror(errno), (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains);
return 0;
}
ptr += len;
post_remains -= len;
}
@@ -1867,7 +1873,7 @@ cycle:
}
if (!ret) {
uwsgi_log("buffering POST data timed-out !!!\n");
uwsgi_log("buffering POST data to disk timed-out !!! (Content-Length: %llu received: %llu)\n", (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains);
goto end;
}
@@ -1894,7 +1900,7 @@ cycle:
}
if (post_chunk == 0) {
uwsgi_log("client did not send the whole body: %s\n", strerror(errno));
uwsgi_log("client did not send the whole body: %s (Content-Length: %llu received: %llu)\n", strerror(errno), (unsigned long long) wsgi_req->post_cl, (unsigned long long) wsgi_req->post_cl - post_remains);
goto end;
}
+4 -4
View File
@@ -43,7 +43,7 @@ PyObject *uwsgi_Input_getline(uwsgi_Input *self) {
UWSGI_RELEASE_GIL;
if (uwsgi_waitfd(wsgi_req->poll.fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) <= 0) {
UWSGI_GET_GIL
return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data");
return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data (readline/getline)");
}
if (self->readline_max_size > 0 && self->readline_max_size < UWSGI_PY_READLINE_BUFSIZE) {
@@ -54,7 +54,7 @@ PyObject *uwsgi_Input_getline(uwsgi_Input *self) {
}
if (rlen <= 0) {
UWSGI_GET_GIL
return PyErr_Format(PyExc_IOError, "error reading wsgi.input data");
return PyErr_Format(PyExc_IOError, "error reading wsgi.input data (readline/getline)");
}
self->readline_size = rlen;
@@ -152,14 +152,14 @@ static PyObject *uwsgi_Input_read(uwsgi_Input *self, PyObject *args) {
if (uwsgi_waitfd(self->wsgi_req->poll.fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) <= 0) {
free(tmp_buf);
UWSGI_GET_GIL
return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data");
return PyErr_Format(PyExc_IOError, "error waiting for wsgi.input data: Content-Length %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) self->wsgi_req->post_cl - remains);
}
rlen = read(self->wsgi_req->poll.fd, tmp_buf+tmp_pos, remains);
if (rlen <= 0) {
free(tmp_buf);
UWSGI_GET_GIL
return PyErr_Format(PyExc_IOError, "error reading wsgi.input data");
return PyErr_Format(PyExc_IOError, "error reading wsgi.input data: Content-Length %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) self->wsgi_req->post_cl - remains);
}
tmp_pos += rlen;
remains -= rlen;