public class HTTPRequest
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DELETE
Value returned by
getMethod() if the request method is DELETE . |
static int |
GET
Value returned by
getMethod() if the request method is GET . |
static int |
POST
Value returned by
getMethod() if the request method is POST . |
static int |
PUT
Value returned by
getMethod() if the request method is PUT . |
Modifier | Constructor and Description |
---|---|
protected |
HTTPRequest(HTTPServer server,
java.io.InputStream inputStream)
Constructs a new instance of HTTPRequest.
|
protected |
HTTPRequest(HTTPServer server,
java.io.InputStream inputStream,
BodyParserFactory bodyParserFactory)
Constructs a new instance of HTTPRequest.
|
Modifier and Type | Method and Description |
---|---|
protected void |
finish()
Not implemented(empty method).
|
BodyParser |
getBodyParser()
Gets the bodyParser.
|
java.util.Map<java.lang.String,java.lang.String> |
getHeader()
Returns all HTTP Header fields of the request.
|
java.lang.String |
getHeaderField(java.lang.String key)
Returns the header field value associated to the given header field
key . |
int |
getMethod()
|
java.util.Map<java.lang.String,java.lang.String> |
getParameters()
Returns the query parameters as
Map . |
java.io.InputStream |
getStream()
Gets the stream.
|
java.lang.String |
getURI()
Returns the request URI.
|
java.lang.String |
getVersion()
Returns the HTTP version request.
|
void |
parseBody()
Request the body to be parsed.
|
protected boolean |
parseRequestBody(java.io.InputStream stream)
Parses the request body given in
stream . |
protected boolean |
parseRequestHeader(java.io.InputStream input)
Called by HTTPSession.
|
void |
setBodyParser(BodyParser bodyParser)
Sets the bodyParser.
|
public static final int POST
Value returned by getMethod()
if the request method is POST
.
public static final int GET
Value returned by getMethod()
if the request method is GET
.
public static final int PUT
Value returned by getMethod()
if the request method is PUT
.
public static final int DELETE
Value returned by getMethod()
if the request method is DELETE
.
protected HTTPRequest(HTTPServer server, java.io.InputStream inputStream, BodyParserFactory bodyParserFactory) throws java.io.IOException, java.lang.IllegalArgumentException
server
- the HTTPServer
instanceinputStream
- the input stream for the requestbodyParserFactory
- the BodyParserFactory
to usejava.io.IOException
- if connection is lost during processing the requestjava.lang.IllegalArgumentException
- if parsing the request header or body failedUnsupportedHTTPEncodingException
- when an unsupported HTTP encoding encounteredprotected HTTPRequest(HTTPServer server, java.io.InputStream inputStream) throws java.io.IOException, java.lang.IllegalArgumentException
server
- the HTTPServer
instanceinputStream
- the input stream for the requestjava.io.IOException
- if connection is lost during processing the requestjava.lang.IllegalArgumentException
- if parsing the request header or body failedUnsupportedHTTPEncodingException
- when an unsupported HTTP encoding encounteredprotected void finish()
public java.util.Map<java.lang.String,java.lang.String> getHeader()
Returns all HTTP Header fields of the request.
Map
of (String,String) representing the HTTP Header Fields (may be empty).public java.lang.String getHeaderField(java.lang.String key)
Returns the header field value associated to the given header field key
.
key
- a header field name (if null
, null
is returned).null
if the header field is not found.public java.util.Map<java.lang.String,java.lang.String> getParameters()
Returns the query parameters as Map
.
Map
of (String,String) representing the HTTP Query Parameters.public java.lang.String getURI()
Returns the request URI.
public java.lang.String getVersion()
Returns the HTTP version request.
protected boolean parseRequestBody(java.io.InputStream stream) throws java.io.IOException
stream
.stream
- the InputStream
java.io.IOException
- when connection is lostprotected boolean parseRequestHeader(java.io.InputStream input) throws java.io.IOException
input
- the InputStream
false
if request is invalid, true
otherwisejava.io.IOException
- if connection has been lostpublic java.io.InputStream getStream()
public BodyParser getBodyParser()
public void setBodyParser(BodyParser bodyParser)
bodyParser
- the bodyParser to set.public void parseBody() throws java.io.IOException
java.io.IOException
- if an IOException
occurs durring parsing.