On Tue, Feb 24, 2015 at 10:26 AM, Poul-Henning Kamp <p...@phk.freebsd.dk> wrote:
> --------
> In message 
> <CABtDKm4ZYZFbJBrSAa5_L8MYko5SpgpJ09q0M_V=j8_g6zc...@mail.gmail.com>
> , Dridi Boukelmoune writes:
>
>>I have a set of patches that serve two purposes:
>>- fixing the current date parsing
>>- not breaking when the locale changes
>
> I think I have solved these issues now.

Yes, my test is passing (see below)

> Thank you for sending patches, even though I hardly used them
> in this case, mostly because I wanted to go a little deeper in the
> solution than you did.

A "little" :-)

I have one question though.

Why did you keep the ISO 8601 format for parsing?

Also please find my first patch rebased against the current master.
It's an improvement of m00020.vtc (testing both parsing and
formatting) and it adds a setlocale capability to the debug vmod.

Best Regards,
Dridi
From f04b72ca89bd82efdbbc03fd5277f39190c88066 Mon Sep 17 00:00:00 2001
From: Dridi Boukelmoune <dridi.boukelmo...@gmail.com>
Date: Mon, 9 Feb 2015 21:28:44 +0100
Subject: [PATCH] Add a new function `VOID debug.setlocale(STRING)`

The test `m00020.vtc` was updated to show how vtim functions behave with
a different locale.
---
 bin/varnishtest/tests/m00020.vtc | 45 ++++++++++++++++++++++++++++++++++++++--
 lib/libvmod_debug/vmod.vcc       |  2 ++
 lib/libvmod_debug/vmod_debug.c   |  8 +++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/bin/varnishtest/tests/m00020.vtc b/bin/varnishtest/tests/m00020.vtc
index 2ac50f8..a9af9b6 100644
--- a/bin/varnishtest/tests/m00020.vtc
+++ b/bin/varnishtest/tests/m00020.vtc
@@ -7,8 +7,19 @@ server s1 {
 
 varnish v1 -vcl+backend {
 	import ${vmod_std};
+	import ${vmod_debug};
+
+	sub vcl_recv {
+		if (req.http.Accept-Language) {
+			debug.setlocale(req.http.Accept-Language);
+		}
+	}
 
 	sub vcl_deliver {
+		if (!req.http.x-date) {
+			return (deliver);
+		}
+		set resp.http.x-date = std.time(req.http.x-date, now);
 		if (std.time(req.http.x-date, now) < now - 1y) {
 			set resp.http.x-past = 1;
 		}
@@ -22,19 +33,49 @@ client c1 {
 	txreq -hdr "X-Date: Mon, 20 Dec 2010 00:00:00 GMT"
 	rxresp
 	expect resp.http.x-past == 1
-	txreq -hdr "X-Date: Monday, 23-Dec-30 00:00:00 GMT"
+	expect resp.http.x-date == "Mon, 20 Dec 2010 00:00:00 GMT"
+
+	txreq -hdr "X-Date: Monday, 20-Dec-30 00:00:00 GMT"
+	rxresp
+	expect resp.http.x-past == <undef>
+	expect resp.http.x-future == <undef>
+
+	txreq -hdr "X-Date: Monday, 30-Feb-15 00:00:00 GMT"
+	rxresp
+	expect resp.http.x-past == <undef>
+	expect resp.http.x-future == <undef>
+
+	txreq -hdr "X-Date: Friday, 20-Dec-30 00:00:00 GMT"
 	rxresp
 	expect resp.http.x-future == 1
+	expect resp.http.x-date == "Fri, 20 Dec 2030 00:00:00 GMT"
+
 	txreq -hdr "X-Date: Mon Dec 20 00:00:00 2010"
 	rxresp
 	expect resp.http.x-past == 1
+	expect resp.http.x-date == "Mon, 20 Dec 2010 00:00:00 GMT"
+
 	txreq -hdr "X-Date: 2030-12-20T00:00:00"
 	rxresp
 	expect resp.http.x-future == 1
+	expect resp.http.x-date == "Fri, 20 Dec 2030 00:00:00 GMT"
+
 	txreq -hdr "X-Date: 1292803200.00"
 	rxresp
 	expect resp.http.x-past == 1
+	expect resp.http.x-date == "Mon, 20 Dec 2010 00:00:00 GMT"
+
 	txreq -hdr "X-Date: 1923955200"
 	rxresp
 	expect resp.http.x-future == 1
-} -run
+	expect resp.http.x-date == "Fri, 20 Dec 2030 00:00:00 GMT"
+}
+
+client c2 {
+	txreq -hdr "Accept-Language: fr_FR"
+	rxresp
+}
+
+client c1 -run
+client c2 -run
+client c1 -run
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index b5d108c..99b1dea 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -93,3 +93,5 @@ Encrypt the HTTP header with quad-ROT13 encryption,
 $Function STRING argtest(STRING one, REAL two=2, STRING three="3")
 
 $Function INT vre_limit()
+
+$Function VOID setlocale(STRING locale)
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index b6736fb..6a065e9 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -28,6 +28,7 @@
 
 #include "config.h"
 
+#include <locale.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -175,3 +176,10 @@ vmod_vre_limit(VRT_CTX)
 	(void)ctx;
 	return (cache_param->vre_limits.match);
 }
+
+VCL_VOID
+vmod_setlocale(VRT_CTX, VCL_STRING locale)
+{
+	(void)ctx;
+	setlocale(LC_ALL, locale);
+}
-- 
1.9.3

_______________________________________________
varnish-dev mailing list
varnish-dev@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to