#include "istream.h"
#include "ostream.h"
#include "http-url.h"
+#include "http-date.h"
#include "http-response-parser.h"
#include "http-transfer.h"
req->callback = callback;
req->context = context;
req->headers = str_new(default_pool, 256);
+ req->date = (time_t)-1;
req->state = HTTP_REQUEST_STATE_NEW;
return req;
const char *key, const char *value)
{
i_assert(req->state == HTTP_REQUEST_STATE_NEW);
+ /* don't allow setting Date header directly;
+ this is ignored for now for backwards compatibility */
+ if (strcasecmp(key, "Date") == 0)
+ return;
str_printfa(req->headers, "%s: %s\r\n", key, value);
}
+void http_client_request_set_date(struct http_client_request *req,
+ time_t date)
+{
+ i_assert(req->state == HTTP_REQUEST_STATE_NEW);
+ req->date = date;
+}
+
void http_client_request_set_payload(struct http_client_request *req,
struct istream *input, bool sync)
{
struct http_client_host *host;
i_assert(req->state == HTTP_REQUEST_STATE_NEW);
+
+ /* use submission date if no date is set explicitly */
+ if (req->date == (time_t)-1)
+ req->date = ioloop_time;
host = http_client_host_get(req->client, req->hostname);
req->state = HTTP_REQUEST_STATE_QUEUED;
str_append(rtext, req->method);
str_append(rtext, " ");
str_append(rtext, req->target);
- str_append(rtext, " HTTP/1.1\r\n");
- str_append(rtext, "Host: ");
+ str_append(rtext, " HTTP/1.1\r\nHost: ");
str_append(rtext, req->hostname);
if ((!req->ssl &&req->port != HTTP_DEFAULT_PORT) ||
(req->ssl && req->port != HTTPS_DEFAULT_PORT)) {
str_printfa(rtext, ":%u", req->port);
}
+ str_append(rtext, "\r\nDate: ");
+ str_append(rtext, http_date_create(req->date));
str_append(rtext, "\r\n");
if (req->payload_sync) {
str_append(rtext, "Expect: 100-continue\r\n");