Permalink
Browse files

get v3.0 build test clean #357

  • Loading branch information...
ritchieGitHub committed Sep 9, 2016
1 parent 0563f1f commit f5c2ec1f00e1cc2ada278a862048f1a813aeacfd
Showing with 1,330 additions and 114 deletions.
  1. +41 −7 core/src/main/java/org/nanohttpd/protocols/http/ClientHandler.java
  2. +54 −23 core/src/main/java/org/nanohttpd/protocols/http/HTTPSession.java
  3. +37 −5 core/src/main/java/org/nanohttpd/protocols/http/IHTTPSession.java
  4. +37 −6 core/src/main/java/org/nanohttpd/protocols/http/NanoHTTPD.java
  5. +41 −7 core/src/main/java/org/nanohttpd/protocols/http/ServerRunnable.java
  6. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/content/ContentType.java
  7. +36 −4 core/src/main/java/org/nanohttpd/protocols/http/content/Cookie.java
  8. +39 −8 core/src/main/java/org/nanohttpd/protocols/http/content/CookieHandler.java
  9. +35 −2 core/src/main/java/org/nanohttpd/protocols/http/request/Method.java
  10. +34 −1 core/src/main/java/org/nanohttpd/protocols/http/response/ChunkedOutputStream.java
  11. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/response/IStatus.java
  12. +43 −10 core/src/main/java/org/nanohttpd/protocols/http/response/Response.java
  13. +37 −4 core/src/main/java/org/nanohttpd/protocols/http/response/Status.java
  14. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/sockets/DefaultServerSocketFactory.java
  15. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/sockets/SecureServerSocketFactory.java
  16. +35 −2 core/src/main/java/org/nanohttpd/protocols/http/tempfiles/DefaultTempFile.java
  17. +36 −3 core/src/main/java/org/nanohttpd/protocols/http/tempfiles/DefaultTempFileManager.java
  18. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/tempfiles/DefaultTempFileManagerFactory.java
  19. +33 −0 core/src/main/java/org/nanohttpd/protocols/http/tempfiles/ITempFile.java
  20. +35 −2 core/src/main/java/org/nanohttpd/protocols/http/tempfiles/ITempFileManager.java
  21. +37 −4 core/src/main/java/org/nanohttpd/protocols/http/threading/DefaultAsyncRunner.java
  22. +34 −1 core/src/main/java/org/nanohttpd/protocols/http/threading/IAsyncRunner.java
  23. +37 −3 core/src/main/java/org/nanohttpd/util/IFactory.java
  24. +41 −6 core/src/main/java/org/nanohttpd/util/IFactoryThrowing.java
  25. +33 −0 core/src/test/java/org/nanohttpd/junit/protocols/http/HttpChunkedResponseTest.java
  26. +33 −0 fileupload/src/main/java/org/nanohttpd/fileupload/NanoFileUpload.java
  27. +5 −3 fileupload/src/test/java/org/nanohttpd/junit/fileupload/TestNanoFileUpLoad.java
  28. +33 −0 markdown-plugin/src/main/java/org/nanohttpd/markdown/MarkdownWebServerPlugin.java
  29. +0 −1 markdown-plugin/src/main/resources/META-INF/services/fi.iki.elonen.WebServerPluginInfo
  30. +1 −0 markdown-plugin/src/main/resources/META-INF/services/org.nanohttpd.webserver.WebServerPluginInfo
  31. +1 −1 nanolets/src/test/java/org/nanohttpd/junit/router/AppNanolets.java
  32. +3 −5 nanolets/src/test/java/org/nanohttpd/junit/router/TestNanolets.java
  33. +1 −2 webserver/src/main/java/org/nanohttpd/webserver/SimpleWebServer.java
  34. +33 −0 webserver/src/test/java/org/nanohttpd/junit/webserver/TestCorsHttpServer.java
  35. +33 −0 webserver/src/test/java/org/nanohttpd/junit/webserver/TestCorsHttpServerWithSingleOrigin.java
  36. +0 −1 webserver/src/test/resources/META-INF/services/fi.iki.elonen.WebServerPluginInfo
  37. +1 −0 webserver/src/test/resources/META-INF/services/org.nanohttpd.webserver.WebServerPluginInfo
  38. +33 −0 websocket/src/main/java/org/nanohttpd/protocols/websockets/CloseCode.java
  39. +33 −0 websocket/src/main/java/org/nanohttpd/protocols/websockets/CloseFrame.java
  40. +33 −1 websocket/src/main/java/org/nanohttpd/protocols/websockets/NanoWSD.java
  41. +33 −0 websocket/src/main/java/org/nanohttpd/protocols/websockets/OpCode.java
  42. +34 −1 websocket/src/main/java/org/nanohttpd/protocols/websockets/State.java
  43. +34 −1 websocket/src/main/java/org/nanohttpd/protocols/websockets/WebSocket.java
  44. +33 −0 websocket/src/main/java/org/nanohttpd/protocols/websockets/WebSocketException.java
  45. +33 −0 websocket/src/main/java/org/nanohttpd/protocols/websockets/WebSocketFrame.java
@@ -1,5 +1,38 @@
package org.nanohttpd.protocols.http;
/*
* #%L
* NanoHttpd-Core
* %%
* Copyright (C) 2012 - 2016 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 java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
@@ -13,6 +46,7 @@
* The runnable that will be used for every new client connection.
*/
public class ClientHandler implements Runnable {
private final NanoHTTPD httpd;
private final InputStream inputStream;
@@ -21,13 +55,13 @@
public ClientHandler(NanoHTTPD httpd, InputStream inputStream, Socket acceptSocket) {
this.httpd = httpd;
this.inputStream = inputStream;
this.inputStream = inputStream;
this.acceptSocket = acceptSocket;
}
public void close() {
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.acceptSocket);
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.acceptSocket);
}
@Override
@@ -52,10 +86,10 @@ public void run() {
NanoHTTPD.LOG.log(Level.SEVERE, "Communication with the client broken, or an bug in the handler code", e);
}
} finally {
NanoHTTPD.safeClose(outputStream);
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.acceptSocket);
NanoHTTPD.safeClose(outputStream);
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.acceptSocket);
httpd.asyncRunner.closed(this);
}
}
}
}
@@ -1,5 +1,38 @@
package org.nanohttpd.protocols.http;
/*
* #%L
* NanoHttpd-Core
* %%
* Copyright (C) 2012 - 2016 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 java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -49,7 +82,7 @@
public static final int MAX_HEADER_SIZE = 1024;
private final NanoHTTPD httpd;
private final ITempFileManager tempFileManager;
private final OutputStream outputStream;
@@ -80,14 +113,14 @@
public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream) {
this.httpd = httpd;
this.tempFileManager = tempFileManager;
this.tempFileManager = tempFileManager;
this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE);
this.outputStream = outputStream;
}
public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) {
this.httpd = httpd;
this.tempFileManager = tempFileManager;
this.tempFileManager = tempFileManager;
this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE);
this.outputStream = outputStream;
this.remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString();
@@ -269,8 +302,7 @@ private int scipOverNewLine(byte[] partHeaderBuff, int index) {
/**
* Decodes parameters in percent-encoded URI-format ( e.g.
* "name=Jack%20Daniels&pass=Single%20Malt" ) and adds them to given
* Map.
* "name=Jack%20Daniels&pass=Single%20Malt" ) and adds them to given Map.
*/
private void decodeParms(String parms, Map<String, List<String>> p) {
if (parms == null) {
@@ -324,14 +356,14 @@ public void execute() throws IOException {
} catch (SSLException e) {
throw e;
} catch (IOException e) {
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.outputStream);
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.outputStream);
throw new SocketException("NanoHttpd Shutdown");
}
if (read == -1) {
// socket was been closed
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.outputStream);
NanoHTTPD.safeClose(this.inputStream);
NanoHTTPD.safeClose(this.outputStream);
throw new SocketException("NanoHttpd Shutdown");
}
while (read > 0) {
@@ -422,14 +454,14 @@ public void execute() throws IOException {
resp.send(this.outputStream);
NanoHTTPD.safeClose(this.outputStream);
} finally {
NanoHTTPD.safeClose(r);
NanoHTTPD.safeClose(r);
this.tempFileManager.clear();
}
}
/**
* Find byte index separating header from body. It must be the last byte
* of the first two sequential new lines.
* Find byte index separating header from body. It must be the last byte of
* the first two sequential new lines.
*/
private int findHeaderEnd(final byte[] buf, int rlen) {
int splitbyte = 0;
@@ -450,9 +482,9 @@ private int findHeaderEnd(final byte[] buf, int rlen) {
}
/**
* Find the byte positions where multipart boundaries start. This reads
* a large block at a time and uses a temporary buffer to optimize
* (memory mapped) file access.
* Find the byte positions where multipart boundaries start. This reads a
* large block at a time and uses a temporary buffer to optimize (memory
* mapped) file access.
*/
private int[] getBoundaryPositions(ByteBuffer b, byte[] boundary) {
int[] res = new int[0];
@@ -554,8 +586,8 @@ public final String getUri() {
}
/**
* Deduce body length in bytes. Either from "content-length" header or
* read bytes.
* Deduce body length in bytes. Either from "content-length" header or read
* bytes.
*/
public long getBodySize() {
if (this.headers.containsKey("content-length")) {
@@ -608,8 +640,7 @@ public void parseBody(Map<String, String> files) throws IOException, ResponseExc
if (contentType.isMultipart()) {
String boundary = contentType.getBoundary();
if (boundary == null) {
throw new ResponseException(Status.BAD_REQUEST,
"BAD REQUEST: Content type is multipart/form-data but boundary missing. Usage: GET /example/file.html");
throw new ResponseException(Status.BAD_REQUEST, "BAD REQUEST: Content type is multipart/form-data but boundary missing. Usage: GET /example/file.html");
}
decodeMultipartFormData(contentType, fbuf, this.parms, files);
} else {
@@ -630,13 +661,13 @@ public void parseBody(Map<String, String> files) throws IOException, ResponseExc
files.put("content", saveTmpFile(fbuf, 0, fbuf.limit(), null));
}
} finally {
NanoHTTPD.safeClose(randomAccessFile);
NanoHTTPD.safeClose(randomAccessFile);
}
}
/**
* Retrieves the content of a sent file and saves it to a temporary
* file. The full path to the saved file is returned.
* Retrieves the content of a sent file and saves it to a temporary file.
* The full path to the saved file is returned.
*/
private String saveTmpFile(ByteBuffer b, int offset, int len, String filename_hint) {
String path = "";
@@ -653,7 +684,7 @@ private String saveTmpFile(ByteBuffer b, int offset, int len, String filename_hi
} catch (Exception e) { // Catch exception if any
throw new Error(e); // we won't recover, so throw an error
} finally {
NanoHTTPD.safeClose(fileOutputStream);
NanoHTTPD.safeClose(fileOutputStream);
}
}
return path;
@@ -1,5 +1,38 @@
package org.nanohttpd.protocols.http;
/*
* #%L
* NanoHttpd-Core
* %%
* Copyright (C) 2012 - 2016 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 java.io.IOException;
import java.io.InputStream;
import java.util.List;
@@ -10,8 +43,7 @@
import org.nanohttpd.protocols.http.request.Method;
/**
* Handles one session, i.e. parses the HTTP request and returns the
* response.
* Handles one session, i.e. parses the HTTP request and returns the response.
*/
public interface IHTTPSession {
@@ -26,9 +58,9 @@
Method getMethod();
/**
* This method will only return the first value for a given parameter.
* You will want to use getParameters if you expect multiple values for
* a given key.
* This method will only return the first value for a given parameter. You
* will want to use getParameters if you expect multiple values for a given
* key.
*
* @deprecated use {@link #getParameters()} instead.
*/
@@ -1,5 +1,38 @@
package org.nanohttpd.protocols.http;
/*
* #%L
* NanoHttpd-Core
* %%
* Copyright (C) 2012 - 2016 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 java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
@@ -90,6 +123,7 @@
* licence)
*/
public abstract class NanoHTTPD {
public static final String CONTENT_DISPOSITION_REGEX = "([ |\t]*Content-Disposition[ |\t]*:)(.*)";
public static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile(CONTENT_DISPOSITION_REGEX, Pattern.CASE_INSENSITIVE);
@@ -102,9 +136,6 @@
public static final Pattern CONTENT_DISPOSITION_ATTRIBUTE_PATTERN = Pattern.compile(CONTENT_DISPOSITION_ATTRIBUTE_REGEX);
public static final class ResponseException extends Exception {
private static final long serialVersionUID = 6569838532917408380L;
@@ -292,10 +323,10 @@ public static final void safeClose(Object closeable) {
private volatile ServerSocket myServerSocket;
public ServerSocket getMyServerSocket() {
return myServerSocket;
}
return myServerSocket;
}
private IFactoryThrowing<ServerSocket, IOException> serverSocketFactory = new DefaultServerSocketFactory();
private IFactoryThrowing<ServerSocket, IOException> serverSocketFactory = new DefaultServerSocketFactory();
private Thread myThread;
Oops, something went wrong.

0 comments on commit f5c2ec1

Please sign in to comment.