gessnerfl / fake-smtp-server

A simple SMTP Server for Testing purposes. Emails are stored in an in-memory database and rendered in a Web UI
Apache License 2.0
426 stars 88 forks source link

Can't delete messages when working behind reverse proxy #67

Closed iivanov9 closed 2 years ago

iivanov9 commented 2 years ago

We run fake-smtp in docker on a devel server with public IP. We use nginx as a reverse proxy with basic auth and https enabled. Everything works fine except one problem - when user press "Delete" button, fake-smtp returns 405 error: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Jun 08 07:55:20 GMT 2022 There was an unexpected error (type=Method Not Allowed, status=405).

And docker logs for this container shows an error: WARN 7 --- [-nio-443-exec-9] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

When fake-smtp runs locally everything works fine. User request simulation with curl. Behind nginx: curl -v -d "_method=delete&_method=delete" -u "user:pass" -H "Content-Type: application/x-www-form-urlencoded" -X POST https://devel-serv/email/50 Response headers: < HTTP/1.1 405 < Server: nginx/1.16.1 < Date: Tue, 07 Jun 2022 15:32:41 GMT < Content-Type: application/json < Transfer-Encoding: chunked < Connection: keep-alive < Allow: DELETE, GET

Locally: curl -v -d "_method=delete&_method=delete" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://127.0.0.1:5080/email/3 Response headers: < HTTP/1.1 302 < Location: http://127.0.0.1:5080/email < Content-Language: en-US < Content-Length: 0 < Date: Tue, 07 Jun 2022 15:19:07 GMT

Nginx config: _upstream smtp { server 127.0.0.1:8280; keepalive 100; } location / { proxy_pass_request_headers on; proxy_set_header Host $host; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_pass http://smtp; auth_basic "Fake SMTP"; auth_basic_userfile /etc/nginx/auth/.htpasswd; }

gessnerfl commented 2 years ago

@iivanov9 do you see in the access logs which status cod is returned form fakesmtp server?

iivanov9 commented 2 years ago

Here is an error message from container logs: fakesmtp_1 | 2022-06-09 18:49:47.198 WARN 1 --- [-nio-443-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]

cbrien commented 2 years ago

@iivanov9 Please try to add spring.mvc.hiddenmethod.filter.enabled=true to your application.properties.

iivanov9 commented 2 years ago

cbrien, thank you! works perfectly.

gessnerfl commented 2 years ago

@cbrien: Thanks for jumping in.