]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: lua: Fix return value of Socket.settimeout
authorTim Duesterhus <tim@bastelstu.be>
Sat, 6 Jan 2018 18:16:25 +0000 (19:16 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 9 Jan 2018 14:22:55 +0000 (15:22 +0100)
commit119a5f10e47f3507e58116002583e1226473485d
tree2e525cdcfeb99941cea3f23121634d8c5e845871
parent6edab865f661edf732d30232808118585cc2a1c7
BUG/MINOR: lua: Fix return value of Socket.settimeout

The `socket.tcp.settimeout` method of Lua returns `1` in all cases,
while the `Socket.settimeout` method of haproxy returns `0` in all
cases. This breaks the `socket.http` module, because it validates
the return value of `settimeout`.

This bug was introduced in commit 7e7ac32dad1e15c19152d37aaf9ea6b3f00a7226
(which is the very first commit adding the Socket class to Lua). This
bugfix should be backported to every branch containing that commit:
- 1.6
- 1.7
- 1.8

A test case for this bug is as follows:

The 'Test' response header will contain an HTTP status code with the
patch applied and will be zero (nil) without the patch applied.

http.lua:
  http = require("socket.http")

  core.register_action("bug", { "http-req" }, function(txn)
   local b, c, h = http.request {
   url = "http://93.184.216.34",
   headers = {
   Host = "example.com"
   },
   create = core.tcp,
   redirect = false
   }

   txn:set_var("txn.foo", c)
  end)

haproxy.cfg:
  global
   lua-load /scratch/haproxy/http.lua

  frontend fe
   bind 127.0.0.1:8080
   http-request lua.bug
   http-response set-header Test %[var(txn.foo)]

   default_backend be

  backend be
   server s example.com:80
src/hlua.c