Package org.simpleframework.http.message
Class RequestConsumer
- java.lang.Object
-
- org.simpleframework.http.message.ArrayConsumer
-
- org.simpleframework.http.message.SegmentConsumer
-
- org.simpleframework.http.message.HeaderConsumer
-
- org.simpleframework.http.message.RequestConsumer
-
- All Implemented Interfaces:
ByteConsumer
,Header
,Segment
public class RequestConsumer extends HeaderConsumer
TheRequestConsumer
object is used to parse the HTTP request line followed by the HTTP message headers. This parses the request URI such that the query parameters and path are extracted and normalized. It performs this using external parsers, which will remove and escaped characters and normalize the path segments. Finally this exposes the HTTP version used using the major and minor numbers sent with the HTTP request.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RequestConsumer.Token
This is a sequence of characters representing the header data consumed.
-
Field Summary
Fields Modifier and Type Field Description protected int
major
This is the major version number of the HTTP request header.protected java.lang.String
method
This is the method token send with the HTTP request header.protected int
minor
This is the minor version number of the HTTP request header.protected AddressParser
parser
This is the address parser used to parse the request URI.protected java.lang.String
target
This represents the raw request URI in an unparsed form.-
Fields inherited from class org.simpleframework.http.message.SegmentConsumer
cookies, disposition, encoding, expect, header, language, length, limit, name, pos, scan, type, value
-
Fields inherited from class org.simpleframework.http.message.ArrayConsumer
array, chunk, count, done
-
-
Constructor Summary
Constructors Constructor Description RequestConsumer()
Constructor for theRequestConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
digit(byte octet)
This is used to determine if a given ISO-8859-1 byte is a digit character, between an ISO-8859-1 0 and 9.Address
getAddress()
This is used to acquire the address from the request line.long
getDate(java.lang.String name)
This can be used to get the date of the first message header that has the specified name.java.lang.CharSequence
getHeader()
This method returns aCharSequence
holding the data consumed for the request.int
getInteger(java.lang.String name)
This can be used to get the integer of the first message header that has the specified name.int
getMajor()
This can be used to get the major number from a HTTP version.java.lang.String
getMethod()
This can be used to get the HTTP method for this request.int
getMinor()
This can be used to get the minor number from a HTTP version.java.util.List<java.lang.String>
getNames()
This method is used to get aList
of the names for the headers.Path
getPath()
This is used to acquire the path as extracted from the the HTTP request URI.Query
getQuery()
This method is used to acquire the query part from the HTTP request URI target.java.lang.String
getTarget()
This can be used to get the target specified for this HTTP request.private void
major()
This will parse the header from the current offset and convert the bytes found into an int as it parses the digits it comes accross.private void
method()
This will parse HTTP method from the first line of the header and store the parsed string internally.private void
minor()
This will parse the header from the current offset and convert the bytes found into an int as it parses the digits it comes accross.protected void
process()
This method is invoked after the terminal token has been read.private void
target()
This will parse URI target from the first line of the header and store the parsed string internally.java.lang.String
toString()
This is used to convert the byte range to a string.protected void
version()
This will parse HTTP version from the first line of the header and store the parsed string internally.-
Methods inherited from class org.simpleframework.http.message.HeaderConsumer
getCookie, getCookies
-
Methods inherited from class org.simpleframework.http.message.SegmentConsumer
add, adjust, cookie, disposition, encoding, end, equal, expect, getContentLength, getContentType, getDisposition, getFileName, getLocales, getName, getTransferEncoding, getValue, getValue, getValues, headers, isExpectContinue, isFile, language, length, resize, scan, space, terminal, type, white
-
Methods inherited from class org.simpleframework.http.message.ArrayConsumer
consume, isFinished
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.simpleframework.http.message.Header
getLocales, isExpectContinue
-
Methods inherited from interface org.simpleframework.http.message.Segment
getContentLength, getContentType, getDisposition, getFileName, getName, getTransferEncoding, getValue, getValue, getValues, isFile
-
-
-
-
Field Detail
-
parser
protected AddressParser parser
This is the address parser used to parse the request URI.
-
method
protected java.lang.String method
This is the method token send with the HTTP request header.
-
target
protected java.lang.String target
This represents the raw request URI in an unparsed form.
-
major
protected int major
This is the major version number of the HTTP request header.
-
minor
protected int minor
This is the minor version number of the HTTP request header.
-
-
Method Detail
-
getTarget
public java.lang.String getTarget()
This can be used to get the target specified for this HTTP request. This corresponds to the URI sent in the request line. Typically this will be the path part of the URI, but can be the full URI if the request is a proxy request.- Returns:
- the target URI that this HTTP request specifies
-
getAddress
public Address getAddress()
This is used to acquire the address from the request line. An address is the full URI including the scheme, domain, port and the query parts. This allows various parameters to be acquired without having to parse the target.- Returns:
- this returns the address of the request line
-
getQuery
public Query getQuery()
This method is used to acquire the query part from the HTTP request URI target. This will return only the values that have been extracted from the request URI target.- Returns:
- the query associated with the HTTP target URI
-
getPath
public Path getPath()
This is used to acquire the path as extracted from the the HTTP request URI. ThePath
object that is provided by this method is immutable, it represents the normalized path only part from the request URI.- Returns:
- this returns the normalized path for the request
-
getMethod
public java.lang.String getMethod()
This can be used to get the HTTP method for this request. The HTTP specification RFC 2616 specifies the HTTP request methods in section 9, Method Definitions. Typically this will be a GET or POST method, but can be any valid alphabetic token.- Returns:
- the HTTP method that this request has specified
-
getMajor
public int getMajor()
This can be used to get the major number from a HTTP version. The major version corrosponds to the major protocol type, that is the 1 of a HTTP/1.0 version string. Typically the major type is 1, by can be 0 for HTTP/0.9 clients.- Returns:
- the major version number for the HTTP message
-
getMinor
public int getMinor()
This can be used to get the minor number from a HTTP version. The minor version corrosponds to the minor protocol type, that is the 0 of a HTTP/1.0 version string. This number is typically used to determine whether persistent connections are supported.- Returns:
- the minor version number for the HTTP message
-
getDate
public long getDate(java.lang.String name)
This can be used to get the date of the first message header that has the specified name. This is a convenience method that avoids having to deal with parsing the value of the requested HTTP message header. This returns -1 if theres no HTTP header value for the specified name.- Specified by:
getDate
in interfaceHeader
- Overrides:
getDate
in classHeaderConsumer
- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the date as a long from the header value
-
getInteger
public int getInteger(java.lang.String name)
This can be used to get the integer of the first message header that has the specified name. This is a convenience method that avoids having to deal with parsing the value of the requested HTTP message header. This returns -1 if theres no HTTP header value for the specified name.- Specified by:
getInteger
in interfaceHeader
- Overrides:
getInteger
in classHeaderConsumer
- Parameters:
name
- the HTTP message header to get the value from- Returns:
- this returns the date as a long from the header value
-
getNames
public java.util.List<java.lang.String> getNames()
This method is used to get aList
of the names for the headers. This will provide the original names for the HTTP headers for the message. Modifications to the provided list will not affect the header, the list is a simple copy.- Specified by:
getNames
in interfaceHeader
- Overrides:
getNames
in classHeaderConsumer
- Returns:
- this returns a list of the names within the header
-
process
protected void process()
This method is invoked after the terminal token has been read. It is used to process the consumed data and is typically used to parse the input such that it can be used by the subclass for some useful puropse. This is called only once by the consumer.- Overrides:
process
in classSegmentConsumer
-
target
private void target()
This will parse URI target from the first line of the header and store the parsed string internally. The target token is used to create anAddress
object which provides all the details of the target including the query part.
-
method
private void method()
This will parse HTTP method from the first line of the header and store the parsed string internally. The method is used to determine what action to take with the request, it also acts as a means to determine the semantics of the request.
-
version
protected void version()
This will parse HTTP version from the first line of the header and store the parsed string internally. The method is used to determine what version of HTTP is being used. Typically this will be HTTP/1.1 however HTTP/1.0 must be supported and this has different connection semantics with regards to pipelines.
-
major
private void major()
This will parse the header from the current offset and convert the bytes found into an int as it parses the digits it comes accross. This will cease to parse bytes when it encounters a non digit byte or the end of the readable bytes.
-
minor
private void minor()
This will parse the header from the current offset and convert the bytes found into an int as it parses the digits it comes accross. This will cease to parse bytes when it encounters a non digit byte or the end of the readable bytes.
-
digit
protected boolean digit(byte octet)
This is used to determine if a given ISO-8859-1 byte is a digit character, between an ISO-8859-1 0 and 9. If it is, this will return true otherwise it returns false.- Parameters:
octet
- this is to be checked to see if it is a digit- Returns:
- true if the byte is a digit character, false otherwise
-
getHeader
public java.lang.CharSequence getHeader()
This method returns aCharSequence
holding the data consumed for the request. A character sequence is returned as it can provide a much more efficient means of representing the header data by just wrapping the consumed byte array.- Returns:
- this returns the characters consumed for the header
-
toString
public java.lang.String toString()
This is used to convert the byte range to a string. This will use UTF-8 encoding for the string which is compatible with the HTTP default header encoding of ISO-8859-1.- Specified by:
toString
in interfaceHeader
- Overrides:
toString
in classSegmentConsumer
- Returns:
- the encoded string representing the token
-
-