private void sendResponse(String status, String mime, Properties header, InputStream data) {
      try {
        if (status == null) throw new Error("sendResponse(): Status can't be null.");

        OutputStream out = mySocket.getOutputStream();
        PrintWriter pw = new PrintWriter(out);
        pw.print("HTTP/1.0 " + status + " \r\n");

        if (mime != null) pw.print("Content-Type: " + mime + "\r\n");

        if (header == null || header.getProperty("Date") == null)
          pw.print("Date: " + gmtFrmt.format(new Date()) + "\r\n");

        if (header != null) {
          Enumeration e = header.keys();
          while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String value = header.getProperty(key);
            pw.print(key + ": " + value + "\r\n");
          }
        }

        pw.print("\r\n");
        pw.flush();

        if (data != null) {
          int pending = data.available(); // This is to support partial sends, see serveFile()
          byte[] buff = new byte[theBufferSize];
          while (pending > 0) {
            int read = data.read(buff, 0, ((pending > theBufferSize) ? theBufferSize : pending));
            if (read <= 0) break;
            out.write(buff, 0, read);
            pending -= read;
          }
        }
        out.flush();
        out.close();
        if (data != null) data.close();
      } catch (IOException ioe) {
        // Couldn't write? No can do.
        try {
          mySocket.close();
        } catch (Throwable t) {}
      }
    }
Sends given response to the socket.
selendroid-test-app/src/main/java/io/selendroid/testapp/server/NanoHTTPD.java