Changeset 3098 for pjproject/trunk


Ignore:
Timestamp:
Feb 11, 2010 12:50:42 PM (15 years ago)
Author:
ming
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjlib-util/http_client.c

    r3095 r3098  
    185185    pj_http_req *hreq = (pj_http_req*) pj_activesock_get_user_data(asock); 
    186186 
    187     if (hreq->state == ABORTING) 
     187    if (hreq->state == ABORTING || hreq->state == IDLE) 
    188188        return PJ_FALSE; 
    189189 
     
    208208    PJ_UNUSED_ARG(op_key); 
    209209 
    210     if (hreq->state == ABORTING) 
     210    if (hreq->state == ABORTING || hreq->state == IDLE) 
    211211        return PJ_FALSE; 
    212212 
     
    282282    TRACE_((THIS_FILE, "\nData received: %d bytes", size)); 
    283283 
    284     if (hreq->state == ABORTING) 
     284    if (hreq->state == ABORTING || hreq->state == IDLE) 
    285285        return PJ_FALSE; 
    286286 
     
    326326            hreq->response.data = NULL; 
    327327            hreq->response.size = 0; 
    328             if (rem > 0) { 
    329                 /* There is some response data remaining after parsing the 
    330                  * header, move it to the front of the buffer. 
    331                  */ 
    332                 pj_memmove((char *)data, (char *)data + size - rem, rem); 
    333                 *remainder = rem; 
    334             } 
    335             /* Speed up the operation a bit rather than waiting for EOF */ 
    336             if (hreq->response.content_length == 0) { 
    337                 return http_on_data_read(asock, NULL, 0, PJ_SUCCESS, NULL); 
    338             } 
    339  
     328 
     329            if (rem > 0 || hreq->response.content_length == 0) 
     330                http_on_data_read(asock, (rem == 0 ? NULL: 
     331                                  (char *)data + size - rem), 
     332                                  rem, PJ_SUCCESS, NULL); 
    340333        } 
    341334 
     
    343336    } 
    344337 
    345     pj_assert(hreq->state == READING_DATA); 
     338    if (hreq->state != READING_DATA) 
     339        return PJ_FALSE; 
    346340    if (hreq->cb.on_data_read) { 
    347341        /* If application wishes to receive the data once available, call 
     
    386380     * or if it's already EOF. 
    387381     */ 
    388     if ((pj_ssize_t)hreq->tcp_state.current_read_size >=  
    389         hreq->response.content_length || 
     382    if ((hreq->response.content_length >=0 && 
     383        (pj_ssize_t)hreq->tcp_state.current_read_size >= 
     384        hreq->response.content_length) || 
    390385        (status == PJ_EEOF && hreq->response.content_length == -1))  
    391386    { 
     
    783778                                  &http_req->addr, &http_req->hurl.host, 
    784779                                  http_req->hurl.port); 
    785         if (status != PJ_SUCCESS ||  
     780        if (status != PJ_SUCCESS || 
    786781            !pj_sockaddr_has_addr(&http_req->addr) || 
    787             (http_req->param.addr_family==pj_AF_INET() &&  
    788              http_req->addr.ipv4.sin_addr.s_addr==PJ_INADDR_NONE))  
     782            (http_req->param.addr_family==pj_AF_INET() && 
     783             http_req->addr.ipv4.sin_addr.s_addr==PJ_INADDR_NONE)) 
    789784        { 
    790785            return status; // cannot resolve host name 
Note: See TracChangeset for help on using the changeset viewer.