Welcome! Log In Create A New Profile

Advanced

Override HTTP-Method

Posted by benvandamme 
Override HTTP-Method
May 03, 2016 03:20PM
Hello,

is it possible to override the $request_method?
I have the problem that a well known client tries to place a request with method "0". This has its roots in a bug that would take long time to fix.
Is it possible to do something like

if ($request_method = 0){
set $request_method POST;
}

I did a quick try on this but i qot an error that the variable "$request_method" is duplicate.

Kind Regards,

Benjamin
Re: Override HTTP-Method
May 03, 2016 03:35PM
Maybe this is helpful http://stackoverflow.com/questions/15362038/nginx-change-request-from-put-to-post

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Override HTTP-Method
May 03, 2016 03:41PM
Thank you for your reply.

I would like to try this but i have no idea how to do this without php.
My setup comes without php. It is a simple reverse proxy.
Is it possible to pass this to the proxy_pass-connection?
Re: Override HTTP-Method
May 03, 2016 04:20PM
Look at the 'map' example on that site, standard nginx stuff.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Override HTTP-Method
May 04, 2016 05:23AM
Hello,

i tried the following config:

add_header XX-method: $request_method;
add_header bla-method: $bla_method;

map $request_method $bla_method {
default $request_method;
0 POST;
BLA POST;
}

server {
listen 80 default;
server_name localhost;
location / {
proxy_method $bla_method;
proxy_pass http://<URL>:8080;
}
}

But it does not work. The problem persists.

Kind Regards,

Benjamin
Re: Override HTTP-Method
May 04, 2016 05:32AM
Try with Curl, check what it reports back including the headers and check the logfiles to see what Curl reports can be found in the logs.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Override HTTP-Method
May 04, 2016 05:40AM
Thats what I did.

The Error-Log says:
3 client sent invalid method while reading client request line, client: 127.0.0.1, server: localhost, request: "0 /"

And Curl:
HTTP/1.1 400 Bad Request
Server: nginx/1.9.15
Date: Wed, 04 May 2016 09:38:30 GMT
Content-Type: text/html
Content-Length: 173
Connection: close

<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.9.15</center>
</body>
</html>


It is like the mapping is not respected.
Re: Override HTTP-Method
May 04, 2016 05:51AM
Correct, a 400 is handled internally before any other handler,
see also https://forum.nginx.org/read.php?2,158557,158557#msg-158557

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Override HTTP-Method
May 04, 2016 06:07AM
Is there any possibility to change the method before the 400 happens?
Re: Override HTTP-Method
May 04, 2016 06:19AM
Maybe with Lua, otherwise you need to hack the code to not handle a 400, a grep for 400 and a grep for some other code which works as desired may give you an idea what to do.

nginx does not waste time with broken clients hence the 400 handling, it may cost you performance when you actually handle it as a lot of basic attacks result in 400's (ea. a DROP).

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 326
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready