title: haproxy http load balancing and status handling
body: <p>I can't clearly understand how Haproxy performs health checks in http mode. </p>
  
  <p>I need to resend http request to another server (next in list of backend servers), if first one returned some error status code (for example, 503). 
  I need following behaviour of Haproxy:
  1) I receive some HTTP request
  2) I send it to the first server
  3) If I get 503 (or some other error code), this HTTP request must be send to the next server
  4) If It returns 200 code, next http requests of this tcp session goes to first server </p>
  
  <p>I know it's easy to implement in nginx (using proxy_next_upstream, I suppose). But I need to use Haproxy, because software I need to connect works on the layer 4 and I can't change it, so it need to keep groups of http messages in the same tcp session. I can keep them in the same session in haproxy, but not in nginx. </p>
  
  <p>I know about <strong>httpchk</strong> and <strong>observe</strong>, but they are not what I need. 
  First one allows me to send some http request, not http request I received (I need to analyse http traffic to decide what http status I will answer). 
  Second marks my servers as dead and doesn't send messages to it anymore, but I need this messages to by analysed. 
  I really need behaviour like nginx, but with ability to have http messages in the tcp sessions.
  Probably there is some nice way to implement it with <strong>ACL</strong>?</p>
  
  <p>Could anyone please give me a detailed explanation how haproxy handles load balancing in http mode or offer some solution to my problem?</p>
  
  <p><strong>UPDATE:</strong>
  For example, when I tried to do it with observe, I used configuration:</p>
  
  <pre><code>global
  log 127.0.0.1   local0
  maxconn 10000
  user haproxy
  group haproxy
  daemon
  
  defaults
  log global
  option  dontlognull
  retries 3
  maxconn 10000
  contimeout  10000
  clitimeout  50000
  srvtimeout  50000
  
  listen zti 127.0.0.1:1111
  mode http
  balance roundrobin
  server zti_1 127.0.0.1:4444 check observe layer7 error-limit 1 on-error mark-down
  server zti_2 127.0.0.1:5555 check observe layer7 error-limit 1 on-error mark-down
  </code></pre>
  
  <p>Thanks,
  Dmitry</p>