Set-header for HAProxy when Content-Type” is missing from headers

haproxy

I am using haproxy as a load balancer. For one of our back end services, example abc, if "Content-Type" is missing from headers, we need to add the header "Content-Type" with value as "application/json" at HA-proxy level.

I am unable to find the solution for same.

Best Answer

You could have used a search engine?

 http-response set-header Content-Type application/json

If you want this only when there's no Content-Type

acl no_ct res.hdr(Content-Type) -m len 0
http-response set-header Content-Type application/json if no_ct

If the backend used the CONTENTTYPE header but you need Content-Type:

acl bad_ct res.hdr(CONTENTTYPE) -m found
http-response set-header Content-Type %[req.hdr(CONTENTTYPE)] if bad_ct