Transparent HTTP proxy with filter by user agent using golang

This is day 10 out of 100 Days of golang coding!

Idea for today is to build transparent http proxy with ability to filter traffic. As for a filter I will use user agent which is common practice to filter traffic.

So, for the task I have used two go modules: user_agent and goproxy:

First I have to setup a proxy and set a decide which hosts I want to match:

Regex “^.*$” is set to match all hosts.

Second I setup user agent parser and filter by bot and browser:

That’s all for coding. Now take a look at test cases:

Use case 1 – curl command no user agent set

Use case 2 – curl with normal browser user agent

In that case we have got requests from twitter server which was 301 to https.

Use case 3 – curl with bot user agent

Full version of proxy with verbose information of user agent parsing:


Source code available at GitHub.