public abstract class NanoHTTPD
extends java.lang.Object
Copyright (c) 2012-2013 by Paul S. Hawke, 2001,2005-2013 by Jarno Elonen, 2010 by Konstantinos Togias Features + limitations:
Modifier and Type | Class and Description |
---|---|
static interface |
NanoHTTPD.AsyncRunner
Pluggable strategy for asynchronously executing requests.
|
static class |
NanoHTTPD.Cookie |
class |
NanoHTTPD.CookieHandler
Provides rudimentary support for cookies.
|
static class |
NanoHTTPD.DefaultAsyncRunner
Default threading strategy for NanoHttpd.
|
static class |
NanoHTTPD.DefaultTempFile
Default strategy for creating and cleaning up temporary files.
|
static class |
NanoHTTPD.DefaultTempFileManager
Default strategy for creating and cleaning up temporary files.
|
protected class |
NanoHTTPD.HTTPSession |
static interface |
NanoHTTPD.IHTTPSession
Handles one session, i.e.
|
static class |
NanoHTTPD.Method
HTTP Request methods, with the ability to decode a
String
back to its enum value. |
static class |
NanoHTTPD.Response
HTTP response.
|
static class |
NanoHTTPD.ResponseException |
static interface |
NanoHTTPD.TempFile
A temp file.
|
static interface |
NanoHTTPD.TempFileManager
Temp file manager.
|
static interface |
NanoHTTPD.TempFileManagerFactory
Factory to create temp file managers.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MIME_HTML
Common mime type for dynamic content: html
|
static java.lang.String |
MIME_PLAINTEXT
Common mime type for dynamic content: plain text
|
static int |
SOCKET_READ_TIMEOUT
Maximum time to wait on Socket.getInputStream().read() (in milliseconds)
This is required as the Keep-Alive HTTP connections would otherwise block
the socket reading thread forever (or as long the browser is open).
|
Constructor and Description |
---|
NanoHTTPD(int port)
Constructs an HTTP server on given port.
|
NanoHTTPD(java.lang.String hostname,
int port)
Constructs an HTTP server on given hostname and port.
|
Modifier and Type | Method and Description |
---|---|
void |
closeAllConnections()
Forcibly closes all connections that are open.
|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
decodeParameters(java.util.Map<java.lang.String,java.lang.String> parms)
Decode parameters from a URL, handing the case where a single parameter
name might have been supplied several times, by return lists of values.
|
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
decodeParameters(java.lang.String queryString)
Decode parameters from a URL, handing the case where a single parameter
name might have been supplied several times, by return lists of values.
|
protected java.lang.String |
decodePercent(java.lang.String str)
Decode percent encoded
String values. |
int |
getListeningPort() |
boolean |
isAlive() |
void |
registerConnection(java.net.Socket socket)
Registers that a new connection has been set up.
|
NanoHTTPD.Response |
serve(NanoHTTPD.IHTTPSession session)
Override this to customize the server.
|
NanoHTTPD.Response |
serve(java.lang.String uri,
NanoHTTPD.Method method,
java.util.Map<java.lang.String,java.lang.String> headers,
java.util.Map<java.lang.String,java.lang.String> parms,
java.util.Map<java.lang.String,java.lang.String> files)
Deprecated.
|
void |
setAsyncRunner(NanoHTTPD.AsyncRunner asyncRunner)
Pluggable strategy for asynchronously executing requests.
|
void |
setTempFileManagerFactory(NanoHTTPD.TempFileManagerFactory tempFileManagerFactory)
Pluggable strategy for creating and cleaning up temporary files.
|
void |
start()
Start the server.
|
void |
stop()
Stop the server.
|
void |
unRegisterConnection(java.net.Socket socket)
Registers that a connection has been closed
|
boolean |
wasStarted() |
public static final int SOCKET_READ_TIMEOUT
public static final java.lang.String MIME_PLAINTEXT
public static final java.lang.String MIME_HTML
public NanoHTTPD(int port)
port
- public NanoHTTPD(java.lang.String hostname, int port)
hostname
- port
- public void start() throws java.io.IOException
java.io.IOException
- if the socket is in use.public void stop()
public void registerConnection(java.net.Socket socket)
socket
- the Socket
for the connection.public void unRegisterConnection(java.net.Socket socket)
socket
- the Socket
for the connection.public void closeAllConnections()
public final int getListeningPort()
public final boolean wasStarted()
public final boolean isAlive()
@Deprecated public NanoHTTPD.Response serve(java.lang.String uri, NanoHTTPD.Method method, java.util.Map<java.lang.String,java.lang.String> headers, java.util.Map<java.lang.String,java.lang.String> parms, java.util.Map<java.lang.String,java.lang.String> files)
uri
- Percent-decoded URI without parameters, for example
"/index.cgi"method
- "GET", "POST" etc.parms
- Parsed, percent decoded parameters from URI and, in case of
POST, data.headers
- Header entries, percent decodedfiles
- public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session)
session
- The HTTP sessionprotected java.lang.String decodePercent(java.lang.String str)
String
values.str
- the percent encoded String
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> decodeParameters(java.util.Map<java.lang.String,java.lang.String> parms)
parms
- original NanoHttpd parameters values, as passed to the
serve()
method.String
(parameter name) to
List<String>
(a list of the values supplied).protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> decodeParameters(java.lang.String queryString)
queryString
- a query string pulled from the URL.String
(parameter name) to
List<String>
(a list of the values supplied).public void setAsyncRunner(NanoHTTPD.AsyncRunner asyncRunner)
asyncRunner
- new strategy for handling threads.public void setTempFileManagerFactory(NanoHTTPD.TempFileManagerFactory tempFileManagerFactory)
tempFileManagerFactory
- new strategy for handling temp files.