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 class |
NanoHTTPD.ResponseException |
| 限定符和类型 | 字段和说明 |
|---|---|
protected IAsyncRunner |
asyncRunner
Pluggable strategy for asynchronously executing requests.
|
static Pattern |
CONTENT_DISPOSITION_ATTRIBUTE_PATTERN |
static String |
CONTENT_DISPOSITION_ATTRIBUTE_REGEX |
static Pattern |
CONTENT_DISPOSITION_PATTERN |
static String |
CONTENT_DISPOSITION_REGEX |
static Pattern |
CONTENT_TYPE_PATTERN |
static String |
CONTENT_TYPE_REGEX |
String |
hostname |
protected List<IHandler<IHTTPSession,Response>> |
interceptors |
static Logger |
LOG
logger to log to.
|
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
|
int |
myPort |
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 |
addHTTPInterceptor(IHandler<IHTTPSession,Response> interceptor) |
void |
closeAllConnections()
Forcibly closes all connections that are open.
|
protected ClientHandler |
createClientHandler(Socket finalAccept,
InputStream inputStream)
create a instance of the client handler, subclasses can return a subclass
of the ClientHandler.
|
protected 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.
|
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
|
ServerSocket |
getMyServerSocket() |
IFactoryThrowing<ServerSocket,IOException> |
getServerSocketFactory() |
IFactory<ITempFileManager> |
getTempFileManagerFactory() |
Response |
handle(IHTTPSession session)
This is the "master" method that delegates requests to handlers and makes
sure there is a response to every request.
|
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 void |
safeClose(Object closeable) |
protected Response |
serve(IHTTPSession session)
已过时。
|
void |
setAsyncRunner(IAsyncRunner asyncRunner)
Pluggable strategy for asynchronously executing requests.
|
void |
setHTTPHandler(IHandler<IHTTPSession,Response> handler) |
void |
setServerSocketFactory(IFactoryThrowing<ServerSocket,IOException> serverSocketFactory) |
void |
setTempFileManagerFactory(IFactory<ITempFileManager> 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.
|
boolean |
wasStarted() |
public static final Pattern CONTENT_DISPOSITION_PATTERN
public static final Pattern CONTENT_TYPE_PATTERN
public static final String CONTENT_DISPOSITION_ATTRIBUTE_REGEX
public static final Pattern CONTENT_DISPOSITION_ATTRIBUTE_PATTERN
public static final int SOCKET_READ_TIMEOUT
public static final String MIME_PLAINTEXT
public static final String MIME_HTML
public static final Logger LOG
protected static Map<String,String> MIME_TYPES
public final String hostname
public final int myPort
protected List<IHandler<IHTTPSession,Response>> interceptors
protected IAsyncRunner 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 static final void safeClose(Object closeable)
public ServerSocket getMyServerSocket()
public void setHTTPHandler(IHandler<IHTTPSession,Response> handler)
public void addHTTPInterceptor(IHandler<IHTTPSession,Response> interceptor)
public void closeAllConnections()
protected ClientHandler createClientHandler(Socket finalAccept, InputStream inputStream)
finalAccept - the socket the cleint is connected toinputStream - the input streamprotected 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 query string pulled from the URL.String (parameter name) to
List<String> (a list of the values supplied).public static String decodePercent(String str)
String values.str - the percent encoded Stringpublic final int getListeningPort()
public final boolean isAlive()
public IFactoryThrowing<ServerSocket,IOException> getServerSocketFactory()
public void setServerSocketFactory(IFactoryThrowing<ServerSocket,IOException> serverSocketFactory)
public String getHostname()
public IFactory<ITempFileManager> getTempFileManagerFactory()
public void makeSecure(SSLServerSocketFactory sslServerSocketFactory, String[] sslProtocols)
public Response handle(IHTTPSession session)
session - the incoming session@Deprecated protected Response serve(IHTTPSession session)
session - The HTTP sessionpublic void setAsyncRunner(IAsyncRunner asyncRunner)
asyncRunner - new strategy for handling threads.public void setTempFileManagerFactory(IFactory<ITempFileManager> 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 © 2012–2020 nanohttpd. All rights reserved.