Setting fake user agent in Polipo

I use Polipo as a caching web proxy for my VPN and for some simple anonymizing. It’s a great software.

One thing bugs me though: when censoring User-Agent, as intended, it does not send a User-Agent header. But: Sometimes poorly written web scripts break on a missing user agent string or web scripts take a missing user agent string as an indicator for a bot and block the request (Wikipedia does that for example).

I have created a tiny patch that sets “User-Agent: empty” header when censoring “User-Agent” so that web scripts do not break or block the request. There are only four new lines and you can set the fake user agent string in config.h:

“`diff
diff -cB ./polipo/config.h ./polipo_custom/config.h
*** ./polipo/config.h 2011-07-17 12:48:42.000000000 +0200
— ./polipo_custom/config.h 2011-07-17 13:22:06.000000000 +0200
***************
*** 35,40 ****
— 35,41 —-
#define CONFIG_INT_LIST 12
#define CONFIG_ATOM_LIST 13
#define CONFIG_ATOM_LIST_LOWER 14
+ #define USER_AGENT_STRING “empty”

typedef struct _ConfigVariable {
AtomPtr name;
diff -cB ./polipo/server.c ./polipo_custom/server.c
*** ./polipo/server.c 2011-07-17 12:48:42.000000000 +0200
— ./polipo_custom/server.c 2011-07-17 13:25:28.000000000 +0200
***************
*** 1678,1683 ****
— 1678,1686 —-
goto fail;

if(request->request && request->request->headers) {
+ if(strstr(request->request->headers->string, “User-Agent:”) == NULL) {
+ n = snnprintf(connection->reqbuf, n, bufsize, “\r\nUser-Agent: %s”, USER_AGENT_STRING);
+ }
n = snnprint_n(connection->reqbuf, n, bufsize,
request->request->headers->string,
request->request->headers->length);
“`

You can check your user agent string with http://whatsmyuseragent.com/.


Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.