Package fi.iki.elonen
Class NanoHTTPD.HTTPSession
- java.lang.Object
-
- fi.iki.elonen.NanoHTTPD.HTTPSession
-
- All Implemented Interfaces:
NanoHTTPD.IHTTPSession
- Enclosing class:
- NanoHTTPD
protected class NanoHTTPD.HTTPSession extends java.lang.Object implements NanoHTTPD.IHTTPSession
-
-
Field Summary
Fields Modifier and Type Field Description static int
BUFSIZE
private NanoHTTPD.CookieHandler
cookies
private java.util.Map<java.lang.String,java.lang.String>
headers
private java.io.BufferedInputStream
inputStream
static int
MAX_HEADER_SIZE
private static int
MEMORY_STORE_LIMIT
private NanoHTTPD.Method
method
private java.io.OutputStream
outputStream
private java.util.Map<java.lang.String,java.util.List<java.lang.String>>
parms
private java.lang.String
protocolVersion
private java.lang.String
queryParameterString
private java.lang.String
remoteHostname
private java.lang.String
remoteIp
private static int
REQUEST_BUFFER_LEN
private int
rlen
private int
splitbyte
private NanoHTTPD.TempFileManager
tempFileManager
private java.lang.String
uri
-
Constructor Summary
Constructors Constructor Description HTTPSession(NanoHTTPD.TempFileManager tempFileManager, java.io.InputStream inputStream, java.io.OutputStream outputStream)
HTTPSession(NanoHTTPD.TempFileManager tempFileManager, java.io.InputStream inputStream, java.io.OutputStream outputStream, java.net.InetAddress inetAddress)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
decodeHeader(java.io.BufferedReader in, java.util.Map<java.lang.String,java.lang.String> pre, java.util.Map<java.lang.String,java.util.List<java.lang.String>> parms, java.util.Map<java.lang.String,java.lang.String> headers)
Decodes the sent headers and loads the data into Key/value pairsprivate void
decodeMultipartFormData(NanoHTTPD.ContentType contentType, java.nio.ByteBuffer fbuf, java.util.Map<java.lang.String,java.util.List<java.lang.String>> parms, java.util.Map<java.lang.String,java.lang.String> files)
Decodes the Multipart Body data and put it into Key/Value pairs.private void
decodeParms(java.lang.String parms, java.util.Map<java.lang.String,java.util.List<java.lang.String>> p)
Decodes parameters in percent-encoded URI-format ( e.g.void
execute()
private int
findHeaderEnd(byte[] buf, int rlen)
Find byte index separating header from body.long
getBodySize()
Deduce body length in bytes.private int[]
getBoundaryPositions(java.nio.ByteBuffer b, byte[] boundary)
Find the byte positions where multipart boundaries start.NanoHTTPD.CookieHandler
getCookies()
java.util.Map<java.lang.String,java.lang.String>
getHeaders()
java.io.InputStream
getInputStream()
NanoHTTPD.Method
getMethod()
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getParameters()
java.util.Map<java.lang.String,java.lang.String>
getParms()
Deprecated.usegetParameters()
instead.java.lang.String
getQueryParameterString()
java.lang.String
getRemoteHostName()
Get the remote hostname of the requester.java.lang.String
getRemoteIpAddress()
Get the remote ip address of the requester.private java.io.RandomAccessFile
getTmpBucket()
java.lang.String
getUri()
void
parseBody(java.util.Map<java.lang.String,java.lang.String> files)
Adds the files in the request body to the files map.private java.lang.String
saveTmpFile(java.nio.ByteBuffer b, int offset, int len, java.lang.String filename_hint)
Retrieves the content of a sent file and saves it to a temporary file.private int
scipOverNewLine(byte[] partHeaderBuff, int index)
-
-
-
Field Detail
-
REQUEST_BUFFER_LEN
private static final int REQUEST_BUFFER_LEN
- See Also:
- Constant Field Values
-
MEMORY_STORE_LIMIT
private static final int MEMORY_STORE_LIMIT
- See Also:
- Constant Field Values
-
BUFSIZE
public static final int BUFSIZE
- See Also:
- Constant Field Values
-
MAX_HEADER_SIZE
public static final int MAX_HEADER_SIZE
- See Also:
- Constant Field Values
-
tempFileManager
private final NanoHTTPD.TempFileManager tempFileManager
-
outputStream
private final java.io.OutputStream outputStream
-
inputStream
private final java.io.BufferedInputStream inputStream
-
splitbyte
private int splitbyte
-
rlen
private int rlen
-
uri
private java.lang.String uri
-
method
private NanoHTTPD.Method method
-
parms
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> parms
-
headers
private java.util.Map<java.lang.String,java.lang.String> headers
-
cookies
private NanoHTTPD.CookieHandler cookies
-
queryParameterString
private java.lang.String queryParameterString
-
remoteIp
private java.lang.String remoteIp
-
remoteHostname
private java.lang.String remoteHostname
-
protocolVersion
private java.lang.String protocolVersion
-
-
Constructor Detail
-
HTTPSession
public HTTPSession(NanoHTTPD.TempFileManager tempFileManager, java.io.InputStream inputStream, java.io.OutputStream outputStream)
-
HTTPSession
public HTTPSession(NanoHTTPD.TempFileManager tempFileManager, java.io.InputStream inputStream, java.io.OutputStream outputStream, java.net.InetAddress inetAddress)
-
-
Method Detail
-
decodeHeader
private void decodeHeader(java.io.BufferedReader in, java.util.Map<java.lang.String,java.lang.String> pre, java.util.Map<java.lang.String,java.util.List<java.lang.String>> parms, java.util.Map<java.lang.String,java.lang.String> headers) throws NanoHTTPD.ResponseException
Decodes the sent headers and loads the data into Key/value pairs- Throws:
NanoHTTPD.ResponseException
-
decodeMultipartFormData
private void decodeMultipartFormData(NanoHTTPD.ContentType contentType, java.nio.ByteBuffer fbuf, java.util.Map<java.lang.String,java.util.List<java.lang.String>> parms, java.util.Map<java.lang.String,java.lang.String> files) throws NanoHTTPD.ResponseException
Decodes the Multipart Body data and put it into Key/Value pairs.- Throws:
NanoHTTPD.ResponseException
-
scipOverNewLine
private int scipOverNewLine(byte[] partHeaderBuff, int index)
-
decodeParms
private void decodeParms(java.lang.String parms, java.util.Map<java.lang.String,java.util.List<java.lang.String>> p)
Decodes parameters in percent-encoded URI-format ( e.g. "name=Jack%20Daniels&pass=Single%20Malt" ) and adds them to given Map.
-
execute
public void execute() throws java.io.IOException
- Specified by:
execute
in interfaceNanoHTTPD.IHTTPSession
- Throws:
java.io.IOException
-
findHeaderEnd
private int findHeaderEnd(byte[] buf, int rlen)
Find byte index separating header from body. It must be the last byte of the first two sequential new lines.
-
getBoundaryPositions
private int[] getBoundaryPositions(java.nio.ByteBuffer b, byte[] boundary)
Find the byte positions where multipart boundaries start. This reads a large block at a time and uses a temporary buffer to optimize (memory mapped) file access.
-
getCookies
public NanoHTTPD.CookieHandler getCookies()
- Specified by:
getCookies
in interfaceNanoHTTPD.IHTTPSession
-
getHeaders
public final java.util.Map<java.lang.String,java.lang.String> getHeaders()
- Specified by:
getHeaders
in interfaceNanoHTTPD.IHTTPSession
-
getInputStream
public final java.io.InputStream getInputStream()
- Specified by:
getInputStream
in interfaceNanoHTTPD.IHTTPSession
-
getMethod
public final NanoHTTPD.Method getMethod()
- Specified by:
getMethod
in interfaceNanoHTTPD.IHTTPSession
-
getParms
@Deprecated public final java.util.Map<java.lang.String,java.lang.String> getParms()
Deprecated.usegetParameters()
instead.Description copied from interface:NanoHTTPD.IHTTPSession
This method will only return the first value for a given parameter. You will want to use getParameters if you expect multiple values for a given key.- Specified by:
getParms
in interfaceNanoHTTPD.IHTTPSession
-
getParameters
public final java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParameters()
- Specified by:
getParameters
in interfaceNanoHTTPD.IHTTPSession
-
getQueryParameterString
public java.lang.String getQueryParameterString()
- Specified by:
getQueryParameterString
in interfaceNanoHTTPD.IHTTPSession
-
getTmpBucket
private java.io.RandomAccessFile getTmpBucket()
-
getUri
public final java.lang.String getUri()
- Specified by:
getUri
in interfaceNanoHTTPD.IHTTPSession
- Returns:
- the path part of the URL.
-
getBodySize
public long getBodySize()
Deduce body length in bytes. Either from "content-length" header or read bytes.
-
parseBody
public void parseBody(java.util.Map<java.lang.String,java.lang.String> files) throws java.io.IOException, NanoHTTPD.ResponseException
Description copied from interface:NanoHTTPD.IHTTPSession
Adds the files in the request body to the files map.- Specified by:
parseBody
in interfaceNanoHTTPD.IHTTPSession
- Parameters:
files
- map to modify- Throws:
java.io.IOException
NanoHTTPD.ResponseException
-
saveTmpFile
private java.lang.String saveTmpFile(java.nio.ByteBuffer b, int offset, int len, java.lang.String filename_hint)
Retrieves the content of a sent file and saves it to a temporary file. The full path to the saved file is returned.
-
getRemoteIpAddress
public java.lang.String getRemoteIpAddress()
Description copied from interface:NanoHTTPD.IHTTPSession
Get the remote ip address of the requester.- Specified by:
getRemoteIpAddress
in interfaceNanoHTTPD.IHTTPSession
- Returns:
- the IP address.
-
getRemoteHostName
public java.lang.String getRemoteHostName()
Description copied from interface:NanoHTTPD.IHTTPSession
Get the remote hostname of the requester.- Specified by:
getRemoteHostName
in interfaceNanoHTTPD.IHTTPSession
- Returns:
- the hostname.
-
-