// Push one new header into the response of an HTTP request.
// When completed, the HTTP transaction now owns the memory allocated for key and val.
void add_response_header(struct http_transaction *h, char *key, char *val) {
- struct http_header *new_response_header = malloc(sizeof(struct http_header));
+ struct key_val_list *new_response_header = malloc(sizeof(struct key_val_list));
new_response_header->key = key;
new_response_header->val = val;
new_response_header->next = h->response_headers;
struct http_transaction h;
char *c, *d;
struct sockaddr_in sin;
- struct http_header *clh; // general purpose iterator variable
+ struct key_val_list *clh; // general purpose iterator variable
memset(&h, 0, sizeof h);
else { // Subsequent lines are headers.
c = strchr(buf, ':'); // Header line folding is obsolete so we don't support it.
if (c != NULL) {
- struct http_header *new_request_header = malloc(sizeof(struct http_header));
+ struct key_val_list *new_request_header = malloc(sizeof(struct key_val_list));
*c = 0;
new_request_header->key = strdup(buf);
++c;
new_request_header->next = h.request_headers;
h.request_headers = new_request_header;
#ifdef DEBUG_HTTP
- syslog(LOG_DEBUG, "{ %s: %s", new_request_header->key, new_request_header->val);
+ syslog(LOG_DEBUG, "\033[1m\033[35m{ %s: %s\033[0m", new_request_header->key, new_request_header->val);
#endif
}
}
client_printf(ch, "Content-encoding: identity\r\n"); // change if we gzip/deflate
for (clh = h.response_headers; clh != NULL; clh = clh->next) {
#ifdef DEBUG_HTTP
- syslog(LOG_DEBUG, "} %s: %s", clh->key, clh->val);
+ syslog(LOG_DEBUG, "\033[1m\033[35m} %s: %s\033[0m", clh->key, clh->val);
#endif
client_printf(ch, "%s: %s\r\n", clh->key, clh->val);
}
// The caller does NOT own the memory of the returned pointer, but can count on the pointer
// to still be valid through the end of the transaction.
char *header_val(struct http_transaction *h, char *requested_header) {
- struct http_header *clh; // general purpose iterator variable
+ struct key_val_list *clh; // general purpose iterator variable
for (clh = h->request_headers; clh != NULL; clh = clh->next) {
if (!strcasecmp(clh->key, requested_header)) {
return (clh->val);
#include <openssl/rand.h>
#include <expat.h>
#define _(x) x // temporary hack until we add i18n back in
-//#define DEBUG_HTTP // uncomment to debug HTTP headers
+#define DEBUG_HTTP // uncomment to debug HTTP headers
// XML_StopParser is present in expat 2.x
#if XML_MAJOR_VERSION > 1
SSL *ssl_handle;
};
-struct http_header { // request and response headers in struct http_transaction use this format
- struct http_header *next;
+struct key_val_list { // linked list of keys and values
+ struct key_val_list *next;
char *key;
char *val;
};
char *url; // application stack. The second half is built up by the application
char *http_version; // stack and sent back down to the web server, which transmits it to
char *site_prefix; // the client.
- struct http_header *request_headers;
+ struct key_val_list *request_headers;
char *request_body;
long request_body_length;
int response_code;
char *response_string;
- struct http_header *response_headers;
+ struct key_val_list *response_headers;
char *response_body;
long response_body_length;
};