aboutsummaryrefslogtreecommitdiff
path: root/lib/http.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-04-25 00:48:56 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-05-01 22:55:29 +0200
commit87eb8d5b30ce2adfe2673cc0b1abf6ca68891cc4 (patch)
treef7ed54448bf9fa13664139bc94e5487bb4ca5745 /lib/http.c
parentf535f4f5fc6cbdce1aec5a3481cec37369dca468 (diff)
http: don't clobber the receive buffer for timecond
Diffstat (limited to 'lib/http.c')
-rw-r--r--lib/http.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/http.c b/lib/http.c
index 04bcbae0d..af3a8db8f 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -1695,9 +1695,10 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
Curl_send_buffer *req_buffer)
{
const struct tm *tm;
- char *buf = data->state.buffer;
struct tm keeptime;
CURLcode result;
+ char datestr[80];
+ const char *condp;
if(data->set.timecondition == CURL_TIMECOND_NONE)
/* no condition was asked for */
@@ -1710,6 +1711,21 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
}
tm = &keeptime;
+ switch(data->set.timecondition) {
+ default:
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ case CURL_TIMECOND_IFMODSINCE:
+ condp = "If-Modified-Since";
+ break;
+ case CURL_TIMECOND_IFUNMODSINCE:
+ condp = "If-Unmodified-Since";
+ break;
+ case CURL_TIMECOND_LASTMOD:
+ condp = "Last-Modified";
+ break;
+ }
+
/* The If-Modified-Since header family should have their times set in
* GMT as RFC2616 defines: "All HTTP date/time stamps MUST be
* represented in Greenwich Mean Time (GMT), without exception. For the
@@ -1718,8 +1734,9 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
*/
/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
- snprintf(buf, BUFSIZE-1,
- "%s, %02d %s %4d %02d:%02d:%02d GMT",
+ snprintf(datestr, sizeof(datestr),
+ "%s: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
+ condp,
Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
tm->tm_mday,
Curl_month[tm->tm_mon],
@@ -1728,22 +1745,7 @@ CURLcode Curl_add_timecondition(struct Curl_easy *data,
tm->tm_min,
tm->tm_sec);
- switch(data->set.timecondition) {
- default:
- break;
- case CURL_TIMECOND_IFMODSINCE:
- result = Curl_add_bufferf(req_buffer,
- "If-Modified-Since: %s\r\n", buf);
- break;
- case CURL_TIMECOND_IFUNMODSINCE:
- result = Curl_add_bufferf(req_buffer,
- "If-Unmodified-Since: %s\r\n", buf);
- break;
- case CURL_TIMECOND_LASTMOD:
- result = Curl_add_bufferf(req_buffer,
- "Last-Modified: %s\r\n", buf);
- break;
- }
+ result = Curl_add_buffer(req_buffer, datestr, strlen(datestr));
return result;
}