Fix NanoHTTP 2.3.1 bug: "BAD REQUEST: Syntax error. HTTP verb .. unhandled"
authorChristian Weiske <cweiske@cweiske.de>
Fri, 3 Jun 2022 19:26:14 +0000 (21:26 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 3 Jun 2022 19:27:21 +0000 (21:27 +0200)
Happens when data are POSTed or PUT without us reading them.

Bug report: https://github.com/NanoHttpd/nanohttpd/issues/356

Solution by @cowenberg in
https://github.com/NanoHttpd/nanohttpd/issues/356#issuecomment-288422714

Error message we got:
E/f       (  571): Got failure response with message: BAD REQUEST: Syntax error. HTTP verb gamer%5Bkey%5D=-----BEGIN+PUBLIC+KEY-----%0AMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUYcfiISnlc%2FHrpRi%2BTX1keBUoY2%2FiR45q0sy6%0A3SXkzgmgQCf5Kitx6rv0djQEOP%2FcvIFYFOx8At%2FAwgzhd8ltU%2F1Z%2BRNohukXvMMiCuJr5CNhtdxp%0ABfWF%2FSTV%2FDSYPpP%2BZtLgthNhERomW8krVcgxV%2F%2B9NK2NHA0W7IJ%2FmIzffwIDAQAB%0A-----END+PUBLIC+KEY-----%0A&gamer%5Bpassword%5D=.&auth_token=00702342-0000-1111-2222-c3e1500cafe1&gamer%5Busername%5D=cweiskePUT unhandled.

src/main/java/fi/iki/elonen/NanoHTTPD.java

index 75174f33fdb8855d8884bea92403ff646159c92f..1810a5a393c955753fb28b8ee29ca63eb41186ec 100644 (file)
@@ -981,6 +981,7 @@ public abstract class NanoHTTPD {
                 safeClose(this.outputStream);
             } finally {
                 safeClose(r);
                 safeClose(this.outputStream);
             } finally {
                 safeClose(r);
+                safeClose(this.inputStream);
                 this.tempFileManager.clear();
             }
         }
                 this.tempFileManager.clear();
             }
         }