Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite: uri query replace operation #6165

Merged

Conversation

armadi1809
Copy link
Contributor

This PR is a followup to close #6096. It implements the replace operation for query strings.

@armadi1809
Copy link
Contributor Author

@francislavoie let me know if you would like to see other test cases to make sure this is working as intended.

Copy link
Member

@francislavoie francislavoie left a comment

Choose a reason for hiding this comment

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

Additional test cases we should have:

  • Placeholders (key, search, replacement)
  • Partial replacement (only replace a subset of the existing value)
  • Ensure nothing is replaced if the search is not found
  • Caddyfile adapt test (to ensure it produces the expected JSON), just make a Caddyfile with as many config combinations as you can think of, don't need to be functional, just coverage for the adapter

modules/caddyhttp/rewrite/caddyfile.go Outdated Show resolved Hide resolved
@francislavoie francislavoie added the feature ⚙️ New feature or request label Mar 10, 2024
@francislavoie francislavoie added this to the v2.8.0 milestone Mar 10, 2024
@francislavoie francislavoie changed the title Query replace operation rewrite: uri query replace operation Mar 10, 2024
@armadi1809 armadi1809 force-pushed the implement-replace-query-operation branch from 9caedc6 to 7f013d7 Compare March 11, 2024 00:16
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Lint error is unrelated, not sure why it is showing up here, but this feature LGTM!! Beautiful. Nice work @armadi1809

@mholt mholt enabled auto-merge (squash) March 12, 2024 04:08
@armadi1809
Copy link
Contributor Author

Thanks! Most of the scenarios mentioned by @francislavoie above should now be covered. The only one I am not sure about is using placeholders for the search, since we are now using regexes. It looks like neither the rewrite operation nor the headers replace operation support it. What do you guys think?

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

What if we merge this in for now, and then address that in a follow-up PR? Great work, @armadi1809 !

I will wait for @francislavoie 's final approval.

Copy link
Member

@francislavoie francislavoie left a comment

Choose a reason for hiding this comment

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

Thanks!

@francislavoie francislavoie force-pushed the implement-replace-query-operation branch from 3849db9 to fee1989 Compare March 22, 2024 02:19
@mholt mholt merged commit 29f57fa into caddyserver:master Mar 22, 2024
25 checks passed
@mholt
Copy link
Member

mholt commented Mar 22, 2024

Yeah this is cool. 😎

@JeDaYoshi
Copy link

JeDaYoshi commented Mar 23, 2024

Since this PR was merged, caddy no longer starts and segfaults. Built on Go 1.22.1.

Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.951647,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.9550269,"msg":"adapted config to JSON","adapter":"caddyfile"}
Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.9563556,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//[::1]:2019","//127.0.0.1:2019","//localhost:2019"]}
Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.95658,"logger":"http.auto_https","msg":"server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS","server_name":"srv0","https_port":443}
Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.9566038,"logger":"http.auto_https","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Mar 23 04:11:23 ten caddy[60323]: {"level":"info","ts":1711167083.9567306,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000601180"}
Mar 23 04:11:23 ten caddy[60323]: panic: runtime error: invalid memory address or nil pointer dereference
Mar 23 04:11:23 ten caddy[60323]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x13b2282]
Mar 23 04:11:23 ten systemd[1]: caddy.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Mar 23 04:11:23 ten systemd[1]: caddy.service: Failed with result 'exit-code'.
octo.autie.net {
        encode {
                zstd
                gzip
        }

        header {
                Permissions-Policy "interest-cohort=()"
                Referrer-Policy "same-origin"
                X-Content-Type-Options "nosniff"
                X-Frame-Options "SAMEORIGIN"
                X-XSS-Protection "0"
        }

        handle_path /api/* {
                reverse_proxy 127.0.0.1:4000
        }

        reverse_proxy 127.0.0.1:3000
}

Should I open an issue?

@armadi1809
Copy link
Contributor Author

@mholt @francislavoie I just submitted a PR that fixes the issue mentioned in the comment above. I when calling the Query field of the Rewrite structure, within the provision method, I did not account for the fact that Query could be null. Sorry about that!

@mholt
Copy link
Member

mholt commented Mar 28, 2024

Thank you @armadi1809 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Query rewrite operations
4 participants