add_header: use sblist
note that the old code inserted added headers at the beginning of the list, reasoning unknown. this seems counter-intuitive as the headers would end up in the request in the reverse order they were added, but this was irrelevant, as the headers were originally first put into the hashmap hashofheaders before sending it to the client. since the hashmap didn't preserve ordering, the headers would appear in random order anyway.
This commit is contained in:
parent
7d33fc8e8a
commit
e929e81a55
26
src/conf.c
26
src/conf.c
@ -271,19 +271,20 @@ struct {
|
|||||||
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
const unsigned int ndirectives = sizeof (directives) / sizeof (directives[0]);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_added_headers (vector_t add_headers)
|
free_added_headers (sblist* add_headers)
|
||||||
{
|
{
|
||||||
ssize_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < vector_length (add_headers); i++) {
|
if (!add_headers) return;
|
||||||
http_header_t *header = (http_header_t *)
|
|
||||||
vector_getentry (add_headers, i, NULL);
|
for (i = 0; i < sblist_getsize (add_headers); i++) {
|
||||||
|
http_header_t *header = sblist_get (add_headers, i);
|
||||||
|
|
||||||
safefree (header->name);
|
safefree (header->name);
|
||||||
safefree (header->value);
|
safefree (header->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_delete (add_headers);
|
sblist_free (add_headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_config (struct config_s *conf)
|
void free_config (struct config_s *conf)
|
||||||
@ -848,19 +849,16 @@ static HANDLE_FUNC (handle_addheader)
|
|||||||
{
|
{
|
||||||
char *name = get_string_arg (line, &match[2]);
|
char *name = get_string_arg (line, &match[2]);
|
||||||
char *value = get_string_arg (line, &match[3]);
|
char *value = get_string_arg (line, &match[3]);
|
||||||
http_header_t *header;
|
http_header_t header;
|
||||||
|
|
||||||
if (!conf->add_headers) {
|
if (!conf->add_headers) {
|
||||||
conf->add_headers = vector_create ();
|
conf->add_headers = sblist_new (sizeof(http_header_t), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
header = (http_header_t *) safemalloc (sizeof (http_header_t));
|
header.name = name;
|
||||||
header->name = name;
|
header.value = value;
|
||||||
header->value = value;
|
|
||||||
|
|
||||||
vector_prepend (conf->add_headers, header, sizeof *header);
|
sblist_add (conf->add_headers, &header);
|
||||||
|
|
||||||
safefree (header);
|
|
||||||
|
|
||||||
/* Don't free name or value here, as they are referenced in the
|
/* Don't free name or value here, as they are referenced in the
|
||||||
* struct inserted into the vector. */
|
* struct inserted into the vector. */
|
||||||
|
@ -110,7 +110,7 @@ struct config_s {
|
|||||||
/*
|
/*
|
||||||
* Extra headers to be added to outgoing HTTP requests.
|
* Extra headers to be added to outgoing HTTP requests.
|
||||||
*/
|
*/
|
||||||
vector_t add_headers;
|
sblist* add_headers;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int reload_config_file (const char *config_fname, struct config_s *conf);
|
extern int reload_config_file (const char *config_fname, struct config_s *conf);
|
||||||
|
@ -1511,7 +1511,7 @@ void handle_connection (struct conn_s *connptr, union sockaddr_union* addr)
|
|||||||
while(0)
|
while(0)
|
||||||
|
|
||||||
int got_headers = 0, fd = connptr->client_fd;
|
int got_headers = 0, fd = connptr->client_fd;
|
||||||
ssize_t i;
|
size_t i;
|
||||||
struct request_s *request = NULL;
|
struct request_s *request = NULL;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
orderedmap hashofheaders = NULL;
|
orderedmap hashofheaders = NULL;
|
||||||
@ -1648,9 +1648,9 @@ e401:
|
|||||||
* Add any user-specified headers (AddHeader directive) to the
|
* Add any user-specified headers (AddHeader directive) to the
|
||||||
* outgoing HTTP request.
|
* outgoing HTTP request.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < vector_length (config->add_headers); i++) {
|
if (config->add_headers)
|
||||||
http_header_t *header = (http_header_t *)
|
for (i = 0; i < sblist_getsize (config->add_headers); i++) {
|
||||||
vector_getentry (config->add_headers, i, NULL);
|
http_header_t *header = sblist_get (config->add_headers, i);
|
||||||
|
|
||||||
orderedmap_append (hashofheaders, header->name, header->value);
|
orderedmap_append (hashofheaders, header->name, header->value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user