const char *reason;
string_t *headers;
+ ARRAY_TYPE(string) perm_headers;
time_t date;
ARRAY_TYPE(http_auth_challenge) auth_challenges;
payload_handler_raw_input, rhandler);
i_stream_set_input_pending(conn->incoming_payload, TRUE);
}
+
+void http_server_request_add_response_header(struct http_server_request *req,
+ const char *key, const char *value)
+{
+ struct http_server_response *resp;
+
+ resp = http_server_response_create(req, 0, "");
+ http_server_response_add_permanent_header(resp, key, value);
+}
start a new one (would usually be a failure response)
*/
resp = req->response;
+
+ ARRAY_TYPE(string) perm_headers = resp->perm_headers;
+ i_zero(&resp->perm_headers);
+
http_server_response_free(resp);
i_zero(resp);
+
+ resp->perm_headers = perm_headers;
}
resp->request = req;
resp->headers = str_new(default_pool, 256);
resp->date = (time_t)-1;
+ if (array_is_created(&resp->perm_headers)) {
+ unsigned int i, count;
+ char *const *headers = array_get(&resp->perm_headers, &count);
+ for (i = 0; i < count; i += 2)
+ http_server_response_add_header(resp, headers[i],
+ headers[i+1]);
+ }
return resp;
}
i_stream_unref(&resp->payload_input);
o_stream_unref(&resp->payload_output);
str_free(&resp->headers);
+
+ if (array_is_created(&resp->perm_headers)) {
+ char **headers;
+
+ array_foreach_modifiable(&resp->perm_headers, headers)
+ i_free(*headers);
+ array_free(&resp->perm_headers);
+ }
}
void http_server_response_add_header(struct http_server_response *resp,
i_assert(resp != NULL);
return resp->payload_size + str_len(resp->headers);
}
+
+void http_server_response_add_permanent_header(struct http_server_response *resp,
+ const char *key, const char *value)
+{
+ char *key_dup = i_strdup(key), *value_dup = i_strdup(value);
+
+ http_server_response_add_header(resp, key, value);
+
+ if (!array_is_created(&resp->perm_headers))
+ i_array_init(&resp->perm_headers, 4);
+ key_dup = i_strdup(key);
+ value_dup = i_strdup(value);
+ array_push_back(&resp->perm_headers, &key_dup);
+ array_push_back(&resp->perm_headers, &value_dup);
+}
otherwise created implicitly. */
void http_server_response_add_header(struct http_server_response *resp,
const char *key, const char *value);
+/* Add a header permanently to the response. Even if another response is
+ created for the request, this header is kept. */
+void http_server_response_add_permanent_header(struct http_server_response *resp,
+ const char *key, const char *value);
/* Change the response code and text, cannot be used after submission */
void http_server_response_update_status(struct http_server_response *resp,
unsigned int status, const char *reason);
or because the request was aborted. */
bool http_server_request_is_finished(struct http_server_request *req);
+/* Add a header to any HTTP response created for the HTTP request. */
+void http_server_request_add_response_header(struct http_server_request *req,
+ const char *key, const char *value);
+
/* Return input stream for the request's payload. Optionally, this stream
can be made blocking. Do *NOT* meddle with the FD of the http_request
payload to achieve the same, because protocol violations will result.