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:修飾子とタイプ | クラスと説明 |
---|---|
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 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
|
protected static java.util.Map<java.lang.String,java.lang.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(java.lang.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(java.net.Socket finalAccept,
java.io.InputStream inputStream)
create a instance of the client handler, 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 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 static 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 static java.lang.String |
decodePercent(java.lang.String str)
Decode percent encoded
String values. |
java.lang.String |
getHostname() |
int |
getListeningPort() |
static java.lang.String |
getMimeTypeForFile(java.lang.String uri)
Get MIME type from file name extension, if possible
|
NanoHTTPD.ServerSocketFactory |
getServerSocketFactory() |
NanoHTTPD.TempFileManagerFactory |
getTempFileManagerFactory() |
boolean |
isAlive() |
void |
makeSecure(javax.net.ssl.SSLServerSocketFactory sslServerSocketFactory,
java.lang.String[] sslProtocols)
Call before start() to serve over HTTPS instead of HTTP
|
static javax.net.ssl.SSLServerSocketFactory |
makeSSLSocketFactory(java.security.KeyStore loadedKeyStore,
javax.net.ssl.KeyManager[] keyManagers)
Creates an SSLSocketFactory for HTTPS.
|
static javax.net.ssl.SSLServerSocketFactory |
makeSSLSocketFactory(java.security.KeyStore loadedKeyStore,
javax.net.ssl.KeyManagerFactory loadedKeyFactory)
Creates an SSLSocketFactory for HTTPS.
|
static javax.net.ssl.SSLServerSocketFactory |
makeSSLSocketFactory(java.lang.String keyAndTrustStoreClasspathPath,
char[] passphrase)
Creates an SSLSocketFactory for HTTPS.
|
static java.util.Map<java.lang.String,java.lang.String> |
mimeTypes() |
static NanoHTTPD.Response |
newChunkedResponse(NanoHTTPD.Response.IStatus status,
java.lang.String mimeType,
java.io.InputStream data)
Create a response with unknown length (using HTTP 1.1 chunking).
|
static NanoHTTPD.Response |
newFixedLengthResponse(NanoHTTPD.Response.IStatus status,
java.lang.String mimeType,
java.io.InputStream data,
long totalBytes)
Create a response with known length.
|
static NanoHTTPD.Response |
newFixedLengthResponse(NanoHTTPD.Response.IStatus status,
java.lang.String mimeType,
java.lang.String txt)
Create a text response with known length.
|
static NanoHTTPD.Response |
newFixedLengthResponse(java.lang.String msg)
Create a text response with known length.
|
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)
非推奨です。
|
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 java.lang.String MIME_PLAINTEXT
public static final java.lang.String MIME_HTML
protected static java.util.Map<java.lang.String,java.lang.String> MIME_TYPES
protected NanoHTTPD.AsyncRunner asyncRunner
public NanoHTTPD(int port)
port
- portpublic NanoHTTPD(java.lang.String hostname, int port)
hostname
- hostnameport
- portpublic static java.util.Map<java.lang.String,java.lang.String> mimeTypes()
public static javax.net.ssl.SSLServerSocketFactory makeSSLSocketFactory(java.security.KeyStore loadedKeyStore, javax.net.ssl.KeyManager[] keyManagers) throws java.io.IOException
loadedKeyStore
- loadedKeyStorekeyManagers
- keyManagersjava.io.IOException
- IOExceptionpublic static javax.net.ssl.SSLServerSocketFactory makeSSLSocketFactory(java.security.KeyStore loadedKeyStore, javax.net.ssl.KeyManagerFactory loadedKeyFactory) throws java.io.IOException
loadedKeyStore
- loadedKeyStoreloadedKeyFactory
- loadedKeyFactoryjava.io.IOException
- IOExceptionpublic static javax.net.ssl.SSLServerSocketFactory makeSSLSocketFactory(java.lang.String keyAndTrustStoreClasspathPath, char[] passphrase) throws java.io.IOException
keyAndTrustStoreClasspathPath
- keyAndTrustStoreClasspathPathpassphrase
- passphrasejava.io.IOException
- IOExceptionpublic static java.lang.String getMimeTypeForFile(java.lang.String uri)
uri
- the string representing a filepublic void closeAllConnections()
protected NanoHTTPD.ClientHandler createClientHandler(java.net.Socket finalAccept, java.io.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 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 static 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).protected static java.lang.String decodePercent(java.lang.String str)
String
values.str
- the percent encoded String
protected boolean useGzipWhenAccepted(NanoHTTPD.Response r)
r
- Responsepublic final int getListeningPort()
public final boolean isAlive()
public NanoHTTPD.ServerSocketFactory getServerSocketFactory()
public void setServerSocketFactory(NanoHTTPD.ServerSocketFactory serverSocketFactory)
public java.lang.String getHostname()
public NanoHTTPD.TempFileManagerFactory getTempFileManagerFactory()
public void makeSecure(javax.net.ssl.SSLServerSocketFactory sslServerSocketFactory, java.lang.String[] sslProtocols)
sslServerSocketFactory
- sslServerSocketFactorysslProtocols
- sslProtocolspublic static NanoHTTPD.Response newChunkedResponse(NanoHTTPD.Response.IStatus status, java.lang.String mimeType, java.io.InputStream data)
status
- statusmimeType
- mimeTypedata
- datapublic static NanoHTTPD.Response newFixedLengthResponse(NanoHTTPD.Response.IStatus status, java.lang.String mimeType, java.io.InputStream data, long totalBytes)
status
- statusmimeType
- mimeTypedata
- datatotalBytes
- totalBytespublic static NanoHTTPD.Response newFixedLengthResponse(NanoHTTPD.Response.IStatus status, java.lang.String mimeType, java.lang.String txt)
status
- statusmimeType
- mimeTypetxt
- txtpublic static NanoHTTPD.Response newFixedLengthResponse(java.lang.String msg)
msg
- msgpublic NanoHTTPD.Response serve(NanoHTTPD.IHTTPSession session)
session
- The HTTP session@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.headers
- Header entries, percent decodedparms
- Parsed, percent decoded parameters from URI and, in case of
POST, data.files
- filespublic 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 java.io.IOException
java.io.IOException
- if the socket is in use.public void start(int timeout) throws java.io.IOException
timeout
- timeoutjava.io.IOException
- IOExceptionpublic void start(int timeout, boolean daemon) throws java.io.IOException
timeout
- timeout to use for socket connections.daemon
- start the thread daemon or not.java.io.IOException
- if the socket is in use.public void stop()
public final boolean wasStarted()