Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP method is not preserved with redirect #1772

Closed
rothgar opened this issue Nov 30, 2017 · 4 comments · Fixed by #1776
Closed

HTTP method is not preserved with redirect #1772

rothgar opened this issue Nov 30, 2017 · 4 comments · Fixed by #1776

Comments

@rothgar
Copy link
Member

rothgar commented Nov 30, 2017

Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see https://kubernetes.io/docs/tasks/debug-application-cluster/troubleshooting/.):

What keywords did you search in NGINX Ingress controller issues before filing this one? (If you have found any duplicates, you should instead reply there.):


Is this a BUG REPORT or FEATURE REQUEST? (choose one):

NGINX Ingress controller version:
gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.15

Kubernetes version (use kubectl version):
1.5.7

Environment:

  • Cloud provider or hardware configuration: bare metal
  • OS (e.g. from /etc/os-release): coreos

What happened:
If a client redirects with a POST request to one of the ingress rules the ingress controller will provide a 301 redirect which changes POST to GET on the pod. A 307 redirect should be used instead to preserve the method.

What you expected to happen:
POST requests should be redirected as POST requests.

How to reproduce it (as minimally and precisely as possible):
Create an ingress rule and curl -X POST to the endpoint.
You'll get a 301 redirect to the backend and your POST will turn into a GET in the pod.

Anything else we need to know:
I was able to manually fix this by adding this snippet to my ingress rule

            if ($pass_access_scheme = http) {
                set $type  "http";
            }

            if ($request_method = POST) {
                set $type  "${type}POST"; 
            }

            if ($type = httpPOST) { 
                  return 307 https://$best_http_host$request_uri;
                  break; 
            }

This may not be the best way to make this work but it is the work around we found to make POST methods work.
We can probably do this with a configuration-snippet annotation but haven't tried yet.

@rothgar
Copy link
Member Author

rothgar commented Nov 30, 2017

I added the configuration snippet and it was added successfully but the snippets gets added to the end of the server section and so the default 301 redirect is being picked up first and the new configuration is not working as expected.

@aledbf
Copy link
Member

aledbf commented Nov 30, 2017

@rothgar I think we could change 301 with 308. https://developer.mozilla.org/es/docs/Web/HTTP/Status/308

Edit: or add a configuration option with a default

@rothgar
Copy link
Member Author

rothgar commented Nov 30, 2017

Simply changing 301 to 308 worked for the app I was testing. I didn't try all my other apps but this was a much easier change than expected.

@zlance
Copy link

zlance commented Aug 16, 2018

I'm still seeing this issue. I'm using image "quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.18.0" with pretty vanilla setup. I tried adding a configuration snippet to the ingress rule and that was not working. @rothgar could you tell me a bit more on how you got it to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants