Skip to content

chore: create proxy instance once per provider#267

Merged
pawbana merged 3 commits intomainfrom
pb/passthough-proxy-per-route
Apr 17, 2026
Merged

chore: create proxy instance once per provider#267
pawbana merged 3 commits intomainfrom
pb/passthough-proxy-per-route

Conversation

@pawbana
Copy link
Copy Markdown
Contributor

@pawbana pawbana commented Apr 15, 2026

Changes newPassthroughRouter so it created proxy per provider not on each request.
Replaced Director in httputil.ReverseProxy with Rewrite as Director is being deprecated in next go version.

Fixes: #187

Copy link
Copy Markdown
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, just some questions to make sure I understand this change 🙂

Comment thread passthrough.go
Comment thread passthrough.go
Comment thread passthrough.go
Comment thread passthrough_test.go
reqPath: "http://client-host/chat",
reqRemoteAddr: "not-a-socket-address",
reqHeaders: http.Header{
"X-Forwarded-For": {"1.1.1.1"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this header in the expectHeader set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As test case name suggest: omits_forwarded_for_when_remote_addr_is_not_parseable

reqRemoteAddr is set to not proper value. This is weird edge case that probably will never happen but I think it is better to point it out.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but 1.1.1.1 is a valid address; it should still be kept in the header, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure why library decides to drop the header but maybe due to a security concerns?
If RemoteAddr / last hop is unknown it is better to drop whole header then forward it with missing hop.
Maybe I should remove this test as it tests library rather then our code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this is a very edge case and not sure it can even occur in production. I would suggest either removing the test, or if we decide to keep it add a comment explaining this for future reference

Comment thread passthrough_test.go
@pawbana pawbana force-pushed the pb/passthough-proxy-per-route branch from b81eeff to 1334e6b Compare April 16, 2026 16:01
@pawbana pawbana requested a review from ssncferreira April 17, 2026 09:36
Copy link
Copy Markdown
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💪 thank you for addressing the comments!

Comment thread passthrough_test.go
reqPath: "http://client-host/chat",
reqRemoteAddr: "not-a-socket-address",
reqHeaders: http.Header{
"X-Forwarded-For": {"1.1.1.1"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this is a very edge case and not sure it can even occur in production. I would suggest either removing the test, or if we decide to keep it add a comment explaining this for future reference

@pawbana pawbana merged commit 1d53ad0 into main Apr 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create proxy per pass though route once

2 participants