summaryrefslogtreecommitdiff
path: root/pjlib-util/src
diff options
context:
space:
mode:
authorLiong Sauw Ming <ming@teluu.com>2010-02-11 12:50:42 +0000
committerLiong Sauw Ming <ming@teluu.com>2010-02-11 12:50:42 +0000
commit327a139d0b7c6aa1237418b46d0b76ad0d2767ae (patch)
treeec6d0a6ad80c0c5e9b114675295ce040a59c58c2 /pjlib-util/src
parent6e7425c8d63ed4ea1b86c65d782b237d0358a30d (diff)
More ticket #1018:
* Immediately process response body after receiving the header. * Fix GET method when Content-Length header is not specified. * Fix checking when HTTP request is cancelled. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3098 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src')
-rw-r--r--pjlib-util/src/pjlib-util/http_client.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/pjlib-util/src/pjlib-util/http_client.c b/pjlib-util/src/pjlib-util/http_client.c
index bff68e2a..05b5c50f 100644
--- a/pjlib-util/src/pjlib-util/http_client.c
+++ b/pjlib-util/src/pjlib-util/http_client.c
@@ -184,7 +184,7 @@ static pj_bool_t http_on_connect(pj_activesock_t *asock,
{
pj_http_req *hreq = (pj_http_req*) pj_activesock_get_user_data(asock);
- if (hreq->state == ABORTING)
+ if (hreq->state == ABORTING || hreq->state == IDLE)
return PJ_FALSE;
if (status != PJ_SUCCESS) {
@@ -207,7 +207,7 @@ static pj_bool_t http_on_data_sent(pj_activesock_t *asock,
PJ_UNUSED_ARG(op_key);
- if (hreq->state == ABORTING)
+ if (hreq->state == ABORTING || hreq->state == IDLE)
return PJ_FALSE;
if (sent <= 0) {
@@ -281,7 +281,7 @@ static pj_bool_t http_on_data_read(pj_activesock_t *asock,
TRACE_((THIS_FILE, "\nData received: %d bytes", size));
- if (hreq->state == ABORTING)
+ if (hreq->state == ABORTING || hreq->state == IDLE)
return PJ_FALSE;
if (hreq->state == READING_RESPONSE) {
@@ -325,24 +325,18 @@ static pj_bool_t http_on_data_read(pj_activesock_t *asock,
(*hreq->cb.on_response)(hreq, &hreq->response);
hreq->response.data = NULL;
hreq->response.size = 0;
- if (rem > 0) {
- /* There is some response data remaining after parsing the
- * header, move it to the front of the buffer.
- */
- pj_memmove((char *)data, (char *)data + size - rem, rem);
- *remainder = rem;
- }
- /* Speed up the operation a bit rather than waiting for EOF */
- if (hreq->response.content_length == 0) {
- return http_on_data_read(asock, NULL, 0, PJ_SUCCESS, NULL);
- }
+ if (rem > 0 || hreq->response.content_length == 0)
+ http_on_data_read(asock, (rem == 0 ? NULL:
+ (char *)data + size - rem),
+ rem, PJ_SUCCESS, NULL);
}
return PJ_TRUE;
}
- pj_assert(hreq->state == READING_DATA);
+ if (hreq->state != READING_DATA)
+ return PJ_FALSE;
if (hreq->cb.on_data_read) {
/* If application wishes to receive the data once available, call
* its callback.
@@ -385,8 +379,9 @@ static pj_bool_t http_on_data_read(pj_activesock_t *asock,
/* If the total data received so far is equal to the content length
* or if it's already EOF.
*/
- if ((pj_ssize_t)hreq->tcp_state.current_read_size >=
- hreq->response.content_length ||
+ if ((hreq->response.content_length >=0 &&
+ (pj_ssize_t)hreq->tcp_state.current_read_size >=
+ hreq->response.content_length) ||
(status == PJ_EEOF && hreq->response.content_length == -1))
{
/* Finish reading */
@@ -782,10 +777,10 @@ PJ_DEF(pj_status_t) pj_http_req_start(pj_http_req *http_req)
status = pj_sockaddr_init(http_req->param.addr_family,
&http_req->addr, &http_req->hurl.host,
http_req->hurl.port);
- if (status != PJ_SUCCESS ||
+ if (status != PJ_SUCCESS ||
!pj_sockaddr_has_addr(&http_req->addr) ||
- (http_req->param.addr_family==pj_AF_INET() &&
- http_req->addr.ipv4.sin_addr.s_addr==PJ_INADDR_NONE))
+ (http_req->param.addr_family==pj_AF_INET() &&
+ http_req->addr.ipv4.sin_addr.s_addr==PJ_INADDR_NONE))
{
return status; // cannot resolve host name
}