Search code examples
httptcpbackendconfighaproxy

redirecting Haproxy HTTP-requests in mode tcp


I would like to return a http-response status 200 to http-requests which are send on port 8883. The port is used for mqtt but we would like to catch http-requests on it.

The configuration I have now is (Haproxy 2.2) :

frontend smqtt
    bind :8883
    mode tcp
    use_backend port_check if HTTP
    default_backend smqtt-broker

backend smqtt-broker
    mode tcp
    server A-SMQTT <ip>:<port> check
    server B-SMQTT <ip>:<port> check

backend port_check
    mode http
    http-response return status 200 content-type "text/plain" lf-string "Port Check Success"

The MQTT backend (default_backend) is working but the 'catching' of HTTP-requests is not. How can I detect (and change the backend) if a HTTP-request is coming in mode tcp?


Solution

  • The working configuration is:

    frontend smqtt
        bind :8883
        mode tcp
        tcp-request inspect-delay 5s
        tcp-request content capture req.proto_http len 1
        use_backend port_check if HTTP
        default_backend smqtt_broker
    
    backend smqtt_broker
        mode tcp
        server A-SMQTT <ip>:<port> check
        server B-SMQTT <ip>:<port> check
    
    backend port_check
        mode http
        http-request return content-type "text/plain" string "Port Check Succes"
    

    Have to capture req.proto_http and http-request instead of http-response.