Re: Print header lua script

2018-01-11 Thread Aleksandar Lazic

Hi.

I have written a blog post how to use this lua scirpt in a dockerized 
haproxy.


https://www.me2digital.com/blog/2018/01/show-headers-in-haproxy/

I appreciate any feedback ;-)

Best regards
Aleks

-- Originalnachricht --
Von: "Aleksandar Lazic" <al-hapr...@none.at>
An: haproxy@formilux.org
Gesendet: 10.01.2018 23:33:01
Betreff: Print header lua script


Hi.

I have the need to print the request headers which reaches the haproxy.

Today I was sitting down and started to write this small script.

Due to the fact that this is my first lua & haproxy script I'm sure 
it's not the most efficient version ;-)


I appreciate any feedback ;-)

### print_headers.lua
core.register_action("print-headers",{ "http-req" }, 
function(transaction)

   --[[
   transaction is of class TXN.
   TXN contains contains a property 'http' which is an instance
   of HAProxy HTTP class
   ]]

   local hdr = transaction.http:req_get_headers()

   for key,value in pairs(hdr) do
 local mystr = key
 mystr = mystr .. ": "
 for _ ,val2 in pairs(value) do
   mystr = mystr .. val2
 end
 core.Info(mystr)
   end

end)

###

### haproxy.cfg
global
 log /dev/log local1 debug
 lua-load /etc/haproxy/print_headers.lua

defaults
 log global
 mode http

listen proxy001
 
 http-request lua.print-headers
 
###

One issue is that I have every entry twice in the log, I assume this 
could be because I defined the loglevel "debug" and the 'core.Info' is 
in info level


###
Jan 10 23:22:58 app001 haproxy[26681]: accept-encoding: deflate, gzip
Jan 10 23:22:58 app001 haproxy[26681]: accept-encoding: deflate, gzip
Jan 10 23:22:58 app001 haproxy[26681]: content-type: application/json
Jan 10 23:22:58 app001 haproxy[26681]: content-type: application/json
Jan 10 23:22:58 app001 haproxy[26681]: user-agent: curl/7.47.0
Jan 10 23:22:58 app001 haproxy[26681]: user-agent: curl/7.47.0
Jan 10 23:22:58 app001 haproxy[26681]: x-request-id: 3
Jan 10 23:22:58 app001 haproxy[26681]: x-request-id: 3
Jan 10 23:22:58 app001 haproxy[26681]: content-length: 63
Jan 10 23:22:58 app001 haproxy[26681]: content-length: 63
Jan 10 23:22:58 app001 haproxy[26681]: host: MY_HOST:1234
Jan 10 23:22:58 app001 haproxy[26681]: host: MY_HOST:1234
Jan 10 23:22:58 app001 haproxy[26681]: accept: */*
Jan 10 23:22:58 app001 haproxy[26681]: accept: */*
###

Thanks for feedback.

aleks







Print header lua script

2018-01-10 Thread Aleksandar Lazic

Hi.

I have the need to print the request headers which reaches the haproxy.

Today I was sitting down and started to write this small script.

Due to the fact that this is my first lua & haproxy script I'm sure it's 
not the most efficient version ;-)


I appreciate any feedback ;-)

### print_headers.lua
core.register_action("print-headers",{ "http-req" }, 
function(transaction)

--[[
transaction is of class TXN.
TXN contains contains a property 'http' which is an instance
of HAProxy HTTP class
]]

local hdr = transaction.http:req_get_headers()

for key,value in pairs(hdr) do
  local mystr = key
  mystr = mystr .. ": "
  for _ ,val2 in pairs(value) do
mystr = mystr .. val2
  end
  core.Info(mystr)
end

end)

###

### haproxy.cfg
global
  log /dev/log local1 debug
  lua-load /etc/haproxy/print_headers.lua

defaults
  log global
  mode http

listen proxy001
  
  http-request lua.print-headers
  
###

One issue is that I have every entry twice in the log, I assume this 
could be because I defined the loglevel "debug" and the 'core.Info' is 
in info level


###
Jan 10 23:22:58 app001 haproxy[26681]: accept-encoding: deflate, gzip
Jan 10 23:22:58 app001 haproxy[26681]: accept-encoding: deflate, gzip
Jan 10 23:22:58 app001 haproxy[26681]: content-type: application/json
Jan 10 23:22:58 app001 haproxy[26681]: content-type: application/json
Jan 10 23:22:58 app001 haproxy[26681]: user-agent: curl/7.47.0
Jan 10 23:22:58 app001 haproxy[26681]: user-agent: curl/7.47.0
Jan 10 23:22:58 app001 haproxy[26681]: x-request-id: 3
Jan 10 23:22:58 app001 haproxy[26681]: x-request-id: 3
Jan 10 23:22:58 app001 haproxy[26681]: content-length: 63
Jan 10 23:22:58 app001 haproxy[26681]: content-length: 63
Jan 10 23:22:58 app001 haproxy[26681]: host: MY_HOST:1234
Jan 10 23:22:58 app001 haproxy[26681]: host: MY_HOST:1234
Jan 10 23:22:58 app001 haproxy[26681]: accept: */*
Jan 10 23:22:58 app001 haproxy[26681]: accept: */*
###

Thanks for feedback.

aleks