public class NanoHTTPd extends Object
NanoHTTPd version 1.22, Copyright © 2001,2005-2011 Jarno Elonen (elonen@iki.fi, http://iki.fi/elonen/) and Copyright © 2010 Konstantinos Togias (info@ktogias.gr, http://ktogias.gr)
Minimally modified to support subclassing and to bind server socket to the loopback interface, 2013 Benjamin Nanes
Features + limitations:
Ways to use:
See the end of the source file for distribution license (Modified BSD licence)
Modifier and Type | Class and Description |
---|---|
private class |
NanoHTTPd.HTTPSession
Handles one session, i.e.
|
class |
NanoHTTPd.Response
HTTP response.
|
Modifier and Type | Field and Description |
---|---|
private static SimpleDateFormat |
gmtFrmt
GMT date formatter
|
static String |
HTTP_BADREQUEST
Some HTTP response status codes
|
static String |
HTTP_FORBIDDEN
Some HTTP response status codes
|
static String |
HTTP_INTERNALERROR
Some HTTP response status codes
|
static String |
HTTP_NOTFOUND
Some HTTP response status codes
|
static String |
HTTP_NOTIMPLEMENTED
Some HTTP response status codes
|
static String |
HTTP_OK
Some HTTP response status codes
|
static String |
HTTP_REDIRECT
Some HTTP response status codes
|
private static byte[] |
lh |
private static String |
LICENCE
The distribution licence
|
static String |
MIME_DEFAULT_BINARY
Common mime types for dynamic content
|
static String |
MIME_HTML
Common mime types for dynamic content
|
static String |
MIME_PLAINTEXT
Common mime types for dynamic content
|
static String |
MIME_XML
Common mime types for dynamic content
|
protected ServerSocket |
myServerSocket |
private int |
myTcpPort |
private Thread |
myThread |
protected static Hashtable |
theMimeTypes
Hashtable mapping (String)FILENAME_EXTENSION to (String)MIME_TYPE
BN: Changed from 'private' to 'protected'
|
Constructor and Description |
---|
NanoHTTPd(int port)
Starts a HTTP server to given port.
|
Modifier and Type | Method and Description |
---|---|
private String |
encodeUri(String uri)
URL-encodes everything between "/"-characters.
|
NanoHTTPd.Response |
serve(String uri,
String method,
Properties header,
Properties parms,
Properties files)
Override this to customize the server.
|
NanoHTTPd.Response |
serveFile(String uri,
Properties header,
File homeDir,
boolean allowDirectoryListing)
Serves file from homeDir and its' subdirectories (only).
|
void |
stop()
Stops the server.
|
public static final String HTTP_OK
public static final String HTTP_REDIRECT
public static final String HTTP_FORBIDDEN
public static final String HTTP_NOTFOUND
public static final String HTTP_BADREQUEST
public static final String HTTP_INTERNALERROR
public static final String HTTP_NOTIMPLEMENTED
public static final String MIME_PLAINTEXT
public static final String MIME_HTML
public static final String MIME_DEFAULT_BINARY
public static final String MIME_XML
private static byte[] lh
private int myTcpPort
protected final ServerSocket myServerSocket
private Thread myThread
protected static Hashtable theMimeTypes
private static SimpleDateFormat gmtFrmt
private static final String LICENCE
public NanoHTTPd(int port) throws IOException
Throws an IOException if the socket is already in use
IOException
public NanoHTTPd.Response serve(String uri, String method, Properties header, Properties parms, Properties files)
(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()
private String encodeUri(String uri)
public NanoHTTPd.Response serveFile(String uri, Properties header, File homeDir, boolean allowDirectoryListing)
Copyright © 2023. All rights reserved.