de.netseeker.ejoe.http
Class HttpHeaderParser

java.lang.Object
  extended by de.netseeker.ejoe.http.HttpHeaderParser
Direct Known Subclasses:
HttpRequestParser, HttpResponseParser

public class HttpHeaderParser
extends java.lang.Object

This is the main HTTP header parser of EJOE. It's able to validate an ByteBuffer if it contains a valid HTTP header and can detect:

It's not possible to create an instance directly, instead use HttpRequestParser or HttpResponseParser to create concrete parser instances.

Since:
0.3.9.1
Author:
netseeker

Field Summary
protected static java.nio.charset.Charset csISO
           
protected static java.lang.String LINE_SEP
           
protected static java.util.regex.Pattern pConnection
           
protected static java.util.regex.Pattern pContentLength
           
protected static java.util.regex.Pattern pLineEnd
           
 
Constructor Summary
protected HttpHeaderParser(java.nio.ByteBuffer buf)
          Hidden constructor, only child classes are permitted to create a new instance
 
Method Summary
protected  int extractContentLength()
          Determines the length of the expected content as stated in the "Content-Length:" section of the header
protected static int extractHeaderLength(java.nio.ByteBuffer bb)
          Searches the ByteBuffer for two line breaks (either "\r\n\r\n" or "\n\n") to detect the end of HTTP header data
 java.nio.ByteBuffer getByteHeader()
           
 java.nio.CharBuffer getCharHeader()
           
 int getContentLength()
          Returns the content length
 int getHeaderLength()
          Returns the length of the HTTP header in bytes without any preread content
 boolean hasCompression()
          Returns the compression setting in the HTTP-Header.
 boolean hasPrereadContent()
           
static boolean isComplete(java.nio.ByteBuffer bb)
          Checks if the HTTP is complete.
protected  boolean isConnectionPersistent()
          Checks if the client has requested a persistent connection
 boolean isPersistentConnection()
          Indicates whether the value for the HTTP header line "Connection:" was "close" or "open".
 boolean isValid()
          Checks if the HTTP header seems to be valid
protected  void setCompression(boolean enable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEP

protected static final java.lang.String LINE_SEP
See Also:
Constant Field Values

csISO

protected static final java.nio.charset.Charset csISO

pLineEnd

protected static final java.util.regex.Pattern pLineEnd

pContentLength

protected static final java.util.regex.Pattern pContentLength

pConnection

protected static final java.util.regex.Pattern pConnection
Constructor Detail

HttpHeaderParser

protected HttpHeaderParser(java.nio.ByteBuffer buf)
Hidden constructor, only child classes are permitted to create a new instance

Parameters:
buf - ByteBuffer expected to contain a HTTP header [ + optional preread content ]
Method Detail

getContentLength

public int getContentLength()
Returns the content length

Returns:
the content length

getHeaderLength

public int getHeaderLength()
Returns the length of the HTTP header in bytes without any preread content

Returns:
the length of the header

isValid

public boolean isValid()
Checks if the HTTP header seems to be valid

Returns:
true if the HTTP header seems to be valid (at least for EJOE) otherwise false

getCharHeader

public java.nio.CharBuffer getCharHeader()
Returns:
The decoded underlying buffer

getByteHeader

public java.nio.ByteBuffer getByteHeader()
Returns:
the underlying ByteBuffer

hasPrereadContent

public boolean hasPrereadContent()
Returns:
true if the underlying ByteBuffer already contains one or more preread bytes of content data

isPersistentConnection

public boolean isPersistentConnection()
Indicates whether the value for the HTTP header line "Connection:" was "close" or "open".

Returns:
true if the HTTP header did contain a "Connection:" header line and the value was "open" otherwise false

hasCompression

public boolean hasCompression()
Returns the compression setting in the HTTP-Header.

Returns:
true if the HTTP header requested use of GZIP compression otherwise false

setCompression

protected void setCompression(boolean enable)

extractContentLength

protected int extractContentLength()
Determines the length of the expected content as stated in the "Content-Length:" section of the header

Returns:
the content length

isConnectionPersistent

protected boolean isConnectionPersistent()
Checks if the client has requested a persistent connection

Returns:
true if the client requested a persitent connection otherwise false

extractHeaderLength

protected static int extractHeaderLength(java.nio.ByteBuffer bb)
Searches the ByteBuffer for two line breaks (either "\r\n\r\n" or "\n\n") to detect the end of HTTP header data

Parameters:
bb - ByteBuffer containing HTTP header data
Returns:
the length of the HTTP header in bytes

isComplete

public static boolean isComplete(java.nio.ByteBuffer bb)
Checks if the HTTP is complete. A header is then complete if either "\r\n\r\n" or "\n\n" are found within the given ByteBuffer

Parameters:
bb - ByteBuffer containing HTTP header data
Returns:
true if the HTTP header is complete (the buffer contains a terminated HTTP header [ + optional prearead content ]) otherwise false


Copyright © 2005-2007 netseeker. All Rights Reserved.