Hi Josh, Le mercredi 20 avril 2011 00:32:45, Josh Brown (Mailing List) a écrit : > Hi, > > I am wondering if anyone has been able to rewrite a request with regular > expression to use double quotes. > > I need to rewrites the second variable with quotes around it for the > backend application to accept it. > > Something like /service/list?key="value" > > I have tried the following rewrite rules on the backend before sending to > the servers: > > reqrep ^([^\ ]*)\ /uri/list/(.+) \1\ /service/list?key="\2" > reqrep ^([^\ ]*)\ /uri/list/(.+) \1\ /service/list?key=\"\2\" > reqrep ^([^\ ]*)\ /uri/list/(.+) \1\ /service/list?key=\x22\2\x22 > reqrep ^([^\ ]*)\ /uri/list/(.+) \1\ /service/list?key=%22\2%22 > > Unfortunately every time I do this the client gets back a 400 Bad Request. > > [19/Apr/2011:15:21:43.776] frontend backend/<NOSRV> -1/-1/-1/-1/0 400 187 - > - PR-- 0/0/0/0/0 0/0 "GET /uri/list/value HTTP/1.0" > > If I remove the quotes the request goes through HAProxy just fine. > Unfortunately the application then freaks out :-) > > This is HAProxy 1.4.8 on CentOS. > > Anyone have any ideas?
This is because your regexp also matches the HTTP/1.0 or HTTP/1.1 part of the request line, due to (.+). For a request like : GET /uri/list/foo HTTP/1.0 Your rewrite rules (I take the last one as an example, which looks to be what you need) will rewrite it as : GET /service/list?key=%22foo HTTP/1.0%22 You can try something like this instead (not tested) : reqrep ^([^\ ]*)\ /uri/list/([^\ ]*)\ (.*) \1\ /service/list?key=%22\2%22\ \3 This should rewrite the following line : GET /uri/list/foo HTTP/1.0 as : GET /service/list?key=%22foo%22 HTTP/1.0 -- Cyril Bonté