diff options
Diffstat (limited to 'lib/http.c')
-rw-r--r-- | lib/http.c | 125 |
1 files changed, 51 insertions, 74 deletions
@@ -977,12 +977,15 @@ Curl_send_buffer *Curl_add_buffer_init(void) * Returns CURLcode */ CURLcode Curl_add_buffer_send(Curl_send_buffer *in, - struct connectdata *conn, - long *bytes_written, /* add the number of sent bytes - to this counter */ - size_t included_body_bytes, /* how much of the buffer - contains body data */ - int socketindex) + struct connectdata *conn, + + /* add the number of sent bytes to this + counter */ + long *bytes_written, + + /* how much of the buffer contains body data */ + size_t included_body_bytes, + int socketindex) { ssize_t amount; @@ -1069,7 +1072,10 @@ CURLcode Curl_add_buffer_send(Curl_send_buffer *in, accordingly */ http->writebytecount += bodylen; - *bytes_written += amount; + /* 'amount' can never be a very large value here so typecasting it so a + signed 31 bit value should not cause problems even if ssize_t is + 64bit */ + *bytes_written += (long)amount; if(http) { if((size_t)amount != size) { @@ -1283,7 +1289,6 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn, struct SessionHandle *data=conn->data; struct SingleRequest *k = &data->req; CURLcode result; - int res; long timeout = data->set.timeout?data->set.timeout:PROXY_TIMEOUT; /* in milliseconds */ curl_socket_t tunnelsocket = conn->sock[sockindex]; @@ -1381,7 +1386,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn, if(CURLE_OK == result) { /* Now send off the request */ result = Curl_add_buffer_send(req_buffer, conn, - &data->info.request_size, 0, sockindex); + &data->info.request_size, 0, sockindex); } req_buffer = NULL; if(result) @@ -1467,11 +1472,10 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn, break; default: DEBUGASSERT(ptr+BUFSIZE-nread <= data->state.buffer+BUFSIZE+1); - res = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread, &gotbytes); - if(res< 0) - /* EWOULDBLOCK */ + result = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread, &gotbytes); + if(result==CURLE_AGAIN) continue; /* go loop yourself */ - else if(res) + else if(result) keepon = FALSE; else if(gotbytes <= 0) { keepon = FALSE; @@ -1817,9 +1821,9 @@ static CURLcode https_connecting(struct connectdata *conn, bool *done) } #endif -#ifdef USE_SSLEAY -/* This function is OpenSSL-specific. It should be made to query the generic - SSL layer instead. */ +#if defined(USE_SSLEAY) || defined(USE_GNUTLS) +/* This function is for OpenSSL and GnuTLS only. It should be made to query + the generic SSL layer instead. */ static int https_getsock(struct connectdata *conn, curl_socket_t *socks, int numsocks) @@ -1844,7 +1848,7 @@ static int https_getsock(struct connectdata *conn, return CURLE_OK; } #else -#ifdef USE_GNUTLS +#ifdef USE_NSS static int https_getsock(struct connectdata *conn, curl_socket_t *socks, int numsocks) @@ -1855,7 +1859,7 @@ static int https_getsock(struct connectdata *conn, return GETSOCK_BLANK; } #else -#ifdef USE_NSS +#ifdef USE_QSOSSL static int https_getsock(struct connectdata *conn, curl_socket_t *socks, int numsocks) @@ -1866,7 +1870,7 @@ static int https_getsock(struct connectdata *conn, return GETSOCK_BLANK; } #else -#ifdef USE_QSOSSL +#ifdef USE_POLARSSL static int https_getsock(struct connectdata *conn, curl_socket_t *socks, int numsocks) @@ -2224,7 +2228,10 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) if((conn->protocol&PROT_HTTP) && data->set.upload && (data->set.infilesize == -1)) { - if (use_http_1_1(data, conn)) { + if(conn->bits.authneg) + /* don't enable chunked during auth neg */ + ; + else if(use_http_1_1(data, conn)) { /* HTTP, upload, unknown file size and not HTTP 1.0 */ data->req.upload_chunky = TRUE; } @@ -2529,7 +2536,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) /* url */ if (paste_ftp_userpwd) result = Curl_add_bufferf(req_buffer, "ftp://%s:%s@%s", - conn->user, conn->passwd, ppath + sizeof("ftp://") - 1); + conn->user, conn->passwd, + ppath + sizeof("ftp://") - 1); else result = Curl_add_buffer(req_buffer, ppath, strlen(ppath)); if (result) @@ -2665,14 +2673,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) return result; result = Curl_add_buffer_send(req_buffer, conn, - &data->info.request_size, 0, FIRSTSOCKET); + &data->info.request_size, 0, FIRSTSOCKET); if(result) failf(data, "Failed sending POST request"); else /* setup variables for the upcoming transfer */ - result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, - &http->readbytecount, - -1, NULL); + Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, &http->readbytecount, + -1, NULL); break; } @@ -2735,15 +2742,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) /* fire away the whole request to the server */ result = Curl_add_buffer_send(req_buffer, conn, - &data->info.request_size, 0, FIRSTSOCKET); + &data->info.request_size, 0, FIRSTSOCKET); if(result) failf(data, "Failed sending POST request"); else /* setup variables for the upcoming transfer */ - result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, - &http->readbytecount, - FIRSTSOCKET, - &http->writebytecount); + Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, + &http->readbytecount, FIRSTSOCKET, + &http->writebytecount); if(result) { Curl_formclean(&http->sendit); /* free that whole lot */ @@ -2788,15 +2794,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) /* this sends the buffer and frees all the buffer resources */ result = Curl_add_buffer_send(req_buffer, conn, - &data->info.request_size, 0, FIRSTSOCKET); + &data->info.request_size, 0, FIRSTSOCKET); if(result) failf(data, "Failed sending PUT request"); else /* prepare for transfer */ - result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, - &http->readbytecount, - postsize?FIRSTSOCKET:-1, - postsize?&http->writebytecount:NULL); + Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, + &http->readbytecount, postsize?FIRSTSOCKET:-1, + postsize?&http->writebytecount:NULL); if(result) return result; break; @@ -2889,6 +2894,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) } if(result) return result; + /* Make sure the progress information is accurate */ + Curl_pgrsSetUploadSize(data, postsize); } else { /* A huge POST coming up, do data separate from the request */ @@ -2938,16 +2945,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) } /* issue the request */ result = Curl_add_buffer_send(req_buffer, conn, &data->info.request_size, - (size_t)included_body, FIRSTSOCKET); + (size_t)included_body, FIRSTSOCKET); if(result) failf(data, "Failed sending HTTP POST request"); else - result = - Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, - &http->readbytecount, - http->postdata?FIRSTSOCKET:-1, - http->postdata?&http->writebytecount:NULL); + Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, + &http->readbytecount, http->postdata?FIRSTSOCKET:-1, + http->postdata?&http->writebytecount:NULL); break; default: @@ -2957,16 +2962,15 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) /* issue the request */ result = Curl_add_buffer_send(req_buffer, conn, - &data->info.request_size, 0, FIRSTSOCKET); + &data->info.request_size, 0, FIRSTSOCKET); if(result) failf(data, "Failed sending HTTP request"); else /* HTTP GET/HEAD download: */ - result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, - &http->readbytecount, - http->postdata?FIRSTSOCKET:-1, - http->postdata?&http->writebytecount:NULL); + Curl_setup_transfer(conn, FIRSTSOCKET, -1, TRUE, &http->readbytecount, + http->postdata?FIRSTSOCKET:-1, + http->postdata?&http->writebytecount:NULL); } if(result) return result; @@ -3289,13 +3293,6 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data, data->req.deductheadercount = (100 <= k->httpcode && 199 >= k->httpcode)?data->req.headerbytecount:0; - if(data->state.resume_from && - (data->set.httpreq==HTTPREQ_GET) && - (k->httpcode == 416)) { - /* "Requested Range Not Satisfiable" */ - *stop_reading = TRUE; - } - if(!*stop_reading) { /* Curl_http_auth_act() checks what authentication methods * that are available and decides which one (if any) to @@ -3508,9 +3505,6 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data, * message-body, and thus is always terminated by the first * empty line after the header fields. */ /* FALLTHROUGH */ - case 416: /* Requested Range Not Satisfiable, it has the - Content-Length: set as the "real" document but no - actual response is sent. */ case 304: /* (quote from RFC2616, section 10.3.5): The 304 response * MUST NOT contain a message-body, and thus is always @@ -3542,10 +3536,7 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data, /* Curl_convert_from_network calls failf if unsuccessful */ #endif /* CURL_DOES_CONVERSIONS */ - /* Check for Content-Length: header lines to get size. Ignore - the header completely if we get a 416 response as then we're - resuming a document that we don't get, and this header contains - info about the true size of the document we didn't get now. */ + /* Check for Content-Length: header lines to get size */ if(!k->ignorecl && !data->set.ignorecl && checkprefix("Content-Length:", k->p)) { curl_off_t contentlength = curlx_strtoofft(k->p+15, NULL, 10); @@ -3643,20 +3634,6 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data, /* init our chunky engine */ Curl_httpchunk_init(conn); } - - else if(checkprefix("Trailer:", k->p) || - checkprefix("Trailers:", k->p)) { - /* - * This test helps Curl_httpchunk_read() to determine to look - * for well formed trailers after the zero chunksize record. In - * this case a CRLF is required after the zero chunksize record - * when no trailers are sent, or after the last trailer record. - * - * It seems both Trailer: and Trailers: occur in the wild. - */ - k->trailerhdrpresent = TRUE; - } - else if(checkprefix("Content-Encoding:", k->p) && data->set.str[STRING_ENCODING]) { /* |