save headers in an ordered dictionary
due to the usage of a hashmap to store headers, when relaying them to the other side the order was not prevented. even though correct from a standards point-of-view, this caused issues with various programs, and it allows to fingerprint the use of tinyproxy. to implement this, i imported the MIT-licensed hsearch.[ch] from https://github.com/rofl0r/htab which was originally taken from musl libc. it's a simple and efficient hashtable implementation with far better performance characteristic than the one previously used by tinyproxy. additionally it has an API much more well-suited for this purpose. orderedmap.[ch] was implemented from scratch to address this issue. behind the scenes it uses an sblist to store string values, and a htab to store keys and the indices into the sblist. this allows us to iterate linearly over the sblist and then find the corresponding key in the hash table, so the headers can be reproduced in the order they were received. closes #73
This commit is contained in:
1 parent
9d5ee85c3e
commit
34a8b28414
10 files changed
+432
-96
No files matched your search
+3
-4
@@ -111,7 +111,7 @@ void free_reversepath_list (struct reversepath *reverse)
|
||||
/*
|
||||
* Rewrite the URL for reverse proxying.
|
||||
*/
|
||||
char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
||||
char *reverse_rewrite_url (struct conn_s *connptr, orderedmap hashofheaders,
|
||||
char *url)
|
||||
{
|
||||
char *rewrite_url = NULL;
|
||||
@@ -130,9 +130,8 @@ char *reverse_rewrite_url (struct conn_s *connptr, hashmap_t hashofheaders,
|
||||
strcpy (rewrite_url, reverse->url);
|
||||
strcat (rewrite_url, url + strlen (reverse->path));
|
||||
} else if (config->reversemagic
|
||||
&& hashmap_entry_by_key (hashofheaders,
|
||||
"cookie",
|
||||
(void **) &cookie) > 0) {
|
||||
&& (cookie = orderedmap_find (hashofheaders,
|
||||
"cookie"))) {
|
||||
|
||||
/* No match - try the magical tracking cookie next */
|
||||
if ((cookieval = strstr (cookie, REVERSE_COOKIE "="))
|
||||
|
||||
Reference in new issue
Block a user