HAProxy community

ACL to match the HTML response only

Not sure how this page/response named so I create this topic. Which ACL filter I can use to match the response (HTML) of webpage only.

I mean I plan to add CSP, HSTS, Early hints to the first HTML document only like the screenshot below, no need to add to other (static content, image, zip,…). The rule should not check if path_end is not .html because some settings can be / in the end, sometimes can be .html.

Thanks for your reading.

I tried:

capture response header Accept len 40
acl is_html_response res.hdr(accept) -m sub "text/html"

and

http-request set-var(txn.accept) hdr(Accept)
acl is_html_response var(txn.accept) -m str "text/html"

but not work :frowning:

It’s not Accept, it’s Content-type

OMG. I’m so dumb to not realize this.

  capture response header Content-Type len 40
  acl is_html_response res.hdr(Content-Type) -m sub "text/html"

Working as expected. Thank you so much.

1 Like