annotate src/lib-http/http-response.c @ 22633:9284bdc3c5c5

director: Don't recreate timeout on every user lookup Recreate it only when the timeout should change.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sat, 04 Nov 2017 01:34:02 +0200
parents 2e2563132d5f
children cb108f786fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21389
diff changeset
1 /* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */
21264
8f33680c6722 global: Added missing copyright notices.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 16848
diff changeset
2
16744
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
3 #include "lib.h"
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
4 #include "array.h"
16848
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
5 #include "ioloop.h"
16744
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
6 #include "istream.h"
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
7
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
8 #include "http-response.h"
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
9
16848
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
10 void
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
11 http_response_init(struct http_response *resp,
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
12 unsigned int status, const char *reason)
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
13 {
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21264
diff changeset
14 i_zero(resp);
16848
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
15 resp->version_major = 1;
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
16 resp->version_minor = 1;
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
17 resp->date = ioloop_time;
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
18 resp->status = status;
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
19 resp->reason = reason;
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
20 }
aa39d877d2c5 lib-http: http-client: Made dummy response for returning internal errors more complete by filling in the version number and a proper date.
Stephan Bosch <stephan@rename-it.nl>
parents: 16744
diff changeset
21
16744
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
22 bool http_response_has_connection_option(const struct http_response *resp,
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
23 const char *option)
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
24 {
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
25 const char *const *opt_idx;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
26
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
27 if (!array_is_created(&resp->connection_options))
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
28 return FALSE;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
29 array_foreach(&resp->connection_options, opt_idx) {
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
30 if (strcasecmp(*opt_idx, option) == 0)
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
31 return TRUE;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
32 }
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
33 return FALSE;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
34 }
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
35
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
36 int http_response_get_payload_size(const struct http_response *resp,
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
37 uoff_t *size_r)
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
38 {
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
39 if (resp->payload == NULL) {
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
40 *size_r = 0;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
41 return 1;
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
42 }
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
43
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
44 return i_stream_get_size(resp->payload, TRUE, size_r);
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
45 }
dca140149d80 lib-http: Unified http-request.h and http-response.h headers.
Stephan Bosch <stephan@rename-it.nl>
parents:
diff changeset
46