diff options
author | ritchie <ritchie@gmx.at> | 2015-05-10 07:48:04 +0200 |
---|---|---|
committer | ritchie <ritchie@gmx.at> | 2015-05-10 07:48:04 +0200 |
commit | 34109aa1ea59d8e73d46e5945a62942a431044e0 (patch) | |
tree | 6dd0e496c9ac81cfd5122d8dc177e6a8befb5207 /core | |
parent | b2067792254729ba7267bdba569b609ab38463ea (diff) | |
download | nanohttpd-34109aa1ea59d8e73d46e5945a62942a431044e0.tar.gz |
#175 missinh header version fixed
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/fi/iki/elonen/NanoHTTPD.java | 21 | ||||
-rw-r--r-- | core/src/test/java/fi/iki/elonen/InvalidRequestTest.java | 80 |
2 files changed, 91 insertions, 10 deletions
diff --git a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java index 7ad1843..5bdb9bb 100644 --- a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java +++ b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java @@ -301,7 +301,7 @@ public abstract class NanoHTTPD { // stacktrace if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage())) && !(e instanceof SocketTimeoutException)) { - LOG.log(Level.SEVERE, "Communication with the client broken", e); + LOG.log(Level.FINE, "Communication with the client broken", e); } } finally { safeClose(outputStream); @@ -312,7 +312,7 @@ public abstract class NanoHTTPD { } }); } catch (IOException e) { - LOG.log(Level.SEVERE, "Communication with the client broken", e); + LOG.log(Level.FINE, "Communication with the client broken", e); } } while (!myServerSocket.isClosed()); } @@ -1217,14 +1217,15 @@ public abstract class NanoHTTPD { // followed by HTTP headers. Ignore version but parse headers. // NOTE: this now forces header names lower case since they are // case insensitive and vary by client. - if (st.hasMoreTokens()) { - String line = in.readLine(); - while (line != null && line.trim().length() > 0) { - int p = line.indexOf(':'); - if (p >= 0) - headers.put(line.substring(0, p).trim().toLowerCase(Locale.US), line.substring(p + 1).trim()); - line = in.readLine(); - } + if (!st.hasMoreTokens()) { + LOG.log(Level.FINE, "no protocol version specified, strange.."); + } + String line = in.readLine(); + while (line != null && line.trim().length() > 0) { + int p = line.indexOf(':'); + if (p >= 0) + headers.put(line.substring(0, p).trim().toLowerCase(Locale.US), line.substring(p + 1).trim()); + line = in.readLine(); } pre.put("uri", uri); diff --git a/core/src/test/java/fi/iki/elonen/InvalidRequestTest.java b/core/src/test/java/fi/iki/elonen/InvalidRequestTest.java new file mode 100644 index 0000000..fd3d196 --- /dev/null +++ b/core/src/test/java/fi/iki/elonen/InvalidRequestTest.java @@ -0,0 +1,80 @@ +package fi.iki.elonen; + +/* + * #%L + * NanoHttpd-Core + * %% + * Copyright (C) 2012 - 2015 nanohttpd + * %% + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the nanohttpd nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +import org.junit.Test; + +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; + +public class InvalidRequestTest extends HttpServerTest { + + @Test + public void testGetRequestWithoutProtocol() { + invokeServer("GET " + URI + "\r\nX-Important-Header: foo" ); + + assertNotNull(testServer.parms); + assertTrue(testServer.header.size() > 0); + assertNotNull(testServer.files); + assertNotNull(testServer.uri); + } + + @Test + public void testPostRequestWithoutProtocol() { + invokeServer("POST " + URI + "\r\nContent-Length: 123"); + assertNotNull(testServer.parms); + assertTrue(testServer.header.size() > 0); + assertNotNull(testServer.files); + assertNotNull(testServer.uri); + } + + + @Test + public void testGetRequestWithProtocol() { + invokeServer("GET " + URI + " HTTP/1.1\r\nX-Important-Header: foo" ); + + assertNotNull(testServer.parms); + assertTrue(testServer.header.size() > 0); + assertNotNull(testServer.files); + assertNotNull(testServer.uri); + } + + @Test + public void testPostRequestWithProtocol() { + invokeServer("POST " + URI + " HTTP/1.1\r\nContent-Length: 123"); + assertNotNull(testServer.parms); + assertTrue(testServer.header.size() > 0); + assertNotNull(testServer.files); + assertNotNull(testServer.uri); + } +}
\ No newline at end of file |