org.owasp.webscarab.model
Class Request

java.lang.Object
  extended by org.owasp.webscarab.model.Message
      extended by org.owasp.webscarab.model.Request

public class Request
extends Message

This class represents a request that can be sent to an HTTP server.

Author:
rdawes

Field Summary
 
Fields inherited from class org.owasp.webscarab.model.Message
_logger
 
Constructor Summary
Request()
          Creates a new instance of Request
Request(Request req)
          Creates a new Request, which is a copy of the supplied Request
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.lang.String getMethod()
          gets the Request method
 HttpUrl getURL()
          Gets the Request URL
 java.lang.String getVersion()
          gets the HTTP version
 void parse(java.lang.String string)
          parses a string representation of a request
 void parse(java.lang.StringBuffer buff)
          parses a string representation of a request
 void read(java.io.InputStream is)
          initialises the Request from the supplied InputStream
 void read(java.io.InputStream is, HttpUrl base)
          initialises the Request from the supplied InputStream, using the supplied Url as a base.
 void setMethod(java.lang.String method)
          Sets the request method
 void setURL(HttpUrl url)
          Sets the Request URL
 void setVersion(java.lang.String version)
          Sets the HTTP version supported
 java.lang.String toString()
          returns a string representation of the Request, using a CRLF of "\r\n"
 java.lang.String toString(java.lang.String crlf)
          returns a string representation of the Request, using the supplied string to separate lines
 void write(java.io.OutputStream os)
          Writes the Request to the supplied OutputStream, in a format appropriate for sending to an HTTP proxy.
 void write(java.io.OutputStream os, java.lang.String crlf)
          Writes the Request to the supplied OutputStream, in a format appropriate for sending to an HTTP proxy.
 void writeDirect(java.io.OutputStream os)
          Writes the Request to the supplied OutputStream, in a format appropriate for sending to the HTTP server itself.
 void writeDirect(java.io.OutputStream os, java.lang.String crlf)
          Writes the Request to the supplied OutputStream, in a format appropriate for sending to the HTTP server itself.
 
Methods inherited from class org.owasp.webscarab.model.Message
addHeader, addHeader, deleteHeader, flushContentStream, getContent, getHeader, getHeaderNames, getHeaders, getHeaders, getLine, readLine, setContent, setHeader, setHeader, setHeaders, setNoBody
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Request

public Request()
Creates a new instance of Request


Request

public Request(Request req)
Creates a new Request, which is a copy of the supplied Request

Parameters:
req - the request to copy
Method Detail

read

public void read(java.io.InputStream is)
          throws java.io.IOException
initialises the Request from the supplied InputStream

Overrides:
read in class Message
Parameters:
is - the InputStream to read from
Throws:
java.io.IOException - propagates any exceptions thrown by the InputStream

read

public void read(java.io.InputStream is,
                 HttpUrl base)
          throws java.io.IOException
initialises the Request from the supplied InputStream, using the supplied Url as a base. This will generally be useful where we are acting as a web server, and reading a line like "GET / HTTP/1.0". The request Url is then created relative to the supplied Url.

Parameters:
is - the InputStream to read from
base - the base Url to use for relative Urls
Throws:
java.io.IOException - propagates any IOExceptions thrown by the InputStream

parse

public void parse(java.lang.String string)
           throws java.text.ParseException
parses a string representation of a request

Parameters:
string - the string representing the request
Throws:
java.text.ParseException - if there are any errors parsing the request

parse

public void parse(java.lang.StringBuffer buff)
           throws java.text.ParseException
parses a string representation of a request

Overrides:
parse in class Message
Parameters:
buff - a StringBuffer containing the request. Note that the contents of the StringBuffer are consumed during parsing.
Throws:
java.text.ParseException - if there are any errors parsing the request

write

public void write(java.io.OutputStream os)
           throws java.io.IOException
Writes the Request to the supplied OutputStream, in a format appropriate for sending to an HTTP proxy. Uses the RFC CRLF string "\r\n"

Overrides:
write in class Message
Parameters:
os - the OutputStream to write to
Throws:
java.io.IOException - if the underlying stream throws any.

write

public void write(java.io.OutputStream os,
                  java.lang.String crlf)
           throws java.io.IOException
Writes the Request to the supplied OutputStream, in a format appropriate for sending to an HTTP proxy. Uses the supplied string to separate lines.

Overrides:
write in class Message
Parameters:
os - the OutputStream to write to
crlf - the string to use to separate the lines (usually a CRLF pair)
Throws:
java.io.IOException - if the underlying stream throws any.

writeDirect

public void writeDirect(java.io.OutputStream os)
                 throws java.io.IOException
Writes the Request to the supplied OutputStream, in a format appropriate for sending to the HTTP server itself. Uses the RFC CRLF string "\r\n"

Parameters:
os - the OutputStream to write to
Throws:
java.io.IOException - if the underlying stream throws any.

writeDirect

public void writeDirect(java.io.OutputStream os,
                        java.lang.String crlf)
                 throws java.io.IOException
Writes the Request to the supplied OutputStream, in a format appropriate for sending to the HTTP server itself. Uses the supplied string to separate lines.

Parameters:
os - the OutputStream to write to
crlf - the string to use to separate the lines (usually a CRLF pair)
Throws:
java.io.IOException - if the underlying stream throws any.

setMethod

public void setMethod(java.lang.String method)
Sets the request method

Parameters:
method - the method of the request (automatically converted to uppercase)

getMethod

public java.lang.String getMethod()
gets the Request method

Returns:
the request method

setURL

public void setURL(HttpUrl url)
Sets the Request URL

Parameters:
url - the url

getURL

public HttpUrl getURL()
Gets the Request URL

Returns:
the request url

setVersion

public void setVersion(java.lang.String version)
Sets the HTTP version supported

Parameters:
version - the version of the request. Automatically converted to uppercase.

getVersion

public java.lang.String getVersion()
gets the HTTP version

Returns:
the version of the request

toString

public java.lang.String toString()
returns a string representation of the Request, using a CRLF of "\r\n"

Overrides:
toString in class Message
Returns:
a string representation of the Request, using a CRLF of "\r\n"

toString

public java.lang.String toString(java.lang.String crlf)
returns a string representation of the Request, using the supplied string to separate lines

Overrides:
toString in class Message
Parameters:
crlf - the string to use to separate lines (usually CRLF)
Returns:
a string representation of the Request

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class Message