Re: fields vs word converter, unexpected "0" result

2017-08-01 Thread Cyril Bonté

Hi,

Le 01/08/2017 à 17:37, Daniel Schneller a écrit :

Any idea on the difference between “word” and “field”, though?


"field" and "word" are similar, except that "word" will ignore 
consecutive delimiters without any word.


Example with "x//y/z" :
  word(1,/)  => returns "x"
  word(2,/)  => returns "y"
  word(3,/)  => returns "z"
whereas :
  field(1,/) => returns "x"
  field(2,/) => returns ""
  field(3,/) => returns "y"


--
Cyril Bonté



Re: fields vs word converter, unexpected "0" result

2017-08-01 Thread Daniel Schneller
On 1. Aug. 2017, at 17:32, Holger Just  wrote:

> GET / HTTP/1.1
> Host: 127.0.0.1:8881
> User-Agent: curl/7.43.0
> Accept: */*
> 
> The HTTP 1.1 specification requires that a Host header is always sent
> along with the request. Curl specifically always sends the host from the
> given URL, unless it was explicitly overwritten.
> 
> Thus, in your case the fetch extracts the second part from the given IP
> address, which is 0 in your case.
> 

Ha! Thanks. I actually had used curl -v before, but selective vision must have 
kicked in with all the 127.0.0.1’s :)

Any idea on the difference between “word” and “field”, though?

Daniel




Re: fields vs word converter, unexpected "0" result

2017-08-01 Thread Holger Just
Hi Daniel,

Daniel Schneller wrote:
> root@haproxy-1:~# curl -s http://127.0.0.1:8881
> Aug  1 15:12:55 haproxy-1 haproxy[3049]: 127.0.0.1:45875 
> [01/Aug/2017:15:12:55.198] "0"
> 
> While the first three are expected, the last one confuses me. Why would 
> leaving the header out result in “0” being logged?

Because the header is not left out in your request. Instead, the raw
request is sent as follows

GET / HTTP/1.1
Host: 127.0.0.1:8881
User-Agent: curl/7.43.0
Accept: */*

The HTTP 1.1 specification requires that a Host header is always sent
along with the request. Curl specifically always sends the host from the
given URL, unless it was explicitly overwritten.

Thus, in your case the fetch extracts the second part from the given IP
address, which is 0 in your case.

Regards,
Holger



fields vs word converter, unexpected "0" result

2017-08-01 Thread Daniel Schneller
Hi!

First, the basics:

--
root@haproxy-1:~# haproxy -vv
HA-Proxy version 1.6.13-1ppa1~trusty 2017/06/19
Copyright 2000-2017 Willy Tarreau 

Build options :
  TARGET  = linux2628
  CPU = generic
  CC  = gcc
  CFLAGS  = -g -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 -Wformat 
-Werror=format-security -D_FORTIFY_SOURCE=2
  OPTIONS = USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1 USE_NS=1

Default settings :
  maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200




root@haproxy-1:/vagrant# cat mini.cfg

global
  log /dev/log len 350 local0 info
  stats socket /var/run/haproxy.stat user haproxy group haproxy mode 600 level 
admin

defaults
  mode http
  log global
  option httplog
  option dontlognull
  option http-keep-alive
  option redispatch
  timeout http-request 10s
  timeout queue 1m
  timeout connect 5s
  timeout client 2m
  timeout server 2m
  timeout http-keep-alive 10s
  timeout check 5s
  retries 3
  maxconn 2000


listen demo
  bind 127.0.0.1:8881
  log-format %ci:%cp\ [%t]\ %{+Q}[var(txn.host),lower,word(2,'.')]
  http-request set-var(txn.host) req.hdr(Host)
  server dummy dummy:8081 check
———


I need to log the 2nd subdomain of any incoming request. The above is the 
minimum config
I used to demo this behaviour, the actual one is a bit more involved ;)

First question: What is the difference between the “word” and “field” 
converters?
I tried both, but the behavior described below is the same regardless.



Now, this is what confuses me (request interleaved with corresponding log line):

root@haproxy-1:~# curl -s http://127.0.0.1:8881 -H "Host: aa.bb.cc”
Aug  1 15:12:42 haproxy-1 haproxy[3049]: 127.0.0.1:45868 
[01/Aug/2017:15:12:42.528] "bb"


root@haproxy-1:~# curl -s http://127.0.0.1:8881 -H "Host: cc"
Aug  1 15:12:47 haproxy-1 haproxy[3049]: 127.0.0.1:45871 
[01/Aug/2017:15:12:47.296] ""


root@haproxy-1:~# curl -s http://127.0.0.1:8881 -H "Host:"
Aug  1 15:12:50 haproxy-1 haproxy[3049]: 127.0.0.1:45872 
[01/Aug/2017:15:12:50.695] ""


root@haproxy-1:~# curl -s http://127.0.0.1:8881
Aug  1 15:12:55 haproxy-1 haproxy[3049]: 127.0.0.1:45875 
[01/Aug/2017:15:12:55.198] "0"


While the first three are expected, the last one confuses me. Why would leaving 
the header out result in “0” being logged?

Ideally, I’d like this to show as “-“, but empty string would be fine, too.
But “0” is pretty counter-intuitive.

It’s not strictly horrible, but at least it is unexpected and would also 
collide with cases where the actual 2nd subdomain was called “0”.

Is this a bug, or am I doing something wrong? 


Thanks,
Daniel

-- 
Daniel Schneller
Principal Cloud Engineer
 
CenterDevice GmbH  | Hochstraße 11
   | 42697 Solingen
tel: +49 1754155711| Deutschland
daniel.schnel...@centerdevice.de   | www.centerdevice.de

Geschäftsführung: Dr. Patrick Peschlow, Dr. Lukas Pustina,
Michael Rosbach, Handelsregister-Nr.: HRB 18655,
HR-Gericht: Bonn, USt-IdNr.: DE-815299431