public class NanoHTTPD
extends java.lang.Object
NanoHTTPD version 1.14, Copyright © 2001,2005-2010 Jarno Elonen (elonen@iki.fi, http://iki.fi/elonen/)
Features + limitations:
Ways to use:
| Modifier and Type | Class and Description |
|---|---|
static class |
NanoHTTPD.Response
HTTP response.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
HTTP_BADREQUEST
Some HTTP response status codes
|
static java.lang.String |
HTTP_FORBIDDEN
Some HTTP response status codes
|
static java.lang.String |
HTTP_INTERNALERROR
Some HTTP response status codes
|
static java.lang.String |
HTTP_NOTFOUND
Some HTTP response status codes
|
static java.lang.String |
HTTP_NOTIMPLEMENTED
Some HTTP response status codes
|
static java.lang.String |
HTTP_OK
Some HTTP response status codes
|
static java.lang.String |
HTTP_REDIRECT
Some HTTP response status codes
|
static java.lang.String |
MIME_DEFAULT_BINARY
Common mime types for dynamic content
|
static java.lang.String |
MIME_HTML
Common mime types for dynamic content
|
static java.lang.String |
MIME_JSON
Common mime types for dynamic content
|
static java.lang.String |
MIME_PLAINTEXT
Common mime types for dynamic content
|
| Constructor and Description |
|---|
NanoHTTPD(int port)
Starts a HTTP server to given port and binds on all host-names.
|
NanoHTTPD(int port,
java.net.InetAddress bindHost)
Starts a HTTP server to given port and only binds on the given name if specifed non-null.
|
NanoHTTPD(int port,
java.net.InetAddress bindHost,
int sessionTimeout)
Starts a HTTP server to given port and only binds on the given name if specifed non-null.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
main(java.lang.String[] args)
Starts as a standalone file server and waits for Enter.
|
NanoHTTPD.Response |
serve(java.lang.String uri,
java.lang.String method,
java.util.Properties header,
java.util.Properties parms)
Override this to customize the server.
|
NanoHTTPD.Response |
serveFile(java.lang.String uriIn,
java.util.Properties header,
java.io.File homeDir,
boolean allowDirectoryListing)
Serves file from homeDir and its' subdirectories (only).
|
static void |
setEncoding(java.lang.String encoding) |
void |
stop()
Stops the server.
|
public static final java.lang.String HTTP_OK
public static final java.lang.String HTTP_REDIRECT
public static final java.lang.String HTTP_FORBIDDEN
public static final java.lang.String HTTP_NOTFOUND
public static final java.lang.String HTTP_BADREQUEST
public static final java.lang.String HTTP_INTERNALERROR
public static final java.lang.String HTTP_NOTIMPLEMENTED
public static final java.lang.String MIME_PLAINTEXT
public static final java.lang.String MIME_HTML
public static final java.lang.String MIME_JSON
public static final java.lang.String MIME_DEFAULT_BINARY
public NanoHTTPD(int port)
throws java.io.IOException
port - The port to listen for HTTP connectionsjava.io.IOException - if the socket is already in usepublic NanoHTTPD(int port,
java.net.InetAddress bindHost)
throws java.io.IOException
port - The port to listen for HTTP connectionsbindHost - If non-null, the hostanme/address to bind to.java.io.IOException - if the socket is already in usepublic NanoHTTPD(int port,
java.net.InetAddress bindHost,
int sessionTimeout)
throws java.io.IOException
port - The port to listen for HTTP connectionsbindHost - If non-null, the hostanme/address to bind to.sessionTimeout - Timeout in milliseconds after which reading from the HTTP client side is terminated
with a timeout-error.java.io.IOException - if the socket is already in usepublic static void setEncoding(java.lang.String encoding)
public NanoHTTPD.Response serve(java.lang.String uri, java.lang.String method, java.util.Properties header, java.util.Properties parms)
(By default, this delegates to serveFile() and allows directory listing.)
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.header - Header entries, percent decodedpublic void stop()
public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOExceptionpublic NanoHTTPD.Response serveFile(java.lang.String uriIn, java.util.Properties header, java.io.File homeDir, boolean allowDirectoryListing)