Clone this repo:
  1. a649e26 DO NOT MERGE - Merge pi-dev@5234907 into stage-aosp-master by Xin Li · 6 months ago master android-o-mr1-iot-release-1.0.13 android-o-mr1-iot-release-1.0.14
  2. 0acbaee Convert file to Android.bp am: 34424f0c17 am: 06459d67bb by Sasha Smundak · 7 months ago
  3. 06459d6 Convert file to Android.bp am: 34424f0c17 by Sasha Smundak · 7 months ago
  4. 34424f0 Convert file to Android.bp by Sasha Smundak · 7 months ago oreo-mr1-iot-release android-o-mr1-iot-release-1.0.10 android-o-mr1-iot-release-1.0.12 android-q-preview-1 android-q-preview-2.5 android-q-preview-4 android-q-preview-5 android-q-preview-6
  5. c6783c3 Integrate upstream changes to 2.2.0. am: f47b11cc8e by Daniel Erat · 3 years, 8 months ago master-cuttlefish-testing-release n-iot-preview-4 nougat-cts-release nougat-dev nougat-dr1-release nougat-iot-release nougat-mr0.5-release nougat-mr1-cts-release nougat-mr1-dev nougat-mr1-flounder-release nougat-mr1-release nougat-mr1-security-release nougat-mr1-volantis-release nougat-mr1.1-release nougat-mr1.2-release nougat-mr1.3-release nougat-mr1.4-release nougat-mr1.5-release nougat-mr1.6-release nougat-mr1.7-release nougat-mr1.8-release nougat-mr2-dev nougat-mr2-pixel-release nougat-mr2-release nougat-mr2-security-release nougat-mr2.1-release nougat-mr2.2-release nougat-mr2.3-release nougat-release o-iot-preview-5 o-mr1-iot-preview-6 o-mr1-iot-preview-7 o-mr1-iot-preview-8 o-preview oreo-cts-release oreo-dev oreo-dr1-dev oreo-dr1-release oreo-dr2-release oreo-dr3-release oreo-m2-release oreo-m2-s1-release oreo-m2-s2-release oreo-m2-s3-release oreo-m2-s4-release oreo-m2-s5-release oreo-m3-release oreo-m4-s1-release oreo-m4-s10-release oreo-m4-s11-release oreo-m4-s12-release oreo-m4-s2-release oreo-m4-s3-release oreo-m4-s4-release oreo-m4-s5-release oreo-m4-s6-release oreo-m4-s7-release oreo-m4-s8-release oreo-m4-s9-release oreo-m5-release oreo-m6-s2-release oreo-m6-s3-release oreo-m6-s4-release oreo-m7-release oreo-m8-release oreo-mr1-1.2-iot-release oreo-mr1-cts-release oreo-mr1-cuttlefish-testing oreo-mr1-dev oreo-mr1-release oreo-mr1-s1-release oreo-mr1-security-release oreo-mr1-vts-release oreo-mr1-wear-release oreo-r2-release oreo-r3-release oreo-r4-release oreo-r5-release oreo-r6-release oreo-release oreo-security-release oreo-vts-release pie-b4s4-dev pie-b4s4-release pie-cts-release pie-cuttlefish-testing pie-dev pie-dr1-dev pie-dr1-release pie-gsi pie-platform-release pie-qpr1-release pie-qpr1-s1-release pie-qpr1-s2-release pie-qpr1-s3-release pie-qpr2-release pie-qpr3-b-release pie-qpr3-release pie-qpr3-s1-release pie-r2-release pie-r2-s1-release pie-r2-s2-release pie-release pie-release-2 pie-s2-release pie-vts-release android-7.0.0_r1 android-7.0.0_r12 android-7.0.0_r13 android-7.0.0_r14 android-7.0.0_r15 android-7.0.0_r17 android-7.0.0_r19 android-7.0.0_r21 android-7.0.0_r24 android-7.0.0_r27 android-7.0.0_r28 android-7.0.0_r29 android-7.0.0_r3 android-7.0.0_r30 android-7.0.0_r31 android-7.0.0_r32 android-7.0.0_r33 android-7.0.0_r34 android-7.0.0_r35 android-7.0.0_r36 android-7.0.0_r4 android-7.0.0_r5 android-7.0.0_r6 android-7.0.0_r7 android-7.1.0_r1 android-7.1.0_r2 android-7.1.0_r3 android-7.1.0_r4 android-7.1.0_r5 android-7.1.0_r6 android-7.1.0_r7 android-7.1.1_r1 android-7.1.1_r10 android-7.1.1_r11 android-7.1.1_r12 android-7.1.1_r13 android-7.1.1_r14 android-7.1.1_r15 android-7.1.1_r16 android-7.1.1_r17 android-7.1.1_r2 android-7.1.1_r20 android-7.1.1_r21 android-7.1.1_r22 android-7.1.1_r23 android-7.1.1_r24 android-7.1.1_r25 android-7.1.1_r26 android-7.1.1_r27 android-7.1.1_r28 android-7.1.1_r3 android-7.1.1_r31 android-7.1.1_r32 android-7.1.1_r33 android-7.1.1_r35 android-7.1.1_r38 android-7.1.1_r39 android-7.1.1_r4 android-7.1.1_r40 android-7.1.1_r41 android-7.1.1_r42 android-7.1.1_r43 android-7.1.1_r44 android-7.1.1_r45 android-7.1.1_r46 android-7.1.1_r47 android-7.1.1_r48 android-7.1.1_r49 android-7.1.1_r50 android-7.1.1_r51 android-7.1.1_r52 android-7.1.1_r53 android-7.1.1_r54 android-7.1.1_r55 android-7.1.1_r56 android-7.1.1_r57 android-7.1.1_r58 android-7.1.1_r59 android-7.1.1_r6 android-7.1.1_r7 android-7.1.1_r8 android-7.1.1_r9 android-7.1.2_r1 android-7.1.2_r10 android-7.1.2_r11 android-7.1.2_r12 android-7.1.2_r13 android-7.1.2_r14 android-7.1.2_r15 android-7.1.2_r16 android-7.1.2_r17 android-7.1.2_r18 android-7.1.2_r19 android-7.1.2_r2 android-7.1.2_r23 android-7.1.2_r24 android-7.1.2_r25 android-7.1.2_r27 android-7.1.2_r28 android-7.1.2_r29 android-7.1.2_r3 android-7.1.2_r30 android-7.1.2_r32 android-7.1.2_r33 android-7.1.2_r36 android-7.1.2_r37 android-7.1.2_r4 android-7.1.2_r5 android-7.1.2_r6 android-7.1.2_r8 android-7.1.2_r9 android-8.0.0_r1 android-8.0.0_r10 android-8.0.0_r11 android-8.0.0_r12 android-8.0.0_r13 android-8.0.0_r15 android-8.0.0_r16 android-8.0.0_r17 android-8.0.0_r2 android-8.0.0_r21 android-8.0.0_r22 android-8.0.0_r23 android-8.0.0_r24 android-8.0.0_r25 android-8.0.0_r26 android-8.0.0_r27 android-8.0.0_r28 android-8.0.0_r29 android-8.0.0_r3 android-8.0.0_r30 android-8.0.0_r31 android-8.0.0_r32 android-8.0.0_r33 android-8.0.0_r34 android-8.0.0_r35 android-8.0.0_r36 android-8.0.0_r37 android-8.0.0_r4 android-8.0.0_r7 android-8.0.0_r9 android-8.1.0_r1 android-8.1.0_r10 android-8.1.0_r11 android-8.1.0_r12 android-8.1.0_r13 android-8.1.0_r14 android-8.1.0_r15 android-8.1.0_r16 android-8.1.0_r17 android-8.1.0_r18 android-8.1.0_r19 android-8.1.0_r2 android-8.1.0_r20 android-8.1.0_r21 android-8.1.0_r22 android-8.1.0_r23 android-8.1.0_r25 android-8.1.0_r26 android-8.1.0_r27 android-8.1.0_r28 android-8.1.0_r29 android-8.1.0_r3 android-8.1.0_r30 android-8.1.0_r31 android-8.1.0_r32 android-8.1.0_r33 android-8.1.0_r35 android-8.1.0_r36 android-8.1.0_r37 android-8.1.0_r38 android-8.1.0_r39 android-8.1.0_r4 android-8.1.0_r40 android-8.1.0_r41 android-8.1.0_r42 android-8.1.0_r43 android-8.1.0_r45 android-8.1.0_r46 android-8.1.0_r47 android-8.1.0_r48 android-8.1.0_r5 android-8.1.0_r50 android-8.1.0_r51 android-8.1.0_r52 android-8.1.0_r53 android-8.1.0_r6 android-8.1.0_r60 android-8.1.0_r61 android-8.1.0_r62 android-8.1.0_r63 android-8.1.0_r64 android-8.1.0_r65 android-8.1.0_r66 android-8.1.0_r67 android-8.1.0_r7 android-8.1.0_r8 android-8.1.0_r9 android-9.0.0_r1 android-9.0.0_r10 android-9.0.0_r11 android-9.0.0_r12 android-9.0.0_r16 android-9.0.0_r17 android-9.0.0_r18 android-9.0.0_r19 android-9.0.0_r2 android-9.0.0_r20 android-9.0.0_r21 android-9.0.0_r22 android-9.0.0_r3 android-9.0.0_r30 android-9.0.0_r31 android-9.0.0_r32 android-9.0.0_r33 android-9.0.0_r34 android-9.0.0_r35 android-9.0.0_r36 android-9.0.0_r37 android-9.0.0_r38 android-9.0.0_r39 android-9.0.0_r40 android-9.0.0_r41 android-9.0.0_r42 android-9.0.0_r43 android-9.0.0_r44 android-9.0.0_r45 android-9.0.0_r46 android-9.0.0_r47 android-9.0.0_r5 android-9.0.0_r6 android-9.0.0_r7 android-9.0.0_r8 android-9.0.0_r9 android-cts-7.0_r1 android-cts-7.0_r10 android-cts-7.0_r11 android-cts-7.0_r12 android-cts-7.0_r13 android-cts-7.0_r14 android-cts-7.0_r15 android-cts-7.0_r16 android-cts-7.0_r17 android-cts-7.0_r18 android-cts-7.0_r19 android-cts-7.0_r2 android-cts-7.0_r20 android-cts-7.0_r21 android-cts-7.0_r22 android-cts-7.0_r23 android-cts-7.0_r24 android-cts-7.0_r25 android-cts-7.0_r26 android-cts-7.0_r27 android-cts-7.0_r28 android-cts-7.0_r29 android-cts-7.0_r3 android-cts-7.0_r30 android-cts-7.0_r31 android-cts-7.0_r32 android-cts-7.0_r4 android-cts-7.0_r5 android-cts-7.0_r6 android-cts-7.0_r7 android-cts-7.0_r8 android-cts-7.0_r9 android-cts-7.1_r1 android-cts-7.1_r10 android-cts-7.1_r11 android-cts-7.1_r12 android-cts-7.1_r13 android-cts-7.1_r14 android-cts-7.1_r15 android-cts-7.1_r16 android-cts-7.1_r17 android-cts-7.1_r18 android-cts-7.1_r19 android-cts-7.1_r2 android-cts-7.1_r20 android-cts-7.1_r21 android-cts-7.1_r22 android-cts-7.1_r23 android-cts-7.1_r24 android-cts-7.1_r25 android-cts-7.1_r26 android-cts-7.1_r27 android-cts-7.1_r28 android-cts-7.1_r3 android-cts-7.1_r4 android-cts-7.1_r5 android-cts-7.1_r6 android-cts-7.1_r7 android-cts-7.1_r8 android-cts-7.1_r9 android-cts-8.0_r1 android-cts-8.0_r10 android-cts-8.0_r11 android-cts-8.0_r12 android-cts-8.0_r13 android-cts-8.0_r14 android-cts-8.0_r15 android-cts-8.0_r16 android-cts-8.0_r17 android-cts-8.0_r18 android-cts-8.0_r19 android-cts-8.0_r2 android-cts-8.0_r20 android-cts-8.0_r3 android-cts-8.0_r4 android-cts-8.0_r5 android-cts-8.0_r6 android-cts-8.0_r7 android-cts-8.0_r8 android-cts-8.0_r9 android-cts-8.1_r1 android-cts-8.1_r10 android-cts-8.1_r11 android-cts-8.1_r12 android-cts-8.1_r13 android-cts-8.1_r14 android-cts-8.1_r15 android-cts-8.1_r16 android-cts-8.1_r2 android-cts-8.1_r3 android-cts-8.1_r4 android-cts-8.1_r5 android-cts-8.1_r6 android-cts-8.1_r7 android-cts-8.1_r8 android-cts-8.1_r9 android-cts-9.0_r1 android-cts-9.0_r2 android-cts-9.0_r3 android-cts-9.0_r4 android-cts-9.0_r5 android-cts-9.0_r6 android-cts-9.0_r7 android-cts-9.0_r8 android-cts-9.0_r9 android-n-iot-preview-4 android-n-iot-release-ihome-igv1 android-n-iot-release-lg-thinq-wk7 android-n-iot-release-polk-at1 android-n-iot-release-smart-display android-n-iot-release-smart-display-r2 android-n-mr1-preview-1 android-n-mr1-preview-2 android-n-mr2-preview-1 android-n-mr2-preview-2 android-o-iot-preview-5 android-o-mr1-iot-preview-6 android-o-mr1-iot-preview-7 android-o-mr1-iot-preview-8 android-o-mr1-iot-release-1.0.0 android-o-mr1-iot-release-1.0.1 android-o-mr1-iot-release-1.0.2 android-o-mr1-iot-release-1.0.3 android-o-mr1-iot-release-1.0.4 android-o-mr1-iot-release-1.0.5 android-o-mr1-iot-release-1.0.7 android-o-mr1-iot-release-1.0.8 android-o-mr1-iot-release-cube-fcs android-o-mr1-iot-release-cube-fsi android-o-mr1-iot-release-cube_r2 android-o-mr1-iot-release-smart-display-r3 android-o-mr1-iot-release-smart-display-r4 android-o-mr1-iot-release-smart-display-r5 android-o-mr1-iot-release-smart-display-r8 android-o-mr1-iot-release-smart-display-r9 android-o-mr1-preview-1 android-o-mr1-preview-2 android-o-preview-1 android-o-preview-2 android-o-preview-3 android-o-preview-4 android-p-preview-1 android-p-preview-2 android-p-preview-3 android-p-preview-4 android-p-preview-5 android-vts-8.0_r1 android-vts-8.0_r10 android-vts-8.0_r11 android-vts-8.0_r12 android-vts-8.0_r2 android-vts-8.0_r6 android-vts-8.0_r7 android-vts-8.0_r8 android-vts-8.0_r9 android-vts-8.1_r3 android-vts-8.1_r4 android-vts-8.1_r5 android-vts-8.1_r6 android-vts-8.1_r7 android-vts-8.1_r8 android-vts-8.1_r9 android-vts-9.0_r10 android-vts-9.0_r4 android-vts-9.0_r5 android-vts-9.0_r6 android-vts-9.0_r7 android-vts-9.0_r8 android-vts-9.0_r9 android-wear-8.0.0_r1 android-wear-8.0.0_r2 android-wear-8.1.0_r1 android-wear-9.0.0_r1 android-wear-9.0.0_r2 android-wear-9.0.0_r3 android-wear-9.0.0_r4 android-wear-9.0.0_r5 android-wear-o-preview-3 android-wear-o-preview-4 android-wear-p-preview-2

NanoHTTPD – a tiny web server in Java

NanoHTTPD is a light-weight HTTP server designed for embedding in other applications, released under a Modified BSD licence.

It is being developed at Github and uses Apache Maven for builds & unit testing:

  • Build status: Build Status
  • Coverage Status: Coverage Status
  • Current central released version: Maven Central


We'll create a custom HTTP server project using Maven for build/dep system. This tutorial assumes you are using a Unix variant and a shell. First, install Maven and Java SDK if not already installed. Then run:

mvn compile
mvn exec:java -pl webserver -Dexec.mainClass="fi.iki.elonen.SimpleWebServer"

You should now have a HTTP file server running on http://localhost:8080/.

Custom web app

Let's raise the bar and build a custom web application next:

mvn archetype:generate -DgroupId=com.example -DartifactId=myHellopApp -DinteractiveMode=false
cd myHellopApp

Edit pom.xml, and add this between <dependencies>:

	<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->

Edit src/main/java/com/example/ and replace it with:

package com.example;

import java.util.Map;
import fi.iki.elonen.NanoHTTPD;

public class App extends NanoHTTPD {

    public App() throws IOException {
		System.out.println( "\nRunning! Point your browers to http://localhost:8080/ \n" );

    public static void main(String[] args) {
		try {
		    new App();
		catch( IOException ioe ) {
			System.err.println( "Couldn't start server:\n" + ioe );

    public Response serve(IHTTPSession session) {
        String msg = "<html><body><h1>Hello server</h1>\n";
        Map<String, String> parms = session.getParms();
        if (parms.get("username") == null) {
            msg += "<form action='?' method='get'>\n  <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
        } else {
            msg += "<p>Hello, " + parms.get("username") + "!</p>";
        return newFixedLengthResponse( msg + "</body></html>\n" );

Compile and run the server:

mvn compile
mvn exec:java -Dexec.mainClass="com.example.App"

If it started ok, point your browser at http://localhost:8080/ and enjoy a web server that asks your name and replies with a greeting.


Nanolets are like sevlet's only that they have a extrem low profile. They offer an easy to use system for a more complex server application. This text has to be extrended with an example, so for now take a look at the unit tests for the usage.


We are currently in the process of stabilizing NanoHttpd from the many pull requests and feature requests that were integrated over the last few months. The next release will come soon, and there will not be any more “intended” major changes before the next release. If you want to use the bleeding edge version, you can clone it from Github, or get it from (see “Maven dependencies / Living on the edge” below).

Project structure

NanoHTTPD project currently consist of four parts:

  • /core – Fully functional HTTP(s) server consisting of one (1) Java file, ready to be customized/inherited for your own project

  • /samples – Simple examples on how to customize NanoHTTPD. See for a killer app that greets you enthusiastically!

  • /websocket – Websocket implementation, also in a single Java file. Depends on core.

  • /webserver – Standalone file server. Run & enjoy. A popular use seems to be serving files out off an Android device.

  • /nanolets – Standalone nano app server, giving a servlet like system to the implementor.

  • /fileupload – integration of the apache common file upload library.



  • Only one Java file, providing HTTP 1.1 support.
  • No fixed config files, logging, authorization etc. (Implement by yourself if you need them. Errors are passed to java.util.logging, though.)
  • Support for HTTPS (SSL)
  • Basic support for cookies
  • Supports parameter parsing of GET and POST methods.
  • Some built-in support for HEAD, POST and DELETE requests. You can easily implement/customize any HTTP method, though.
  • Supports file upload. Uses memory for small uploads, temp files for large ones.
  • Never caches anything.
  • Does not limit bandwidth, request time or simultaneous connections by default.
  • All header names are converted to lower case so they don't vary between browsers/clients.
  • Persistent connections (Connection “keep-alive”) support allowing multiple requests to be served over a single socket connection.


  • Tested on Firefox, Chrome and IE.


  • Default code serves files and shows (prints on console) all HTTP parameters and headers.
  • Supports both dynamic content and file serving.
  • File server supports directory listing, index.html and index.htm.
  • File server supports partial content (streaming & continue download).
  • File server supports ETags.
  • File server does the 301 redirection trick for directories without /.
  • File server serves also very long files without memory overhead.
  • Contains a built-in list of most common MIME types.
  • Runtime extension support (extensions that serve particular MIME types) - example extension that serves Markdown formatted files. Simply including an extension JAR in the webserver classpath is enough for the extension to be loaded.
  • Simple CORS support via --cors paramater
    • by default serves Access-Control-Allow-Headers: origin,accept,content-type
    • possibility to set Access-Control-Allow-Headers by setting System property: AccessControlAllowHeader
    • _example: _ -DAccessControlAllowHeader=origin,accept,content-type,Authorization
    • possible values:
      • --cors: activates CORS support, Access-Control-Allow-Origin will be set to *
      • --cors=some_value: Access-Control-Allow-Origin will be set to some_value.

CORS argument examples

  • --cors=
  • --cors=",": note the double quotes so that the 2 URLs are considered part of a single argument.

Maven dependencies

NanoHTTPD is a Maven based project and deployed to central. Most development environments have means to access the central repository. The coordinates to use in Maven are:

		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->

(Replace CURRENT_VERSION with whatever is reported latest at

The coordinates for your development environment should correspond to these. When looking for an older version take care because we switched groupId from com.nanohttpd to org.nanohttpd in mid 2015.

Next it depends what you are useing nanohttpd for, there are tree main usages.

Gradle dependencies

In gradle you can use nano http the same way because gradle accesses the same central repository:

dependencies {
		[group: 'org.nanohttpd', name: 'nanohttpd', version: 'CURRENT_VERSION'],

(Replace CURRENT_VERSION with whatever is reported latest at

Just replace the name with the artifact id of the module you want to use and gradle will find it for you.

Develop your own specialized HTTP service

For a specialized HTTP (HTTPS) service you can use the module with artifactId nanohttpd.

		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->

Here you write your own subclass of fi.iki.elonen.NanoHTTPD to configure and to serve the requests.

Develop a websocket based service

For a specialized websocket service you can use the module with artifactId nanohttpd-websocket.

		<groupId>org.nanohttpd</groupId> <!-- <groupId>com.nanohttpd</groupId> for 2.1.0 and earlier -->

Here you write your own subclass of fi.iki.elonen.NanoWebSocketServer to configure and to serve the websocket requests. A small standard echo example is included as fi.iki.elonen.samples.echo.DebugWebSocketServer. You can use it as a starting point to implement your own services.

Develop a custom HTTP file server

For a more classic aproach, perhaps to just create a HTTP server serving mostly service files from your disk, you can use the module with artifactId nanohttpd-webserver.


The included class fi.iki.elonen.SimpleWebServer is intended to be used as a starting point for your own implementation but it also can be used as is. Staring the class as is will start a http server on port 8080 and publishing the current directory.

Living on the edge

The latest Github master version can be fetched through


generating an self signed ssl certificate

Just a hint how to generate a certificate for localhost.

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048 -ext SAN=DNS:localhost,IP:  -validity 9999

This will generate a keystore file named ‘keystore.jks’ with a self signed certificate for a host named localhost with the ip adress . Now you can use:

server.makeSecure(NanoHTTPD.makeSSLSocketFactory("/keystore.jks", "password".toCharArray()));

Before you start the server to make Nanohttpd serve https connections, when you make sure ‘keystore.jks’ is in your classpath .

Thank you to everyone who has reported bugs and suggested fixes.