mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-19 21:27:57 +00:00
HTTP server support for extra response headers
This commit is contained in:
parent
dd1e9f2ffb
commit
98a6fc55d9
@ -1500,7 +1500,7 @@ static void http_request_receive(struct http_request *r)
|
||||
result = 500;
|
||||
}
|
||||
} else {
|
||||
HTTP_REQUEST_PARSER oldparser = r->parser;
|
||||
HTTP_REQUEST_PARSER *oldparser = r->parser;
|
||||
const char *oldparsed = r->parsed;
|
||||
if (r->parser == NULL) {
|
||||
if (r->debug_flag && *r->debug_flag)
|
||||
@ -1881,6 +1881,9 @@ static int _render_response(struct http_request *r)
|
||||
strbuf_append_quoted_string(sb, hr.header.www_authenticate.realm);
|
||||
strbuf_puts(sb, "\r\n");
|
||||
}
|
||||
if (r->render_extra_headers)
|
||||
r->render_extra_headers(r, sb);
|
||||
assert(strcmp(strbuf_substr(sb, -2), "\r\n") == 0);
|
||||
strbuf_puts(sb, "\r\n");
|
||||
if (hr.header.content_length != CONTENT_LENGTH_UNKNOWN)
|
||||
r->response_length = strbuf_count(sb) + hr.header.content_length;
|
||||
|
@ -148,7 +148,8 @@ void http_request_response_static(struct http_request *r, int result, const char
|
||||
void http_request_response_generated(struct http_request *r, int result, const char *mime_type, HTTP_CONTENT_GENERATOR *);
|
||||
void http_request_simple_response(struct http_request *r, uint16_t result, const char *body);
|
||||
|
||||
typedef int (*HTTP_REQUEST_PARSER)(struct http_request *);
|
||||
typedef int HTTP_REQUEST_PARSER(struct http_request *);
|
||||
typedef void HTTP_RENDERER(struct http_request *, strbuf);
|
||||
|
||||
struct http_request {
|
||||
struct sched_ent alarm; // MUST BE FIRST ELEMENT
|
||||
@ -173,12 +174,12 @@ struct http_request {
|
||||
struct http_request_headers request_header;
|
||||
// Parsing is done by setting 'parser' to point to a series of parsing
|
||||
// functions as the parsing state progresses.
|
||||
HTTP_REQUEST_PARSER parser; // current parser function
|
||||
HTTP_REQUEST_PARSER *parser; // current parser function
|
||||
// The caller may set these up, and they are invoked by the parser as request
|
||||
// parsing reaches different stages.
|
||||
HTTP_REQUEST_PARSER handle_first_line; // called after first line is parsed
|
||||
HTTP_REQUEST_PARSER handle_headers; // called after all HTTP headers are parsed
|
||||
HTTP_REQUEST_PARSER handle_content_end; // called after all content is received
|
||||
HTTP_REQUEST_PARSER *handle_first_line; // called after first line is parsed
|
||||
HTTP_REQUEST_PARSER *handle_headers; // called after all HTTP headers are parsed
|
||||
HTTP_REQUEST_PARSER *handle_content_end; // called after all content is received
|
||||
// The following are used for managing the buffer during RECEIVE phase.
|
||||
const char *reserved; // end of reserved data in buffer[]
|
||||
const char *received; // start of received data in buffer[]
|
||||
@ -194,6 +195,7 @@ struct http_request {
|
||||
// The following are used for constructing the response that will be sent in
|
||||
// TRANSMIT phase.
|
||||
struct http_response response;
|
||||
HTTP_RENDERER *render_extra_headers;
|
||||
// The following are used during TRANSMIT phase to control buffering and
|
||||
// sending.
|
||||
http_size_t response_length; // total response bytes (header + content)
|
||||
|
Loading…
Reference in New Issue
Block a user