Skip to content

Adding rewrite option to proxy service#204

Merged
Roasbeef merged 4 commits intolightninglabs:masterfrom
sergey3bv:feat/config-n-rewrite-option
Mar 24, 2026
Merged

Adding rewrite option to proxy service#204
Roasbeef merged 4 commits intolightninglabs:masterfrom
sergey3bv:feat/config-n-rewrite-option

Conversation

@sergey3bv
Copy link
Copy Markdown
Contributor

Addressing #157

@sergey3bv sergey3bv marked this pull request as draft January 29, 2026 09:48
@sergey3bv sergey3bv force-pushed the feat/config-n-rewrite-option branch from 1ed3f17 to f768e6d Compare January 29, 2026 09:51
@sergey3bv sergey3bv marked this pull request as ready for review January 29, 2026 09:51
@sergey3bv
Copy link
Copy Markdown
Contributor Author

Hey, @guggero, @Roasbeef, is everything alright with the code? I will be happy to fix any issue if there are any.

@hieblmi
Copy link
Copy Markdown
Collaborator

hieblmi commented Mar 5, 2026

Hi @sergey3bv, thanks for your contribution.

There are no tests for either the validation logic in prepareServices() or the rewrite behavior in director(). The existing proxy_test.go doesn't test the director at all. At minimum, tests should cover:

  • Valid prefix is prepended correctly.
  • Invalid prefix formats are rejected at startup (relative path, with host/scheme).
  • Unknown rewrite keys are rejected.
  • url.JoinPath behavior with edge cases (trailing slashes, encoded segments).

@sergey3bv sergey3bv force-pushed the feat/config-n-rewrite-option branch from f768e6d to eaf906d Compare March 6, 2026 13:51
@sergey3bv sergey3bv marked this pull request as draft March 6, 2026 13:51
@sergey3bv sergey3bv force-pushed the feat/config-n-rewrite-option branch from eaf906d to 14344b2 Compare March 10, 2026 09:04
@sergey3bv sergey3bv marked this pull request as ready for review March 10, 2026 09:05
@sergey3bv
Copy link
Copy Markdown
Contributor Author

@hieblmi, I added tests. What do you think?

@sergey3bv sergey3bv force-pushed the feat/config-n-rewrite-option branch from 14344b2 to 6134ab2 Compare March 11, 2026 07:56
@hieblmi
Copy link
Copy Markdown
Collaborator

hieblmi commented Mar 19, 2026

Hi @sergey3bv, nice work.

there still seems to be a bug in proxy/proxy.go:95 — when rewriteRequestPath sets req.URL.Path, it doesn't clear req.URL.RawPath.

Also can we add the two missing test categories

  • Unknown rewrite keys rejected
  • A test that verifies RawPath is cleared after rewrite — the bug flagged.

@sergey3bv sergey3bv force-pushed the feat/config-n-rewrite-option branch from 6134ab2 to d3bbbdb Compare March 19, 2026 10:30
@sergey3bv
Copy link
Copy Markdown
Contributor Author

@hieblmi, everything is good on my side, do I need to update anything else?

@sergey3bv
Copy link
Copy Markdown
Contributor Author

Hey, @Roasbeef, @guggero, it looks like Claude review is broken in CI

@hieblmi hieblmi self-requested a review March 24, 2026 19:08
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi left a comment

Choose a reason for hiding this comment

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

Thanks again for your changes. LGTM!

Address review findings for the rewrite prefix feature:

- Use url.URL.JoinPath instead of url.JoinPath to correctly preserve
  percent-encoded characters (e.g., %2F) in RawPath. Backends that rely
  on RawPath for routing (gRPC-gateway, etc.) will now see the original
  encoding rather than a blanket-cleared RawPath.

- Consolidate error messages in prepareRewrite to use "invalid prefix
  format" consistently for both parse and semantic errors. Fix trailing
  space in the error format string, use %q for quoting.

- Store validated prefix via u.Path instead of u.EscapedPath() to avoid
  redundant double-normalization in the hot path.

- Comment out sample-conf.yaml headers/rewrite blocks with placeholder
  credential to prevent users from copying a Bearer token verbatim.

- Document known limitation: backend redirect Location headers are not
  rewritten to strip the prefix.

- Expand test coverage with edge cases: root path (/), identity prefix
  (/), double slashes, dot segments, encoded spaces, deeply nested
  prefixes, and RawPath preservation verification.
Copy link
Copy Markdown
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Added some fix ups.

LGTM ⚜️

@Roasbeef Roasbeef merged commit be1830d into lightninglabs:master Mar 24, 2026
5 of 6 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.

3 participants