Package org.simpleframework.http.message
Class SegmentConsumer
java.lang.Object
org.simpleframework.http.message.ArrayConsumer
org.simpleframework.http.message.SegmentConsumer
- All Implemented Interfaces:
ByteConsumer
,Segment
- Direct Known Subclasses:
HeaderConsumer
,PartHeaderConsumer
The
SegmentConsumer
object provides a consumer that is
used to consume a HTTP header. This will read all headers within a
HTTP header message until the carriage return line feed empty line
is encountered. Once all headers are consumed they are available
using the case insensitive header name. This will remove leading
and trailing whitespace from the names and values parsed.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
This is used to track the boundaries of a token so that it can be converted in to a usable string. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CookieParser
This is used to parse the cookie headers that are consumed.protected ContentDisposition
This is used to represent the content disposition header.protected String
This represents the transfer encoding value of the body.protected boolean
This is used to determine if there is a continue expected.protected MessageHeader
This is used to store all consumed headers by the header name.protected LanguageParser
This is used to parse the languages accepted in the request.protected long
Represents the length of the body from the content length.protected long
This represents the length limit of the HTTP header cosumed.protected String
During parsing this is used to store the parsed header name,protected int
This is used to track the read offset within the header.protected int
This is used to track how much of the terminal is read.private static final byte[]
This is the terminal carriage return and line feed end line.protected ContentType
This is used to parse the content type header consumed.protected String
During parsing this is used to store the parsed header value.Fields inherited from class org.simpleframework.http.message.ArrayConsumer
array, chunk, count, done
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for theSegmentConsumer
object.SegmentConsumer
(int limit) Constructor for theSegmentConsumer
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This is used to add the name and value specified as a special header within the segment.protected void
adjust()
This will update the offset variable so that the next read will be of a non whitespace character.protected void
This will accept any cookie header and parse it such that all cookies within it are converted toCookie
objects and made available as typed objects.protected void
disposition
(String value) This is used to parse the content disposition header header so that the MIME type is available to the segment.protected void
This is used to store the transfer encoding header value.protected void
end()
This will update the offset variable so that the next read will be a non whitespace character or terminal character.protected boolean
This is used to determine if two header names are equal, this is done to ensure that the case insensitivity of HTTP header names is observed.protected void
This is used to determine if the expect continue header is present and thus there is a requirement to send the continue status before the client sends the request body.long
This is a convenience method that can be used to determine the length of the message body.This is a convenience method that can be used to determine the content type of the message body.This is a convenience method that can be used to determine the content type of the message body.This method is used to acquire the file name of the part.This is used to acquire the locales from the request header.getName()
This method is used to acquire the name of the part.This is a convenience method that can be used to determine the content type of the message body.This can be used to get the value of the first message header that has the specified name.This can be used to get the value of the first message header that has the specified name.This can be used to get the values of HTTP message headers that have the specified name.private void
header()
This is used to parse a header from the consumed HTTP message and add them to the segment.protected void
headers()
This is used to parse the headers from the consumed HTTP header and add them to the segment.boolean
This is used to determine if the header represents one that requires the HTTP/1.1 continue expectation.boolean
isFile()
This method is used to determine the type of a part.protected void
This is used to parse theAccept-Language
header value.protected void
This is used to parse a provided header value for the content length.private void
name()
This updates the token for the header name.protected void
process()
This is used to process the headers when the terminal token has been fully read from the consumed bytes.protected void
resize
(int size) This method is used to add an additional chunk size to the internal array.protected int
scan()
This method is used to scan for the terminal token.protected boolean
space
(byte octet) This identifies a given ISO-8859-1 byte as a space character.protected boolean
terminal
(byte octet) This determines if an ISO-8859-1 byte is a terminal character.toString()
This is used to provide a string representation of the header read.protected void
This is used to parse the content type header header so that the MIME type is available to the segment.private void
value()
This is used to parse the HTTP header value.protected boolean
white
(byte octet) This is used to determine if a given ISO-8859-1 byte is a white space character, such as a tab or space or a terminal character, such as a carriage return or a new line.Methods inherited from class org.simpleframework.http.message.ArrayConsumer
consume, isFinished
-
Field Details
-
TERMINAL
private static final byte[] TERMINALThis is the terminal carriage return and line feed end line. -
disposition
This is used to represent the content disposition header. -
language
This is used to parse the languages accepted in the request. -
cookies
This is used to parse the cookie headers that are consumed. -
header
This is used to store all consumed headers by the header name. -
type
This is used to parse the content type header consumed. -
encoding
This represents the transfer encoding value of the body. -
name
During parsing this is used to store the parsed header name, -
value
During parsing this is used to store the parsed header value. -
expect
protected boolean expectThis is used to determine if there is a continue expected. -
length
protected long lengthRepresents the length of the body from the content length. -
limit
protected long limitThis represents the length limit of the HTTP header cosumed. -
pos
protected int posThis is used to track the read offset within the header. -
scan
protected int scanThis is used to track how much of the terminal is read.
-
-
Constructor Details
-
SegmentConsumer
public SegmentConsumer()Constructor for theSegmentConsumer
object. This is used to create a segment consumer used to consume and parse a HTTP message header. This delegates parsing of headers if they represent special headers, like content type or cookies. -
SegmentConsumer
public SegmentConsumer(int limit) Constructor for theSegmentConsumer
object. This is used to create a segment consumer used to consume and parse a HTTP message header. This delegates parsing of headers if they represent special headers, like content type or cookies.- Parameters:
limit
- this is the length limit for a HTTP header
-
-
Method Details
-
isFile
public boolean isFile()This method is used to determine the type of a part. Typically a part is either a text parameter or a file. If this is true then the content represented by the associated part is a file. -
getName
This method is used to acquire the name of the part. Typically this is used when the part represents a text parameter rather than a file. However, this can also be used with a file part. -
getFileName
This method is used to acquire the file name of the part. This is used when the part represents a text parameter rather than a file. However, this can also be used with a file part.- Specified by:
getFileName
in interfaceSegment
- Returns:
- this returns the file name of the associated part
-
getContentType
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aContent-Type
header, if there is then this will parse that header and represent it as a typed object which will expose the various parts of the HTTP header.- Specified by:
getContentType
in interfaceSegment
- Returns:
- this returns the content type value if it exists
-
getContentLength
public long getContentLength()This is a convenience method that can be used to determine the length of the message body. This will determine if there is aContent-Length
header, if it does then the length can be determined, if not then this returns -1.- Specified by:
getContentLength
in interfaceSegment
- Returns:
- the content length, or -1 if it cannot be determined
-
getTransferEncoding
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aTransfer-Encoding
header, if there is then this will parse that header and return the first token in the comma separated list of values, which is the primary value.- Specified by:
getTransferEncoding
in interfaceSegment
- Returns:
- this returns the transfer encoding value if it exists
-
getDisposition
This is a convenience method that can be used to determine the content type of the message body. This will determine whether there is aContent-Disposition
header, if there is this will parse that header and represent it as a typed object which will expose the various parts of the HTTP header.- Specified by:
getDisposition
in interfaceSegment
- Returns:
- this returns the content disposition value if it exists
-
getLocales
This is used to acquire the locales from the request header. The locales are provided in theAccept-Language
header. This provides an indication as to the languages that the client accepts. It provides the locales in preference order.- Returns:
- this returns the locales preferred by the client
-
getValues
This can be used to get the values of HTTP message headers that have the specified name. This is a convenience method that will present that values as tokens extracted from the header. This has obvious performance benefits as it avoids having to deal withsubstring
andtrim
calls.The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearance.
The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has highest preference.
-
getValue
This can be used to get the value of the first message header that has the specified name. The value provided from this will be trimmed so there is no need to modify the value, also if the header name specified refers to a comma separated list of values the value returned is the first value in that list. This returns null if theres no HTTP message header. -
getValue
This can be used to get the value of the first message header that has the specified name. The value provided from this will be trimmed so there is no need to modify the value, also if the header name specified refers to a comma separated list of values the value returned is the first value in that list. This returns null if there is no HTTP message header. -
isExpectContinue
public boolean isExpectContinue()This is used to determine if the header represents one that requires the HTTP/1.1 continue expectation. If the request does require this expectation then it should be send the 100 status code which prompts delivery of the message body.- Returns:
- this returns true if a continue expectation exists
-
resize
This method is used to add an additional chunk size to the internal array. Resizing of the internal array is required as the consumed bytes may exceed the initial size of the array. In such a scenario the array is expanded the chunk size.- Overrides:
resize
in classArrayConsumer
- Parameters:
size
- this is the minimum size to expand the array to- Throws:
IOException
-
process
This is used to process the headers when the terminal token has been fully read from the consumed bytes. Processing will extract all headers from the HTTP header message and further parse those values if required.- Specified by:
process
in classArrayConsumer
- Throws:
IOException
-
headers
protected void headers()This is used to parse the headers from the consumed HTTP header and add them to the segment. Once added they are available via the header name in a case insensitive manner. If the header has a special value, that is, if further information is required it will be extracted and exposed in the segment interface. -
header
private void header()This is used to parse a header from the consumed HTTP message and add them to the segment. Once added it is available via the header name in a case insensitive manner. If the header has a special value, that is, if further information is required it will be extracted and exposed in the segment interface. -
add
This is used to add the name and value specified as a special header within the segment. Special headers are those where there are values of interest to the segment. For instance the Content-Length, Content-Type, and Cookie headers are parsed using an external parser to extract the values.- Parameters:
name
- this is the name of the header to be addedvalue
- this is the value of the header to be added
-
expect
This is used to determine if the expect continue header is present and thus there is a requirement to send the continue status before the client sends the request body. This will basically assume the expectation is always continue.- Parameters:
value
- the value in the expect continue header
-
cookie
This will accept any cookie header and parse it such that all cookies within it are converted toCookie
objects and made available as typed objects. If the value can not be parsed this will not add the cookie value.- Parameters:
value
- this is the value of the cookie to be parsed
-
language
This is used to parse theAccept-Language
header value. This allows the locales the client is interested in to be provided in preference order and allows the client do alter and response based on the locale the client has provided.- Parameters:
value
- this is the value that is to be parsed
-
type
This is used to parse the content type header header so that the MIME type is available to the segment. This provides an instance of theContentType
object to represent the content type header, which exposes the charset value.- Parameters:
value
- this is the content type value to parse
-
disposition
This is used to parse the content disposition header header so that the MIME type is available to the segment. This provides an instance of theDisposition
object to represent the content disposition, this exposes the upload type.
- Parameters:
value
- this is the content type value to parse
-
encoding
This is used to store the transfer encoding header value. This is used to determine the encoding of the body this segment represents. Typically this will be the chunked encoding.- Parameters:
value
- this is the value representing the encoding
-
length
This is used to parse a provided header value for the content length. If the string provided is not an integer value this will throw a number format exception, by default length is -1.- Parameters:
value
- this is the header value of the content length
-
name
private void name()This updates the token for the header name. The name is parsed according to the presence of a colon ':'. Once a colon character is encountered then this header name is considered to be read from the buffer and is used to key the value after the colon. -
value
private void value()This is used to parse the HTTP header value. This will parse it in such a way that the line can be folded over several lines see RFC 2616 for the syntax of a folded line. The folded line is basically a way to wrap a single HTTP header into several lines using a tab at the start of the following line to indicate that the header flows onto the next line. -
adjust
protected void adjust()This will update the offset variable so that the next read will be of a non whitespace character. According to RFC 2616 a white space character is a tab or a space. This will remove multiple occurrences of whitespace characters until an non-whitespace character is encountered. -
end
protected void end()This will update the offset variable so that the next read will be a non whitespace character or terminal character. According to RFC 2616 a white space character is a tab or a space. This will remove multiple occurrences of whitespace characters until an non-whitespace character or a non-terminal is encountered. This is basically used to follow through to the end of a header line. -
scan
protected int scan()This method is used to scan for the terminal token. It searches for the token and returns the number of bytes in the buffer after the terminal token. Returning the excess bytes allows the consumer to reset the bytes within the consumer object.- Specified by:
scan
in classArrayConsumer
- Returns:
- this returns the number of excess bytes consumed
-
equal
This is used to determine if two header names are equal, this is done to ensure that the case insensitivity of HTTP header names is observed. Special headers are processed using this consumer and this is used to ensure the correct header is always matched.- Parameters:
name
- this is the name to compare the parsed token withtoken
- this is the header name token to examine- Returns:
- true of the header name token is equal to the name
-
space
protected boolean space(byte octet) This identifies a given ISO-8859-1 byte as a space character. A space is either a space or a tab character in ISO-8859-1.- Parameters:
octet
- the byte to determine whether it is a space- Returns:
- true if it is a space character, false otherwise
-
terminal
protected boolean terminal(byte octet) This determines if an ISO-8859-1 byte is a terminal character. A terminal character is a carriage return or a line feed character.- Parameters:
octet
- the byte to determine whether it is a terminal- Returns:
- true if it is a terminal character, false otherwise
-
white
protected boolean white(byte octet) This is used to determine if a given ISO-8859-1 byte is a white space character, such as a tab or space or a terminal character, such as a carriage return or a new line. If it is, this will return true otherwise it returns false.- Parameters:
octet
- this is to be checked to see if it is a space- Returns:
- true if the byte is a space character, false otherwise
-
toString
This is used to provide a string representation of the header read. Providing a string representation of the header is used so that on debugging the contents of the delivered header can be inspected in order to determine a cause of error.
-