Re: http_date converter gives wrong date

2016-01-22 Thread Cyril Bonté

Hi Gregor,

Le 22/01/2016 18:01, Gregor Kovač a écrit :

Hi!

I've been using HAProxy 1.6.3 on XUbuntu 14.04 64.bit.
In my haproxy.conf I have:
(...)
 http-response set-header Expires %[date,http_date]
(...)
I test this using curl:
curl --cookie "USER_TOKEN=2345678901;BLA=ena;BILUMINA_SERVERID=3" --user
gregor:kovi http://localhost:10001

The HTTP response I get back:
HTTP/1.1 200 OK
content-length: 40
content-type: text/plain
server_name: curl/7.35.0
Expires: Sat, 22 Jan 2016 17:43:38 GMT

Hello HTTP World!

The problem I have here is that Expires should be Friday and not Saturday.


Confirmed.
The bug is easy to fix : gmtime() returns the day of the week as an int 
from 0 to 6, where Sunday = 0, whereas the code in haproxy begins on 
Monday :

const char day[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 
"Sun" };

I'll provide a patch soon.


--
Cyril Bonté



Re: http_date converter gives wrong date

2016-01-22 Thread Holger Just
Hi,

Gregor Kovač wrote:
> The problem I have here is that Expires should be Friday and not Saturday.

This is indeed a bug in HAProxy as it assumes the weekday to start on
Monday instead of Sunday. The attached patch fixes this issue.

The patch applies cleanly against master and 1.6.


Regards,
Holger
From 32cf0c931f0c4bfd3ea687aa7399e4f95626b6ad Mon Sep 17 00:00:00 2001
From: Holger Just 
Date: Fri, 22 Jan 2016 19:23:43 +0100
Subject: [PATCH] BUG/MINOR: Correct weekdays in http_date converter

Days of the week as returned by gmtime(3) are defined as the number of
days since Sunday, in the range 0 to 6.
---
 src/proto_http.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/proto_http.c b/src/proto_http.c
index e362a96..2f76afe 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -11973,7 +11973,7 @@ int val_hdr(struct arg *arg, char **err_msg)
  */
 static int sample_conv_http_date(const struct arg *args, struct sample *smp, 
void *private)
 {
-   const char day[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 
"Sun" };
+   const char day[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", 
"Sat" };
const char mon[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
struct chunk *temp;
struct tm *tm;
-- 
2.6.4



Re: http_date converter gives wrong date

2016-01-22 Thread Gregor Kovač
Hi!

I've tried it and it works as expected. Now I get "Expires: Fri, 22 Jan
2016 17:43:38 GMT"

Best regards,
Kovi

2016-01-22 19:35 GMT+01:00 Holger Just :

> Hi,
>
> Gregor Kovač wrote:
> > The problem I have here is that Expires should be Friday and not
> Saturday.
>
> This is indeed a bug in HAProxy as it assumes the weekday to start on
> Monday instead of Sunday. The attached patch fixes this issue.
>
> The patch applies cleanly against master and 1.6.
>
>
> Regards,
> Holger
>



-- 
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
|  In A World Without Fences Who Needs Gates?  |
|  Experience Linux.   |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~


http_date converter gives wrong date

2016-01-22 Thread Gregor Kovač
Hi!

I've been using HAProxy 1.6.3 on XUbuntu 14.04 64.bit.
In my haproxy.conf I have:
listen proxy_http
bind 127.0.0.1:10001
mode http
option httplog
log-tag haproxy-proxy_http_tag
acl auth_ok http_auth(L1)
acl local_net src 192.168.0.0/24
http-request auth realm 'proxy_http realm' if !auth_ok
http-request allow if local_net auth_ok
http-request deny if !local_net !auth_ok
http-request use-service lua.hello-world-http
http-response set-header Expires %[date,http_date]
capture cookie USER_TOKEN len 20
capture request header User-Agent len 64

lua.hello-world-http in defined in lua file like:
core.register_service("hello-world-http", "http", function(applet)
 local response = "Hello HTTP World!\n"
applet:set_status(200)
applet:add_header("content-length", string.len(response))
applet:add_header("content-type", "text/plain")
applet:add_header("server_name", applet.headers["user-agent"][0])
applet:start_response()
applet:send(response)
end)

I test this using curl:
curl --cookie "USER_TOKEN=2345678901;BLA=ena;BILUMINA_SERVERID=3" --user
gregor:kovi http://localhost:10001

The HTTP response I get back:
HTTP/1.1 200 OK
content-length: 40
content-type: text/plain
server_name: curl/7.35.0
Expires: Sat, 22 Jan 2016 17:43:38 GMT

Hello HTTP World!

The problem I have here is that Expires should be Friday and not Saturday.

Best regards,
Kovi

-- 
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
|  In A World Without Fences Who Needs Gates?  |
|  Experience Linux.   |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~