relayd to match http request according to path and change headers
Good day. I have a setup in OpenBSD 6.8, relayd / httpd and wish to see if I can have specific http options or headers depending on paths in the requests. Can I do "match path ..." and set headers ? Until now, all doc I read say you can set headers globally but not on specific paths. I can set tags, but trying to match on them and set headers after triggers syntax error. Here is an extract of the relayd.conf, where I wish to match on the static path. I got syntax error when I test this conf (currently commented) : http protocol https { # Various TCP options tcp { nodelay, sack, socket buffer 65536, backlog 128 } ... #match path "/static/*" { #response header set "Access-Control-Allow-Methods" value "GET,OPTIONS" #response header set "Access-Control-Allow-Headers" value "Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If- Modified-Since,Cache-Control,Content-Type" # } pass request path "/static/*" forward to pass request path "/tracker/socket" forward to pass request path "/socket.io" forward to pass request path "/*" forward to } Thanks for answers.
Re: relayd to match http request according to path and change headers
Just a idea, have you tried the keyword request ? Something like match request path "/static/*" forward to Regards, Christoph Am 04.04.2021 10:13, schrieb Stephane Guedon: Good day. I have a setup in OpenBSD 6.8, relayd / httpd and wish to see if I can have specific http options or headers depending on paths in the requests. Can I do "match path ..." and set headers ? Until now, all doc I read say you can set headers globally but not on specific paths. I can set tags, but trying to match on them and set headers after triggers syntax error. Here is an extract of the relayd.conf, where I wish to match on the static path. I got syntax error when I test this conf (currently commented) : http protocol https { # Various TCP options tcp { nodelay, sack, socket buffer 65536, backlog 128 } ... #match path "/static/*" { #response header set "Access-Control-Allow-Methods" value "GET,OPTIONS" #response header set "Access-Control-Allow-Headers" value "Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If- Modified-Since,Cache-Control,Content-Type" # } pass request path "/static/*" forward to pass request path "/tracker/socket" forward to pass request path "/socket.io" forward to pass request path "/*" forward to } Thanks for answers.
Re: relayd to match http request according to path and change headers
Le dimanche 4 avril 2021 11:31:27 CEST, vous avez écrit : > Just a idea, have you tried the keyword request ? > > Something like > > match request path "/static/*" forward to > > Regards, > > Christoph > Actually, it's not at the forward stage that I have a problem, sorry if I explained wrongly. That part works perfect : "match request path "/static/*" forward to " I am trying to match a request based on the "static" path and set its reponse headers. This is the part where I want to improve things: match request path "/static/*" response header set "Access-Control- Allow-Headers" value "Range" And those, I always get syntax errors. Thanks Kind regards.
Re: relayd to match http request according to path and change headers
* Stephane Guedon le [04-04-2021 23:59:23 +0200]: > Le dimanche 4 avril 2021 11:31:27 CEST, vous avez écrit : > > Just a idea, have you tried the keyword request ? > > > > Something like > > > > match request path "/static/*" forward to > > > > Regards, > > > > Christoph > > > > Actually, it's not at the forward stage that I have a problem, sorry if > I explained wrongly. > > That part works perfect : > "match request path "/static/*" forward to " > > I am trying to match a request based on the "static" path and set its > reponse headers. > > This is the part where I want to improve things: > > match request path "/static/*" response header set "Access-Control- > Allow-Headers" value "Range" > > And those, I always get syntax errors. I guess that's because you mix "request" and "response". You can tag the request if you want : ``` match request path "/static/*" tag STATIC match response tagged "STATIC" header set "Access-Control-Allow-Headers" value "Range" ```
Re: relayd to match http request according to path and change headers
Le lundi 5 avril 2021, 20:55:20 CEST prx a écrit : > * Stephane Guedon le [04-04-2021 23:59:23 +0200]: > > Le dimanche 4 avril 2021 11:31:27 CEST, vous avez écrit : > > > Just a idea, have you tried the keyword request ? > > > > > > Something like > > > > > > match request path "/static/*" forward to > > > > > > Regards, > > > > > > Christoph > > > > Actually, it's not at the forward stage that I have a problem, sorry > > if I explained wrongly. > > > > That part works perfect : > > "match request path "/static/*" forward to " > > > > I am trying to match a request based on the "static" path and set > > its > > reponse headers. > > > > This is the part where I want to improve things: > > > > match request path "/static/*" response header set "Access-Control- > > Allow-Headers" value "Range" > > > > And those, I always get syntax errors. > > I guess that's because you mix "request" and "response". > You can tag the request if you want : > > ``` > match request path "/static/*" tag STATIC > match response tagged "STATIC" header set > "Access-Control-Allow-Headers" value "Range" ``` Actually, that idea might work. It does not break anyway, so I will see if it works out... Thanks.