Class HttpMessage
- java.lang.Object
-
- org.parosproxy.paros.network.HttpMessage
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
EVENT_DATA_REQUEST_BODY
static java.lang.String
EVENT_DATA_REQUEST_HEADER
static java.lang.String
EVENT_DATA_RESPONSE_BODY
static java.lang.String
EVENT_DATA_RESPONSE_HEADER
static java.lang.String
EVENT_DATA_URI
static java.lang.String
MESSAGE_TYPE
-
Constructor Summary
Constructors Constructor Description HttpMessage()
Constructor for a empty HTTP message.HttpMessage(java.lang.String reqHeader, byte[] reqBody, java.lang.String resHeader, byte[] resBody)
HttpMessage(org.apache.commons.httpclient.URI uri)
Constructs aHttpMessage
with a HTTP/1.1 GET request to the given URI.HttpMessage(org.apache.commons.httpclient.URI uri, ConnectionParam params)
Deprecated.(2.8.0) UseHttpMessage(URI)
instead.HttpMessage(HttpMessage message)
Constructs aHttpMessage
from the given message.HttpMessage(HttpRequestHeader reqHeader)
Constructs an HTTP message with the given request header.HttpMessage(HttpRequestHeader reqHeader, HttpRequestBody reqBody)
Constructs an HTTP message with the given request header and request body.HttpMessage(HttpRequestHeader reqHeader, HttpRequestBody reqBody, HttpResponseHeader resHeader, HttpResponseBody resBody)
Constructor for a HTTP message with given request and response pair.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpMessage
cloneAll()
Clones this message.HttpMessage
cloneRequest()
Clones the request of this message.boolean
equals(java.lang.Object object)
Compare if 2 message is the same.boolean
equalType(HttpMessage msg)
Compares thisHttpMessage
against another.java.util.TreeSet<HtmlParameter>
getCookieParams()
java.lang.String
getCookieParamsAsString()
java.util.TreeSet<HtmlParameter>
getFormParams()
HistoryReference
getHistoryRef()
HttpSession
getHttpSession()
Gets the http session associated with this message.java.lang.String
getNote()
java.util.List<java.lang.String>
getParameterNames(HtmlParameter.Type type)
Returns the names of the parameters of the giventype
in a List.java.util.List<HtmlParameter>
getParameters(HtmlParameter.Type type)
Returns the parameters of the giventype
in a List.java.lang.String[]
getParamNames()
java.util.TreeSet<java.lang.String>
getParamNameSet(HtmlParameter.Type type)
Returns the names of the parameters of the giventype
.HttpRequestBody
getRequestBody()
Gets the request body of this message.HttpRequestHeader
getRequestHeader()
Gets the request header of this message.User
getRequestingUser()
Gets the request user.HttpResponseBody
getResponseBody()
Gets the response body of this message.HttpResponseHeader
getResponseHeader()
Gets the response header of this message.int
getTimeElapsedMillis()
long
getTimeSentMillis()
Get the starting time when the request is going to be sent.java.lang.String
getType()
Returns "HTTP"java.util.TreeSet<HtmlParameter>
getUrlParams()
java.lang.Object
getUserObject()
int
hashCode()
boolean
isEventStream()
ZAP: New method checking if connection is a Server-Sent Events stream.boolean
isForceIntercept()
boolean
isInScope()
boolean
isResponseFromTargetHost()
Tells whether or not the response has been received from the target host.boolean
isWebSocketUpgrade()
ZAP: New method checking for connection upgrade.void
mutateHttpMethod(java.lang.String method)
static void
setContentEncodings(HttpHeader header, HttpBody body)
Sets the content encodings defined in the header into the body.void
setCookieParams(java.util.TreeSet<HtmlParameter> cookieParams)
void
setCookieParamsAsString(java.lang.String data)
void
setCookies(java.util.List<java.net.HttpCookie> cookies)
void
setForceIntercept(boolean force)
void
setFormParams(java.util.TreeSet<HtmlParameter> postParams)
void
setGetParams(java.util.TreeSet<HtmlParameter> getParams)
void
setHistoryRef(HistoryReference historyRef)
void
setHttpSession(HttpSession session)
Sets the http session associated with this message.void
setNote(java.lang.String note)
void
setRequestBody(byte[] body)
Sets the given byte body as the request body.void
setRequestBody(java.lang.String body)
Sets the given string body as the request body.void
setRequestBody(HttpRequestBody reqBody)
Sets the request body of this message.void
setRequestHeader(java.lang.String reqHeader)
Sets the given string as the request header.void
setRequestHeader(HttpRequestHeader reqHeader)
Sets the request header of this message.void
setRequestingUser(User requestUser)
Sets the requesting user.void
setResponseBody(byte[] body)
Sets the given byte body as the response body.void
setResponseBody(java.lang.String body)
Sets the given string body as the response body.void
setResponseBody(HttpResponseBody resBody)
Sets the response body of this message.void
setResponseFromTargetHost(boolean responseFromTargetHost)
Sets if the response has been received or not from the target host.void
setResponseHeader(java.lang.String resHeader)
Sets the given string as the response header.void
setResponseHeader(HttpResponseHeader resHeader)
Sets the response header of this message.void
setTimeElapsedMillis(int timeElapsed)
Set the elapsed time (time difference) between the request is sent and all response is received.void
setTimeSentMillis(long timeSent)
Set the time when the request is sent.void
setUserObject(java.lang.Object userObject)
java.util.Map<java.lang.String,java.lang.String>
toEventData()
Returns a map of data suitable for including in anEvent
-
-
-
Field Detail
-
EVENT_DATA_URI
public static final java.lang.String EVENT_DATA_URI
- See Also:
- Constant Field Values
-
EVENT_DATA_REQUEST_HEADER
public static final java.lang.String EVENT_DATA_REQUEST_HEADER
- See Also:
- Constant Field Values
-
EVENT_DATA_REQUEST_BODY
public static final java.lang.String EVENT_DATA_REQUEST_BODY
- See Also:
- Constant Field Values
-
EVENT_DATA_RESPONSE_HEADER
public static final java.lang.String EVENT_DATA_RESPONSE_HEADER
- See Also:
- Constant Field Values
-
EVENT_DATA_RESPONSE_BODY
public static final java.lang.String EVENT_DATA_RESPONSE_BODY
- See Also:
- Constant Field Values
-
MESSAGE_TYPE
public static final java.lang.String MESSAGE_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpMessage
public HttpMessage()
Constructor for a empty HTTP message.
-
HttpMessage
public HttpMessage(org.apache.commons.httpclient.URI uri) throws HttpMalformedHeaderException
Constructs aHttpMessage
with a HTTP/1.1 GET request to the given URI.The following headers are automatically added:
Host
, with the domain and port from the given URI.User-Agent
, using theHttpRequestHeader.getDefaultUserAgent()
.Pragma: no-cache
Cache-Control: no-cache
, if version is HTTP/1.1Content-Type: application/x-www-form-urlencoded
, if the method is POST or PUT.
- Parameters:
uri
- the request target.- Throws:
HttpMalformedHeaderException
- if the resulting HTTP header is malformed.
-
HttpMessage
@Deprecated public HttpMessage(org.apache.commons.httpclient.URI uri, ConnectionParam params) throws HttpMalformedHeaderException
Deprecated.(2.8.0) UseHttpMessage(URI)
instead.Constructs aHttpMessage
with a HTTP/1.1 GET request to the given URI.The following headers are automatically added:
Host
, with the domain and port from the given URI.User-Agent
, using theHttpRequestHeader.getDefaultUserAgent()
.Pragma: no-cache
Cache-Control: no-cache
, if version is HTTP/1.1Content-Type: application/x-www-form-urlencoded
, if the method is POST or PUT.
- Parameters:
uri
- the request target.params
- unused.- Throws:
HttpMalformedHeaderException
- if the resulting HTTP header is malformed.- Since:
- 2.4.2
-
HttpMessage
public HttpMessage(HttpRequestHeader reqHeader)
Constructs an HTTP message with the given request header.- Parameters:
reqHeader
- the request header- Throws:
java.lang.IllegalArgumentException
- if the parameterreqHeader
isnull
.
-
HttpMessage
public HttpMessage(HttpRequestHeader reqHeader, HttpRequestBody reqBody)
Constructs an HTTP message with the given request header and request body.- Parameters:
reqHeader
- the request headerreqBody
- the request body- Throws:
java.lang.IllegalArgumentException
- if the parameterreqHeader
orreqBody
arenull
.
-
HttpMessage
public HttpMessage(HttpRequestHeader reqHeader, HttpRequestBody reqBody, HttpResponseHeader resHeader, HttpResponseBody resBody)
Constructor for a HTTP message with given request and response pair.- Parameters:
reqHeader
- the request headerreqBody
- the request bodyresHeader
- the response headerresBody
- the response body- Throws:
java.lang.IllegalArgumentException
- if one of the parameters isnull
.
-
HttpMessage
public HttpMessage(java.lang.String reqHeader, byte[] reqBody, java.lang.String resHeader, byte[] resBody) throws HttpMalformedHeaderException
- Throws:
HttpMalformedHeaderException
-
HttpMessage
public HttpMessage(HttpMessage message)
Constructs aHttpMessage
from the given message.All the
HttpMessage
state is copied, except for the following which are the same:- Parameters:
message
- the message to copy.- Since:
- 2.8.0
-
-
Method Detail
-
getHistoryRef
public HistoryReference getHistoryRef()
-
setHistoryRef
public void setHistoryRef(HistoryReference historyRef)
-
getHttpSession
public HttpSession getHttpSession()
Gets the http session associated with this message.- Returns:
- the http session
-
setHttpSession
public void setHttpSession(HttpSession session)
Sets the http session associated with this message.- Parameters:
session
- the new http session
-
getRequestHeader
public HttpRequestHeader getRequestHeader()
Gets the request header of this message.- Returns:
- the request header, never
null
-
setRequestHeader
public void setRequestHeader(HttpRequestHeader reqHeader)
Sets the request header of this message.- Parameters:
reqHeader
- the new request header- Throws:
java.lang.IllegalArgumentException
- if parameterreqHeader
isnull
.
-
getResponseHeader
public HttpResponseHeader getResponseHeader()
Gets the response header of this message.To know if a response has been set call the method
HttpResponseHeader#isEmpty()
on the returned response header. The response header is initially empty.- Returns:
- the response header, never
null
- See Also:
HttpHeader.isEmpty()
-
setResponseHeader
public void setResponseHeader(HttpResponseHeader resHeader)
Sets the response header of this message.- Parameters:
resHeader
- the new response header- Throws:
java.lang.IllegalArgumentException
- if parameterresHeader
isnull
.
-
getRequestBody
public HttpRequestBody getRequestBody()
Gets the request body of this message.- Returns:
- the request body, never
null
-
setRequestBody
public void setRequestBody(HttpRequestBody reqBody)
Sets the request body of this message.Note: No encodings are set to the request body to match the header.
- Parameters:
reqBody
- the new request body- Throws:
java.lang.IllegalArgumentException
- if parameterreqBody
isnull
.
-
getResponseBody
public HttpResponseBody getResponseBody()
Gets the response body of this message.- Returns:
- the response body, never
null
-
setResponseBody
public void setResponseBody(HttpResponseBody resBody)
Sets the response body of this message.Note: No encodings are set to the response body to match the header.
- Parameters:
resBody
- the new response body- Throws:
java.lang.IllegalArgumentException
- if parameterresBody
isnull
.
-
setRequestHeader
public void setRequestHeader(java.lang.String reqHeader) throws HttpMalformedHeaderException
Sets the given string as the request header.Note: No encodings are set to the request body to match the header.
- Parameters:
reqHeader
- the new request header.- Throws:
HttpMalformedHeaderException
- if the given header is malformed.- See Also:
setContentEncodings(HttpHeader, HttpBody)
-
setResponseHeader
public void setResponseHeader(java.lang.String resHeader) throws HttpMalformedHeaderException
Sets the given string as the response header.Note: No encodings are set to the response body to match the header.
- Parameters:
resHeader
- the new response header.- Throws:
HttpMalformedHeaderException
- if the given header is malformed.- See Also:
setContentEncodings(HttpHeader, HttpBody)
-
setContentEncodings
public static void setContentEncodings(HttpHeader header, HttpBody body)
Sets the content encodings defined in the header into the body.Note: Supports only
gzip
anddeflate
.- Parameters:
header
- the header.body
- the body.
-
setRequestBody
public void setRequestBody(java.lang.String body)
Sets the given string body as the request body.The defined request header content encodings are set to the body, the string body will be encoded accordingly.
- Parameters:
body
- the new body.- See Also:
HttpBody.setContentEncodings(List)
-
setRequestBody
public void setRequestBody(byte[] body)
Sets the given byte body as the request body.The defined request header content encodings are set to the body, the byte body is assumed to be properly encoded.
- Parameters:
body
- the new body.- See Also:
HttpBody.setContentEncodings(List)
-
setResponseBody
public void setResponseBody(java.lang.String body)
Sets the given string body as the response body.The defined response header content encodings are set to the body, the string body will be encoded accordingly.
- Parameters:
body
- the new body.- See Also:
HttpBody.setContentEncodings(List)
-
setResponseBody
public void setResponseBody(byte[] body)
Sets the given byte body as the response body.The defined response header content encodings are set to the body, the byte body is assumed to be properly encoded.
- Parameters:
body
- the new body.- See Also:
HttpBody.setContentEncodings(List)
-
equals
public boolean equals(java.lang.Object object)
Compare if 2 message is the same. 2 messages are the same if: Host, port, path and query param and VALUEs are the same. For POST request, the body must be the same.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
-- Returns:
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equalType
public boolean equalType(HttpMessage msg)
Compares thisHttpMessage
against another. Messages are equal type if the host, port, path and parameter names are equal. Even though the query values may differ. For POST this assumes x-www-form-urlencoded, for other types (such as JSON) this means that parameter names and values (the full request body) could be included.- Parameters:
msg
- the message against which thisHttpMessage
is being compared.- Returns:
true
if the messages are considered equal,false
otherwise
-
getParamNameSet
public java.util.TreeSet<java.lang.String> getParamNameSet(HtmlParameter.Type type)
Returns the names of the parameters of the giventype
. As a Set is used no names will be duplicated.- Parameters:
type
- the type of the parameters that will be extracted from the message- Returns:
- a
TreeSet
with the names of the parameters of the giventype
, nevernull
- Since:
- 2.4.2
-
getParameterNames
public java.util.List<java.lang.String> getParameterNames(HtmlParameter.Type type)
Returns the names of the parameters of the giventype
in a List. The List can return duplicated names.- Parameters:
type
- the type of the parameters that will be extracted from the message- Returns:
- a
List
with the names of the parameters of the giventype
, nevernull
- Since:
- 2.10.0
-
getParameters
public java.util.List<HtmlParameter> getParameters(HtmlParameter.Type type)
Returns the parameters of the giventype
in a List. The List can return duplicated parameter names.- Parameters:
type
- the type of the parameters that will be extracted from the message- Returns:
- a
List
with the parameters of the giventype
, nevernull
- Since:
- 2.10.0
-
getParamNames
public java.lang.String[] getParamNames()
-
getUrlParams
public java.util.TreeSet<HtmlParameter> getUrlParams()
-
getFormParams
public java.util.TreeSet<HtmlParameter> getFormParams()
-
setCookieParamsAsString
public void setCookieParamsAsString(java.lang.String data)
-
getCookieParamsAsString
public java.lang.String getCookieParamsAsString()
-
getCookieParams
public java.util.TreeSet<HtmlParameter> getCookieParams()
-
getUserObject
public java.lang.Object getUserObject()
- Returns:
- Returns the userObject.
-
setUserObject
public void setUserObject(java.lang.Object userObject)
- Parameters:
userObject
- The userObject to set.
-
cloneAll
public HttpMessage cloneAll()
Clones this message.It returns a new
HttpMessage
with a copy of the request/response headers and bodies, no other state is copied.- Returns:
- a new
HttpMessage
with the same (contents) request/response headers and bodies as this one. - See Also:
HttpMessage(HttpMessage)
-
cloneRequest
public HttpMessage cloneRequest()
Clones the request of this message.It returns a new
HttpMessage
with a copy of the request header and body, no other state is copied.- Returns:
- a new
HttpMessage
with the same (contents) request header and body as this one. - See Also:
HttpMessage(HttpMessage)
-
getTimeElapsedMillis
public int getTimeElapsedMillis()
- Returns:
- Get the elapsed time (time difference) between the request is sent and all response is received. In millis. The value is zero if the response is not received.
-
setTimeElapsedMillis
public void setTimeElapsedMillis(int timeElapsed)
Set the elapsed time (time difference) between the request is sent and all response is received. In millis.- Parameters:
timeElapsed
-
-
getTimeSentMillis
public long getTimeSentMillis()
Get the starting time when the request is going to be sent. This is the System.currentTimeMillis before the message is sent. The value is zero if the request is not sent yet.
-
setTimeSentMillis
public void setTimeSentMillis(long timeSent)
Set the time when the request is sent.- Parameters:
timeSent
- The timeSent to set.
-
getNote
public java.lang.String getNote()
- Returns:
- Returns the note.
-
setNote
public void setNote(java.lang.String note)
- Parameters:
note
- The note to set.
-
mutateHttpMethod
public void mutateHttpMethod(java.lang.String method)
-
setFormParams
public void setFormParams(java.util.TreeSet<HtmlParameter> postParams)
-
setGetParams
public void setGetParams(java.util.TreeSet<HtmlParameter> getParams)
-
setCookieParams
public void setCookieParams(java.util.TreeSet<HtmlParameter> cookieParams)
-
isWebSocketUpgrade
public boolean isWebSocketUpgrade()
ZAP: New method checking for connection upgrade.- Returns:
- True if this connection should be upgraded to WebSockets.
-
setCookies
public void setCookies(java.util.List<java.net.HttpCookie> cookies)
-
isEventStream
public boolean isEventStream()
ZAP: New method checking if connection is a Server-Sent Events stream.- Returns:
-
isForceIntercept
public boolean isForceIntercept()
- Specified by:
isForceIntercept
in interfaceMessage
-
setForceIntercept
public void setForceIntercept(boolean force)
-
getRequestingUser
public User getRequestingUser()
Gets the request user.- Returns:
- the request user
-
setRequestingUser
public void setRequestingUser(User requestUser)
Sets the requesting user. When sending the message, if a requesting user has been set, the message will be modified so that it will be sent as from the point of view of this particular user.- Parameters:
requestUser
- the new request user
-
isResponseFromTargetHost
public boolean isResponseFromTargetHost()
Tells whether or not the response has been received from the target host.Note: No distinction is done between responses from intermediate proxy servers (if any) and the target host.
- Returns:
true
if the response has been received from the target host,false
otherwise.
-
setResponseFromTargetHost
public void setResponseFromTargetHost(boolean responseFromTargetHost)
Sets if the response has been received or not from the target host.- Parameters:
responseFromTargetHost
-true
if the response has been received from the target host,false
otherwise.
-
toEventData
public java.util.Map<java.lang.String,java.lang.String> toEventData()
Returns a map of data suitable for including in anEvent
- Specified by:
toEventData
in interfaceMessage
- Since:
- 2.8.0
-
-