http header: allow Content-Length to be replaced
In some cases Content-Length: couldn't be replaced by an application Also, indented some code properly
This commit is contained in:
parent
87a45c7998
commit
5f0764870f
130
lib/http.c
130
lib/http.c
@ -1803,8 +1803,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if((conn->handler->protocol&CURLPROTO_HTTP) &&
|
if((conn->handler->protocol&CURLPROTO_HTTP) &&
|
||||||
data->set.upload &&
|
data->set.upload &&
|
||||||
(data->set.infilesize == -1)) {
|
(data->set.infilesize == -1)) {
|
||||||
if(conn->bits.authneg)
|
if(conn->bits.authneg)
|
||||||
/* don't enable chunked during auth neg */
|
/* don't enable chunked during auth neg */
|
||||||
;
|
;
|
||||||
@ -1982,7 +1982,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
* This is meant to get the size of the present remote-file by itself.
|
* This is meant to get the size of the present remote-file by itself.
|
||||||
* We don't support this now. Bail out!
|
* We don't support this now. Bail out!
|
||||||
*/
|
*/
|
||||||
data->state.resume_from = 0;
|
data->state.resume_from = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(data->state.resume_from && !data->state.this_is_a_follow) {
|
if(data->state.resume_from && !data->state.this_is_a_follow) {
|
||||||
@ -2073,17 +2073,17 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
curl_off_t total_expected_size=
|
curl_off_t total_expected_size=
|
||||||
data->state.resume_from + data->set.infilesize;
|
data->state.resume_from + data->set.infilesize;
|
||||||
conn->allocptr.rangeline =
|
conn->allocptr.rangeline =
|
||||||
aprintf("Content-Range: bytes %s%" FORMAT_OFF_T
|
aprintf("Content-Range: bytes %s%" FORMAT_OFF_T
|
||||||
"/%" FORMAT_OFF_T "\r\n",
|
"/%" FORMAT_OFF_T "\r\n",
|
||||||
data->state.range, total_expected_size-1,
|
data->state.range, total_expected_size-1,
|
||||||
total_expected_size);
|
total_expected_size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Range was selected and then we just pass the incoming range and
|
/* Range was selected and then we just pass the incoming range and
|
||||||
append total size */
|
append total size */
|
||||||
conn->allocptr.rangeline =
|
conn->allocptr.rangeline =
|
||||||
aprintf("Content-Range: bytes %s/%" FORMAT_OFF_T "\r\n",
|
aprintf("Content-Range: bytes %s/%" FORMAT_OFF_T "\r\n",
|
||||||
data->state.range, data->set.infilesize);
|
data->state.range, data->set.infilesize);
|
||||||
}
|
}
|
||||||
if(!conn->allocptr.rangeline)
|
if(!conn->allocptr.rangeline)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -2116,45 +2116,47 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
result = Curl_add_bufferf(req_buffer,
|
result =
|
||||||
"%s" /* ftp typecode (;type=x) */
|
Curl_add_bufferf(req_buffer,
|
||||||
" HTTP/%s\r\n" /* HTTP version */
|
"%s" /* ftp typecode (;type=x) */
|
||||||
"%s" /* proxyuserpwd */
|
" HTTP/%s\r\n" /* HTTP version */
|
||||||
"%s" /* userpwd */
|
"%s" /* proxyuserpwd */
|
||||||
"%s" /* range */
|
"%s" /* userpwd */
|
||||||
"%s" /* user agent */
|
"%s" /* range */
|
||||||
"%s" /* host */
|
"%s" /* user agent */
|
||||||
"%s" /* accept */
|
"%s" /* host */
|
||||||
"%s" /* TE: */
|
"%s" /* accept */
|
||||||
"%s" /* accept-encoding */
|
"%s" /* TE: */
|
||||||
"%s" /* referer */
|
"%s" /* accept-encoding */
|
||||||
"%s" /* Proxy-Connection */
|
"%s" /* referer */
|
||||||
"%s",/* transfer-encoding */
|
"%s" /* Proxy-Connection */
|
||||||
|
"%s",/* transfer-encoding */
|
||||||
|
|
||||||
ftp_typecode,
|
ftp_typecode,
|
||||||
httpstring,
|
httpstring,
|
||||||
conn->allocptr.proxyuserpwd?
|
conn->allocptr.proxyuserpwd?
|
||||||
conn->allocptr.proxyuserpwd:"",
|
conn->allocptr.proxyuserpwd:"",
|
||||||
conn->allocptr.userpwd?conn->allocptr.userpwd:"",
|
conn->allocptr.userpwd?conn->allocptr.userpwd:"",
|
||||||
(data->state.use_range && conn->allocptr.rangeline)?
|
(data->state.use_range && conn->allocptr.rangeline)?
|
||||||
conn->allocptr.rangeline:"",
|
conn->allocptr.rangeline:"",
|
||||||
(data->set.str[STRING_USERAGENT] &&
|
(data->set.str[STRING_USERAGENT] &&
|
||||||
*data->set.str[STRING_USERAGENT] && conn->allocptr.uagent)?
|
*data->set.str[STRING_USERAGENT] &&
|
||||||
conn->allocptr.uagent:"",
|
conn->allocptr.uagent)?
|
||||||
(conn->allocptr.host?conn->allocptr.host:""), /* Host: host */
|
conn->allocptr.uagent:"",
|
||||||
http->p_accept?http->p_accept:"",
|
(conn->allocptr.host?conn->allocptr.host:""),
|
||||||
conn->allocptr.te?conn->allocptr.te:"",
|
http->p_accept?http->p_accept:"",
|
||||||
(data->set.str[STRING_ENCODING] &&
|
conn->allocptr.te?conn->allocptr.te:"",
|
||||||
*data->set.str[STRING_ENCODING] &&
|
(data->set.str[STRING_ENCODING] &&
|
||||||
conn->allocptr.accept_encoding)?
|
*data->set.str[STRING_ENCODING] &&
|
||||||
conn->allocptr.accept_encoding:"",
|
conn->allocptr.accept_encoding)?
|
||||||
(data->change.referer && conn->allocptr.ref)?
|
conn->allocptr.accept_encoding:"",
|
||||||
conn->allocptr.ref:"" /* Referer: <data> */,
|
(data->change.referer && conn->allocptr.ref)?
|
||||||
(conn->bits.httpproxy &&
|
conn->allocptr.ref:"" /* Referer: <data> */,
|
||||||
!conn->bits.tunnel_proxy &&
|
(conn->bits.httpproxy &&
|
||||||
!Curl_checkheaders(data, "Proxy-Connection:"))?
|
!conn->bits.tunnel_proxy &&
|
||||||
"Proxy-Connection: Keep-Alive\r\n":"",
|
!Curl_checkheaders(data, "Proxy-Connection:"))?
|
||||||
te
|
"Proxy-Connection: Keep-Alive\r\n":"",
|
||||||
|
te
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2194,8 +2196,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = Curl_add_bufferf(req_buffer,
|
result = Curl_add_bufferf(req_buffer,
|
||||||
"%s%s=%s", count?"; ":"",
|
"%s%s=%s", count?"; ":"",
|
||||||
co->name, co->value);
|
co->name, co->value);
|
||||||
if(result)
|
if(result)
|
||||||
break;
|
break;
|
||||||
count++;
|
count++;
|
||||||
@ -2209,8 +2211,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
result = Curl_add_bufferf(req_buffer, "Cookie: ");
|
result = Curl_add_bufferf(req_buffer, "Cookie: ");
|
||||||
if(CURLE_OK == result) {
|
if(CURLE_OK == result) {
|
||||||
result = Curl_add_bufferf(req_buffer, "%s%s",
|
result = Curl_add_bufferf(req_buffer, "%s%s",
|
||||||
count?"; ":"",
|
count?"; ":"",
|
||||||
addcookies);
|
addcookies);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2277,11 +2279,12 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
|
|
||||||
http->sending = HTTPSEND_BODY;
|
http->sending = HTTPSEND_BODY;
|
||||||
|
|
||||||
if(!data->req.upload_chunky) {
|
if(!data->req.upload_chunky &&
|
||||||
|
!Curl_checkheaders(data, "Content-Length:")) {
|
||||||
/* only add Content-Length if not uploading chunked */
|
/* only add Content-Length if not uploading chunked */
|
||||||
result = Curl_add_bufferf(req_buffer,
|
result = Curl_add_bufferf(req_buffer,
|
||||||
"Content-Length: %" FORMAT_OFF_T "\r\n",
|
"Content-Length: %" FORMAT_OFF_T "\r\n",
|
||||||
http->postsize);
|
http->postsize);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2348,11 +2351,12 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
else
|
else
|
||||||
postsize = data->set.infilesize;
|
postsize = data->set.infilesize;
|
||||||
|
|
||||||
if((postsize != -1) && !data->req.upload_chunky) {
|
if((postsize != -1) && !data->req.upload_chunky &&
|
||||||
|
!Curl_checkheaders(data, "Content-Length:")) {
|
||||||
/* only add Content-Length if not uploading chunked */
|
/* only add Content-Length if not uploading chunked */
|
||||||
result = Curl_add_bufferf(req_buffer,
|
result = Curl_add_bufferf(req_buffer,
|
||||||
"Content-Length: %" FORMAT_OFF_T "\r\n",
|
"Content-Length: %" FORMAT_OFF_T "\r\n",
|
||||||
postsize );
|
postsize );
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2402,8 +2406,8 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
/* we allow replacing this header if not during auth negotiation,
|
/* we allow replacing this header if not during auth negotiation,
|
||||||
although it isn't very wise to actually set your own */
|
although it isn't very wise to actually set your own */
|
||||||
result = Curl_add_bufferf(req_buffer,
|
result = Curl_add_bufferf(req_buffer,
|
||||||
"Content-Length: %" FORMAT_OFF_T"\r\n",
|
"Content-Length: %" FORMAT_OFF_T"\r\n",
|
||||||
postsize);
|
postsize);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -2453,7 +2457,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
/* We're not sending it 'chunked', append it to the request
|
/* We're not sending it 'chunked', append it to the request
|
||||||
already now to reduce the number if send() calls */
|
already now to reduce the number if send() calls */
|
||||||
result = Curl_add_buffer(req_buffer, data->set.postfields,
|
result = Curl_add_buffer(req_buffer, data->set.postfields,
|
||||||
(size_t)postsize);
|
(size_t)postsize);
|
||||||
included_body = postsize;
|
included_body = postsize;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2461,10 +2465,10 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
result = Curl_add_bufferf(req_buffer, "%x\r\n", (int)postsize);
|
result = Curl_add_bufferf(req_buffer, "%x\r\n", (int)postsize);
|
||||||
if(CURLE_OK == result)
|
if(CURLE_OK == result)
|
||||||
result = Curl_add_buffer(req_buffer, data->set.postfields,
|
result = Curl_add_buffer(req_buffer, data->set.postfields,
|
||||||
(size_t)postsize);
|
(size_t)postsize);
|
||||||
if(CURLE_OK == result)
|
if(CURLE_OK == result)
|
||||||
result = Curl_add_buffer(req_buffer,
|
result = Curl_add_buffer(req_buffer,
|
||||||
"\x0d\x0a\x30\x0d\x0a\x0d\x0a", 7);
|
"\x0d\x0a\x30\x0d\x0a\x0d\x0a", 7);
|
||||||
/* CR LF 0 CR LF CR LF */
|
/* CR LF 0 CR LF CR LF */
|
||||||
included_body = postsize + 7;
|
included_body = postsize + 7;
|
||||||
}
|
}
|
||||||
@ -2500,7 +2504,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
|
|||||||
/* Chunky upload is selected and we're negotiating auth still, send
|
/* Chunky upload is selected and we're negotiating auth still, send
|
||||||
end-of-data only */
|
end-of-data only */
|
||||||
result = Curl_add_buffer(req_buffer,
|
result = Curl_add_buffer(req_buffer,
|
||||||
"\x0d\x0a\x30\x0d\x0a\x0d\x0a", 7);
|
"\x0d\x0a\x30\x0d\x0a\x0d\x0a", 7);
|
||||||
/* CR LF 0 CR LF CR LF */
|
/* CR LF 0 CR LF CR LF */
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user