Adis, Am 26.09.19 um 16:01 schrieb Adis Nezirovic: > While I agree that using zero based array indexing is a mistake (wearing > my Lua hat), I don't think your proposal will make situation any better. > Actually ot might hurt existing Lua code in unforeseen ways.
Yes, I understand that it breaks backwards compatibility. That's why I added the cover letter with the rationale of duplicating the first value instead of making the 0-index a nil. > e.g. what happens if you have a Lua action or service which uses request > headers for its own nefarious purposes (like copying headers and using > them for new requests). It now sends duplicate headers (name, value) > which some upstream servers might not like. > > Second thing, with Lua 5.2(?), "one" based arrays can use '#' operator > to get the array length. With your proposal, we'd have tables of length > N, where # operator would report N - 1 length > (That's just confusing, we'd have "1" based arrays which are not "1" based) In fact the `#` operator was the reason for this patch. In my script I was attempting to count the instances of one header and was confused when it returned 0 instead of the expected 1. > The last, but not the least, I am not fond of modifying request data by > the HAProxy Lua layer. Suddenly, existing Lua code would see duplicate > header values out of blue. > > In my book, an improvement would be a new function, let's call it > hlua_http_get_headers_kv(), which returns table with header names as > keys, and values would be either "string" or array in case of multiple > header values (we can fold multiple values easily with Lua)... If a new function is introduced it should normalize headers itself. Either split all of them at a comma or concatenate all duplicates with a comma. Currently you both have to implement both splitting and concatenating yourself. See also: https://github.com/TimWolla/haproxy-auth-request/blob/8c7f3fb364c0798656989db039d0acca80025875/auth-request.lua#L60 [1] Also: The AppletHTTP class is affected as well. But it does not have a function for getting the headers, instead has a `headers` property. That one should probably be made consistent with the HTTP class then. Best regards Tim Düsterhus [1] I'd love to use https://github.com/haproxytech/haproxy-lua-http for haproxy-auth-request, but the GPL stands in the way :-(