Package fi.iki.elonen

Class NanoHTTPD.Response

java.lang.Object
fi.iki.elonen.NanoHTTPD.Response
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
InternalRewrite
Enclosing class:
NanoHTTPD

public static class NanoHTTPD.Response extends Object implements Closeable
HTTP response. Return one of these from serve().
  • Field Details

    • status

      HTTP status code after processing, e.g. "200 OK", Status.OK
    • mimeType

      private String mimeType
      MIME type of content, e.g. "text/html"
    • data

      private InputStream data
      Data of the response, may be null.
    • contentLength

      private long contentLength
    • lowerCaseHeader

      private final Map<String,String> lowerCaseHeader
      copy of the header map with all the keys lowercase for faster searching.
    • requestMethod

      private NanoHTTPD.Method requestMethod
      The request method that spawned this response.
    • chunkedTransfer

      private boolean chunkedTransfer
      Use chunkedTransfer
    • encodeAsGzip

      private boolean encodeAsGzip
    • keepAlive

      private boolean keepAlive
  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • addHeader

      public void addHeader(String name, String value)
      Adds given line to the header.
    • closeConnection

      public void closeConnection(boolean close)
      Indicate to close the connection after the Response has been sent.
      Parameters:
      close - true to hint connection closing, false to let connection be closed by client.
    • isCloseConnection

      public boolean isCloseConnection()
      Returns:
      true if connection is to be closed after this Response has been sent.
    • getData

      public InputStream getData()
    • getHeader

      public String getHeader(String name)
    • getMimeType

      public String getMimeType()
    • getRequestMethod

      public NanoHTTPD.Method getRequestMethod()
    • getStatus

      public NanoHTTPD.Response.IStatus getStatus()
    • setGzipEncoding

      public void setGzipEncoding(boolean encodeAsGzip)
    • setKeepAlive

      public void setKeepAlive(boolean useKeepAlive)
    • send

      protected void send(OutputStream outputStream)
      Sends given response to the socket.
    • printHeader

      protected void printHeader(PrintWriter pw, String key, String value)
    • sendContentLengthHeaderIfNotAlreadyPresent

      protected long sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw, long defaultSize)
    • sendBodyWithCorrectTransferAndEncoding

      private void sendBodyWithCorrectTransferAndEncoding(OutputStream outputStream, long pending) throws IOException
      Throws:
      IOException
    • sendBodyWithCorrectEncoding

      private void sendBodyWithCorrectEncoding(OutputStream outputStream, long pending) throws IOException
      Throws:
      IOException
    • sendBody

      private void sendBody(OutputStream outputStream, long pending) throws IOException
      Sends the body to the specified OutputStream. The pending parameter limits the maximum amounts of bytes sent unless it is -1, in which case everything is sent.
      Parameters:
      outputStream - the OutputStream to send data to
      pending - -1 to send everything, otherwise sets a max limit to the number of bytes sent
      Throws:
      IOException - if something goes wrong while sending the data.
    • setChunkedTransfer

      public void setChunkedTransfer(boolean chunkedTransfer)
    • setData

      public void setData(InputStream data)
    • setMimeType

      public void setMimeType(String mimeType)
    • setRequestMethod

      public void setRequestMethod(NanoHTTPD.Method requestMethod)
    • setStatus

      public void setStatus(NanoHTTPD.Response.IStatus status)