saucelabs / forwarder

Forwarder is a production-ready, fast MITM proxy with PAC support. It's suitable for debugging, intercepting and manipulating HTTP traffic. It's used as a core component of Sauce Labs Sauce Connect Proxy.
https://forwarder-proxy.io
Mozilla Public License 2.0
218 stars 13 forks source link

martian: remove Context and Session #683

Closed mmatczuk closed 6 months ago

mmatczuk commented 6 months ago

This patchset is a significant refactoring of the martian core. It's a continuation of work initiated in #444.

The RequestModifier and ResponseModifier errors are handled and appropriate error response is generated based on ErrorResponse(). Subsequently the connection hijacking functionality is removed.

Proxy connection proxyConn is introduced, and proxy code is restructured to more files focused around specific topics. The proxyConn and proxyHandler have similar structure for easier navigation and compatibility. The Proxy remains for configuration and generic shared items. This has been done in #673 but we expand on it here.

A TraceID is added and it takes the responsibility of request ID generation and duration tracking. The custom Context and Session structs are removed resulting in streamlined function interfaces. TraceID is attached to request context on creation.

Logging is streamlined, single responsibility principle is applied allowing for logger stacking. Each logger has its domain.

Fixes #525 Fixes #523 Fixes #497 Fixes #498

Choraden commented 6 months ago

I'm afraid, this does not fully fix #498 as it still reports denied requests as errors in metrics.

forwarder_proxy_errors_total{reason="denied"} 1

Let's open another one or do not resolve it here.

Choraden commented 6 months ago

While trying new via loop detection mechanism, I found #688.

This PR did not introduce this. It exists in the old approach as well.