AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.util.NanoHTTPD Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.util.NanoHTTPD:
com.google.appinventor.components.runtime.util.AppInvHTTPD

Classes

class  Response
 

Public Member Functions

Response serve (String uri, String method, Properties header, Properties parms, Properties files, Socket mySocket)
 
 NanoHTTPD (int port, File wwwroot) throws IOException
 
void stop ()
 
Response serveFile (String uri, Properties header, File homeDir, boolean allowDirectoryListing)
 

Static Public Member Functions

static void main (String[] args)
 

Static Public Attributes

static final String HTTP_OK = "200 OK"
 
static final String MIME_PLAINTEXT = "text/plain"
 

Static Protected Attributes

static PrintStream myOut = System.out
 
static PrintStream myErr = System.err
 

Detailed Description

A simple, tiny, nicely embeddable HTTP 1.0 (partially 1.1) server in Java

NanoHTTPD version 1.25, Copyright © 2001,2005-2012 Jarno Elonen (elone.nosp@m.n@ik.nosp@m.i.fi, http://iki.fi/elonen/) and Copyright © 2010 Konstantinos Togias (info@.nosp@m.ktog.nosp@m.ias.g.nosp@m.r, http://ktogias.gr)

Improvements in Thread Handling (pooling) by Jeffrey I. Schiller (jis@m.nosp@m.it.e.nosp@m.du)

Features + limitations:

  • Only one Java file
  • Java 1.1 compatible
  • Released as open source, Modified BSD licence
  • No fixed config files, logging, authorization etc. (Implement yourself if you need them.)
  • Supports parameter parsing of GET and POST methods (+ rudimentary PUT support in 1.25)
  • Supports both dynamic content and file serving
  • Supports file upload (since version 1.2, 2010)
  • Supports partial content (streaming)
  • Supports ETags
  • Never caches anything
  • Doesn't limit bandwidth, request time or simultaneous connections
  • Default code serves files and shows all HTTP parameters and headers
  • File server supports directory listing, index.html and index.htm
  • File server supports partial content (streaming)
  • File server supports ETags
  • File server does the 301 redirection trick for directories without '/'
  • File server supports simple skipping for files (continue download)
  • File server serves also very long files without memory overhead
  • Contains a built-in list of most common mime types
  • All header names are converted lowercase so they don't vary between browsers/clients

Ways to use:

  • Run as a standalone app, serves files and shows requests
  • Subclass serve() and embed to your own program
  • Call serveFile() from serve() with your own base directory

See the end of the source file for distribution license (Modified BSD licence)

Definition at line 82 of file NanoHTTPD.java.

Constructor & Destructor Documentation

◆ NanoHTTPD()

com.google.appinventor.components.runtime.util.NanoHTTPD.NanoHTTPD ( int  port,
File  wwwroot 
) throws IOException

Starts a HTTP server to given port.

Throws an IOException if the socket is already in use

Definition at line 240 of file NanoHTTPD.java.

Member Function Documentation

◆ main()

static void com.google.appinventor.components.runtime.util.NanoHTTPD.main ( String[]  args)
static

Starts as a standalone file server and waits for Enter.

Definition at line 280 of file NanoHTTPD.java.

◆ serve()

Response com.google.appinventor.components.runtime.util.NanoHTTPD.serve ( String  uri,
String  method,
Properties  header,
Properties  parms,
Properties  files,
Socket  mySocket 
)

Override this to customize the server.

(By default, this delegates to serveFile() and allows directory listing.)

Parameters
uriPercent-decoded URI without parameters, for example "/index.cgi"
method"GET", "POST" etc.
parmsParsed, percent decoded parameters from URI and, in case of POST, data.
headerHeader entries, percent decoded
Returns
HTTP response, see class Response for details

Reimplemented in com.google.appinventor.components.runtime.util.AppInvHTTPD.

Definition at line 104 of file NanoHTTPD.java.

◆ serveFile()

Response com.google.appinventor.components.runtime.util.NanoHTTPD.serveFile ( String  uri,
Properties  header,
File  homeDir,
boolean  allowDirectoryListing 
)

Serves file from homeDir and its' subdirectories (only). Uses only URI, ignores all headers and HTTP parameters.

Definition at line 895 of file NanoHTTPD.java.

◆ stop()

void com.google.appinventor.components.runtime.util.NanoHTTPD.stop ( )

Stops the server.

Definition at line 265 of file NanoHTTPD.java.

Member Data Documentation

◆ HTTP_OK

final String com.google.appinventor.components.runtime.util.NanoHTTPD.HTTP_OK = "200 OK"
static

Some HTTP response status codes

Definition at line 209 of file NanoHTTPD.java.

◆ MIME_PLAINTEXT

final String com.google.appinventor.components.runtime.util.NanoHTTPD.MIME_PLAINTEXT = "text/plain"
static

Common mime types for dynamic content

Definition at line 224 of file NanoHTTPD.java.

◆ myErr

PrintStream com.google.appinventor.components.runtime.util.NanoHTTPD.myErr = System.err
staticprotected

Definition at line 1128 of file NanoHTTPD.java.

◆ myOut

PrintStream com.google.appinventor.components.runtime.util.NanoHTTPD.myOut = System.out
staticprotected

Definition at line 1127 of file NanoHTTPD.java.


The documentation for this class was generated from the following file: