# Route TCP according to payload

**URL:** <https://discourse.haproxy.org/t/route-tcp-according-to-payload/9996>\
**Category:** Help!\
**Created:** [July 4, 2024, 1:20pm UTC](https://discourse.haproxy.org/t/route-tcp-according-to-payload/9996 "2024-07-04T13:20:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JarmoHu](https://avatars.discourse-cdn.com/v4/letter/j/7feea3/32.png) [@JarmoHu](https://discourse.haproxy.org/u/JarmoHu)\
**Post date:** [July 4, 2024, 1:20pm UTC](https://discourse.haproxy.org/t/route-tcp-according-to-payload/9996/1 "2024-07-04T13:20:22Z")

</div>

if I use haproxy 2.8, this configue is ok:

```auto
global
	log /dev/log	local0
	log /dev/log	local1 notice
	chroot /var/lib/haproxy
	stats socket /run/haproxy/admin.sock mode 660 level admin
	stats timeout 30s
	user haproxy
	group haproxy
	daemon

	# Default SSL material locations
	ca-base /etc/ssl/certs
	crt-base /etc/ssl/private

	# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
        ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
        ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
        ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
	log	global
	mode	http
	option	httplog
	option	dontlognull
        timeout connect 5000
        timeout client 50000
        timeout server 50000
	errorfile 400 /etc/haproxy/errors/400.http
	errorfile 403 /etc/haproxy/errors/403.http
	errorfile 408 /etc/haproxy/errors/408.http
	errorfile 500 /etc/haproxy/errors/500.http
	errorfile 502 /etc/haproxy/errors/502.http
	errorfile 503 /etc/haproxy/errors/503.http
	errorfile 504 /etc/haproxy/errors/504.http

frontend tcp-in
    bind *:48202
    mode tcp
    option tcplog
    
    tcp-request inspect-delay 5s
    # tcp-request content accept if TRUE
    tcp-request content capture payload(0,9) len 9
    log-format %[capture.req.hdr(0)]
    
    
    # tcp-request content accept if { payload(0,9) -m bin 474554202f766d686b302f }
    # tcp-request content accept if { payload(0,8) -m bin 474554202f737461 }

    # 根据检查结果将请求分配到不同的后端
    # use_backend hell-backend if { payload(0,11) -m bin 474554202f766d686b302f }
    use_backend hell-backend if { payload(0,8) -m bin 474554202f766d68 }
    use_backend haproxy-http-backend if { payload(0,8) -m bin 474554202f737461 }

    default_backend default-backend

backend hell-backend
    mode tcp
    server server1 38.207.173.10:42441 check

backend haproxy-http-backend
    mode tcp
    server default-server 127.0.0.1:38202 check
    
backend default-backend
    mode tcp
    server default-server2 127.0.0.1:48200 check

```

in version 3.0, the `log-format %[capture.req.hdr(0)]` is wrong, and the log says:`haproxy[95097]: [ALERT] (95097) : config : Parsing [/etc/haproxy/haproxy.cfg:46]: failed to parse log-format : logformat expression not usable here (at least one node depends on HTTP mode).`

If I remove the comment sign of `# tcp-request content accept if TRUE`, haproxy doesn’t work.

---

<div class="post-metadata">

**Author:** ![IgorC](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/igorc/32/161_2.png) [@IgorC](https://discourse.haproxy.org/u/IgorC)\
**Post date:** [July 6, 2024, 8:54am UTC](https://discourse.haproxy.org/t/route-tcp-according-to-payload/9996/2 "2024-07-06T08:54:58Z")

</div>

I guess the error is telling you you can’t capture a HTTP header in tcp mode. No idea why was this working in version 2.8 at all.
