What

In the last story you learned what a reverse proxy is at a high level. In this story you will look at how golang implements a reverse proxy and how gorouter uses that reverse proxy struct.

How

Read some docs

  1. đź“šRead these golang docs on the Reverse Proxy struct

Look at Gorouter code

  1. Gorouter’s main.go, like many main.gos, is where everything is set up and initialized, but not much happens. Skim through main.go. ❓ Do you see anything interesting in there? Did anything catch your eye?
  2. In main.go it initializes a new proxy. Look at the code here.

  3. When this new proxy is created, it creates a new http.ReverseProxy. Look at the code here.

  4. Golang’s http.ReverseProxy struct has 7 configurable properties. Gorouter configures 5 of them. ❓ Which http.ReverseProxy properties does gorouter configure? ❓ Which http.ReverseProxy properties does gorouter leave alone?

  5. The meatiest tofu-iest bit of configuration that gorouter does is that it assigns its own Proxy Round Tripper to the http.ReverseProxyTransport. Look at the code here.

  6. This Proxy Round Tripper handles gorouter’s custom routing logic and is a wrapper around the default Transport roundTrip function. Take a quick look at the code for the Proxy Round Tripper. We will looker closer at this component in a later story.