Discussion:
relayd to match http request according to path and change headers
Stephane Guedon
2021-04-04 08:13:30 UTC
Permalink
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 <webhosts>
pass request path "/tracker/socket" forward to <apihosts>
pass request path "/socket.io" forward to <apihosts>
pass request path "/*" forward to <apihosts>
}

Thanks for answers.
o***@crw.name
2021-04-04 09:31:27 UTC
Permalink
Just a idea, have you tried the keyword request ?

Something like

match request path "/static/*" forward to <webhosts>

Regards,

Christoph
Post by 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
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 <webhosts>
pass request path "/tracker/socket" forward to <apihosts>
pass request path "/socket.io" forward to <apihosts>
pass request path "/*" forward to <apihosts>
}
Thanks for answers.
Stephane Guedon
2021-04-04 21:59:23 UTC
Permalink
Post by o***@crw.name
Just a idea, have you tried the keyword request ?
Something like
match request path "/static/*" forward to <webhosts>
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 <webhosts>"

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.
prx
2021-04-05 18:55:20 UTC
Permalink
Post by Stephane Guedon
Post by o***@crw.name
Just a idea, have you tried the keyword request ?
Something like
match request path "/static/*" forward to <webhosts>
Regards,
Christoph
Actually, it's not at the forward stage that I have a problem, sorry if
I explained wrongly.
"match request path "/static/*" forward to <webhosts>"
I am trying to match a request based on the "static" path and set its
reponse headers.
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"
```
Stephane Guedon
2021-04-06 20:00:15 UTC
Permalink
Post by prx
Post by Stephane Guedon
Post by o***@crw.name
Just a idea, have you tried the keyword request ?
Something like
match request path "/static/*" forward to <webhosts>
Regards,
Christoph
Actually, it's not at the forward stage that I have a problem, sorry
if I explained wrongly.
"match request path "/static/*" forward to <webhosts>"
I am trying to match a request based on the "static" path and set its
reponse headers.
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".
```
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.

Loading...