-
Notifications
You must be signed in to change notification settings - Fork 30
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
placeholders not support {http.request.host} #26
Comments
Please share your full config. Show an example request with |
Actually, I have a site deployed to cloudflare. Caddy --version:
Caddyfile:
|
We also need your logs (enable the It's important. Whether it works or not depends on how your upstream responds. |
sure, I created a test.html and content is 'Aexample.com' for show the "curl -v" curl -v https://testsub.Bexample.com/clients/test.html
the last line is: {http.request.host} |
Is your backend compressing the response (does it support gzip compression)? If so, the replacer can't operate on compressed payloads... |
@mholt @francislavoie I was able to confirm this issue as well using a simple NodeJS backend for testing: const http = require("http");
const server = http.createServer((req, res, next) => {
console.log(req.url);
console.log(req.rawHeaders);
res.writeHead(200);
res.write("This is a test", "utf8");
res.end();
});
server.listen(process.argv[2]); $ node index.js 8181 Using the following Caddyfile:
Responses are rewritten when using a string with the replacement handler: curl https://localhost:8443 -v
* Trying 127.0.0.1:8443...
* Connected to localhost (127.0.0.1) port 8443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
* CApath: none
< HTTP/2 200
< alt-svc: h3=":8443"; ma=2592000
< date: Tue, 16 Apr 2024 19:08:36 GMT
< server: Caddy
<
This is a I was replaced% However when using placeholder Caddyfile:
Response: curl https://localhost:8443 -v
* Trying 127.0.0.1:8443...
* Connected to localhost (127.0.0.1) port 8443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
* CApath: none
< HTTP/2 200
< alt-svc: h3=":8443"; ma=2592000
< date: Tue, 16 Apr 2024 19:09:57 GMT
< server: Caddy
<
This is a {http.request.host}% |
Oh, you know, this is because, for efficiency reasons, we allocate the transformer chain at Provision-time instead of Request-time. So there is no I don't know for sure, but @icholy's excellent There is no |
Great! Looking forward to seeing what can be done. In our use case, we don't always know what the replacement value should be since we support many vhosts, so being able to dynamically replace would be amazing. |
Hello, I'm trying to replace ngcspnonce in an angular app with this module as well as https://github.com/luludotdev/caddy-requestid so that it's a different nonce on every request. In the header the caddy-requestid module is correctly setting the nonce, but when I try to replace it using this module, it's replacing the string with the string literal. Am I correct in assuming this is because of the same issue here? My Caddyfile:
|
@Jonathazn can confirm, I came here for the same issue - I was attempting to add nonce support to an SPA served using Caddy. There doesn't appear to have a way to add nonce support by combining the uuid or other placeholders and this plugin due to this bug. |
I'd be open to contributions to help address this if anyone has some time :) |
@mholt I don't see any way we can solve this without modifying the I did the following and the performance is great (even faster than direct access to the upstream web site):
In my use case, I have 3 blocks of replace directive each block has it's own matcher and up to 4 regexp replacements and each replacement is using some placeholder. The upstream server/website is in Europe. The average I am very happy with the result. Please share your comments and thoughts on this. I am more than happy to create a PR on this if you think my solution is acceptable. |
@jshenguru That looks promising! Could you open a PR here for review? Then if all looks good we can figure out how to update the replace package upstream. |
@mholt Done. Please review |
Hi,
I have a generic domain name and would like to use the replace-response to reach the replacement of the real domain name requested by the user. But always replace by text:{http.request.host}
As in the following configuration file:
Is there any way to make it happen? Thanks!
The text was updated successfully, but these errors were encountered: