public abstract class NanoHTTPD extends Object
Copyright (c) 2012-2013 by Paul S. Hawke, 2001,2005-2013 by Jarno Elonen, 2010 by Konstantinos Togias
Features + limitations:| 限定符和类型 | 类和说明 |
|---|---|
static interface |
NanoHTTPD.AsyncRunner
Pluggable strategy for asynchronously executing requests.
|
class |
NanoHTTPD.ClientHandler
The runnable that will be used for every new client connection.
|
protected static class |
NanoHTTPD.ContentType |
static class |
NanoHTTPD.Cookie |
class |
NanoHTTPD.CookieHandler
Provides rudimentary support for cookies.
|
static class |
NanoHTTPD.DefaultAsyncRunner
Default threading strategy for NanoHTTPD.
|
static class |
NanoHTTPD.DefaultServerSocketFactory
Creates a normal ServerSocket for TCP connections
|
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. parses the HTTP request and returns the
response.
|
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 class |
NanoHTTPD.SecureServerSocketFactory
Creates a new SSLServerSocket
|
class |
NanoHTTPD.ServerRunnable
The runnable that will be used for the main listening thread.
|
static interface |
NanoHTTPD.ServerSocketFactory
Factory to create ServerSocketFactories.
|
static interface |
NanoHTTPD.TempFile
A temp file.
|
static interface |
NanoHTTPD.TempFileManager
Temp file manager.
|
static interface |
NanoHTTPD.TempFileManagerFactory
Factory to create temp file managers.
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected NanoHTTPD.AsyncRunner |
asyncRunner
Pluggable strategy for asynchronously executing requests.
|
static String |
MIME_HTML
Common MIME type for dynamic content: html
|
static String |
MIME_PLAINTEXT
Common MIME type for dynamic content: plain text
|
protected static Map<String,String> |
MIME_TYPES
Hashtable mapping (String)FILENAME_EXTENSION -> (String)MIME_TYPE
|
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).
|
| 构造器和说明 |
|---|
NanoHTTPD(int port)
Constructs an HTTP server on given port.
|
NanoHTTPD(String hostname,
int port)
Constructs an HTTP server on given hostname and port.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
closeAllConnections()
Forcibly closes all connections that are open.
|
protected NanoHTTPD.ClientHandler |
createClientHandler(Socket finalAccept,
InputStream inputStream)
create a instance of the client support, subclasses can return a subclass
of the ClientHandler.
|
protected NanoHTTPD.ServerRunnable |
createServerRunnable(int timeout)
Instantiate the server runnable, can be overwritten by subclasses to
provide a subclass of the ServerRunnable.
|
protected static Map<String,List<String>> |
decodeParameters(Map<String,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 static Map<String,List<String>> |
decodeParameters(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 static String |
decodePercent(String str)
Decode percent encoded
String values. |
String |
getHostname() |
int |
getListeningPort() |
static String |
getMimeTypeForFile(String uri)
Get MIME type from file name extension, if possible
|
NanoHTTPD.ServerSocketFactory |
getServerSocketFactory() |
NanoHTTPD.TempFileManagerFactory |
getTempFileManagerFactory() |
boolean |
isAlive() |
void |
makeSecure(SSLServerSocketFactory sslServerSocketFactory,
String[] sslProtocols)
Call before start() to serve over HTTPS instead of HTTP
|
static SSLServerSocketFactory |
makeSSLSocketFactory(KeyStore loadedKeyStore,
KeyManager[] keyManagers)
Creates an SSLSocketFactory for HTTPS.
|
static SSLServerSocketFactory |
makeSSLSocketFactory(KeyStore loadedKeyStore,
KeyManagerFactory loadedKeyFactory)
Creates an SSLSocketFactory for HTTPS.
|
static SSLServerSocketFactory |
makeSSLSocketFactory(String keyAndTrustStoreClasspathPath,
char[] passphrase)
Creates an SSLSocketFactory for HTTPS.
|
static Map<String,String> |
mimeTypes() |
static NanoHTTPD.Response |
newChunkedResponse(NanoHTTPD.Response.IStatus status,
String mimeType,
InputStream data)
Create a response with unknown length (using HTTP 1.1 chunking).
|
static NanoHTTPD.Response |
newFixedLengthResponse(NanoHTTPD.Response.IStatus status,
String mimeType,
InputStream data,
long totalBytes)
Create a response with known length.
|
static NanoHTTPD.Response |
newFixedLengthResponse(NanoHTTPD.Response.IStatus status,
String mimeType,
String txt)
Create a text response with known length.
|
static NanoHTTPD.Response |
newFixedLengthResponse(String msg)
Create a text response with known length.
|
NanoHTTPD.Response |
serve(NanoHTTPD.IHTTPSession session)
Override this to customize the server.
|
NanoHTTPD.Response |
serve(String uri,
NanoHTTPD.Method method,
Map<String,String> headers,
Map<String,String> parms,
Map<String,String> files)
已过时。
|
void |
setAsyncRunner(NanoHTTPD.AsyncRunner asyncRunner)
Pluggable strategy for asynchronously executing requests.
|
void |
setServerSocketFactory(NanoHTTPD.ServerSocketFactory serverSocketFactory) |
void |
setTempFileManagerFactory(NanoHTTPD.TempFileManagerFactory tempFileManagerFactory)
Pluggable strategy for creating and cleaning up temporary files.
|
void |
start()
Start the server.
|
void |
start(int timeout)
Starts the server (in setDaemon(true) mode).
|
void |
start(int timeout,
boolean daemon)
Start the server.
|
void |
stop()
Stop the server.
|
protected boolean |
useGzipWhenAccepted(NanoHTTPD.Response r) |
boolean |
wasStarted() |
public static final int SOCKET_READ_TIMEOUT
public static final String MIME_PLAINTEXT
public static final String MIME_HTML
protected static Map<String,String> MIME_TYPES
protected NanoHTTPD.AsyncRunner asyncRunner
public NanoHTTPD(int port)
public NanoHTTPD(String hostname, int port)
public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManager[] keyManagers) throws IOException
IOExceptionpublic static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore, KeyManagerFactory loadedKeyFactory) throws IOException
IOExceptionpublic static SSLServerSocketFactory makeSSLSocketFactory(String keyAndTrustStoreClasspathPath, char[] passphrase) throws IOException
IOExceptionpublic static String getMimeTypeForFile(String uri)
uri - the string representing a filepublic void closeAllConnections()
protected NanoHTTPD.ClientHandler createClientHandler(Socket finalAccept, InputStream inputStream)
finalAccept - the socket the cleint is connected toinputStream - the input streamprotected NanoHTTPD.ServerRunnable createServerRunnable(int timeout)
timeout - the socet timeout to use.protected static Map<String,List<String>> decodeParameters(Map<String,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 static Map<String,List<String>> decodeParameters(String queryString)
queryString - a dsl string pulled from the URL.String (parameter name) to
List<String> (a list of the values supplied).protected static String decodePercent(String str)
String values.str - the percent encoded Stringprotected boolean useGzipWhenAccepted(NanoHTTPD.Response r)
public final int getListeningPort()
public final boolean isAlive()
public NanoHTTPD.ServerSocketFactory getServerSocketFactory()
public void setServerSocketFactory(NanoHTTPD.ServerSocketFactory serverSocketFactory)
public String getHostname()
public NanoHTTPD.TempFileManagerFactory getTempFileManagerFactory()
public void makeSecure(SSLServerSocketFactory sslServerSocketFactory, String[] sslProtocols)
public static NanoHTTPD.Response newChunkedResponse(NanoHTTPD.Response.IStatus status, String mimeType, InputStream data)
public static NanoHTTPD.Response newFixedLengthResponse(NanoHTTPD.Response.IStatus status, String mimeType, InputStream data, long totalBytes)
public static NanoHTTPD.Response newFixedLengthResponse(NanoHTTPD.Response.IStatus status, String mimeType, String txt)
public static NanoHTTPD.Response newFixedLengthResponse(String msg)
public NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session)
session - The HTTP session@Deprecated public NanoHTTPD.Response serve(String uri, NanoHTTPD.Method method, Map<String,String> headers, Map<String,String> parms, Map<String,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 decodedpublic void setAsyncRunner(NanoHTTPD.AsyncRunner asyncRunner)
asyncRunner - new strategy for handling threads.public void setTempFileManagerFactory(NanoHTTPD.TempFileManagerFactory tempFileManagerFactory)
tempFileManagerFactory - new strategy for handling temp files.public void start()
throws IOException
IOException - if the socket is in use.public void start(int timeout)
throws IOException
IOExceptionpublic void start(int timeout,
boolean daemon)
throws IOException
timeout - timeout to use for socket connections.daemon - start the thread daemon or not.IOException - if the socket is in use.public void stop()
public final boolean wasStarted()
Copyright © 2019. All rights reserved.