public class HttpSender extends Object
Modifier and Type | Field and Description |
---|---|
static int |
ACCESS_CONTROL_SCANNER_INITIATOR |
static int |
ACTIVE_SCANNER_INITIATOR |
static int |
AJAX_SPIDER_INITIATOR |
static int |
AUTHENTICATION_HELPER_INITIATOR |
static int |
AUTHENTICATION_INITIATOR |
static int |
BEAN_SHELL_INITIATOR |
static int |
CHECK_FOR_UPDATES_INITIATOR |
static int |
FORCED_BROWSE_INITIATOR |
static int |
FUZZER_INITIATOR |
static int |
MANUAL_REQUEST_INITIATOR |
static int |
PROXY_INITIATOR |
static int |
SPIDER_INITIATOR |
static int |
TOKEN_GENERATOR_INITIATOR |
static int |
WEB_SOCKET_INITIATOR |
Constructor and Description |
---|
HttpSender(ConnectionParam connectionParam,
boolean useGlobalState,
int initiator)
Constructs an
HttpSender . |
Modifier and Type | Method and Description |
---|---|
static void |
addListener(HttpSenderListener listener) |
int |
executeMethod(org.apache.commons.httpclient.HttpMethod method,
org.apache.commons.httpclient.HttpState state) |
org.apache.commons.httpclient.HttpClient |
getClient()
Deprecated.
(2.8.0) Do not use, this exposes implementation details which might change
without warning. It will be removed in a following version.
|
static SSLConnector |
getSSLConnector() |
User |
getUser(HttpMessage msg) |
static String |
getUserAgent() |
static void |
removeListener(HttpSenderListener listener) |
void |
sendAndReceive(HttpMessage msg) |
void |
sendAndReceive(HttpMessage msg,
boolean isFollowRedirect)
Send and receive a HttpMessage.
|
void |
sendAndReceive(HttpMessage message,
HttpRequestConfig requestConfig)
Sends the request of given HTTP
message with the given configurations. |
void |
setAllowCircularRedirects(boolean allow)
Sets whether or not circular redirects are allowed.
|
void |
setFollowRedirect(boolean followRedirect) |
void |
setMaxRedirects(int maxRedirects)
Sets the maximum number of redirects that will be followed before failing with an exception.
|
void |
setMaxRetriesOnIOError(int retries)
Sets the maximum number of retries of an unsuccessful request caused by I/O errors.
|
void |
setRemoveUserDefinedAuthHeaders(boolean removeHeaders)
Sets whether or not the authentication headers ("Authorization" and "Proxy-Authorization")
already present in the request should be removed if received an authentication challenge
(status codes 401 and 407).
|
void |
setUseGlobalState(boolean enableGlobalState)
Sets whether or not the global state should be used.
|
void |
setUser(User user)
Set the user to scan as.
|
static void |
setUserAgent(String userAgent) |
void |
shutdown() |
public static final int PROXY_INITIATOR
public static final int ACTIVE_SCANNER_INITIATOR
public static final int SPIDER_INITIATOR
public static final int FUZZER_INITIATOR
public static final int AUTHENTICATION_INITIATOR
public static final int MANUAL_REQUEST_INITIATOR
public static final int CHECK_FOR_UPDATES_INITIATOR
public static final int BEAN_SHELL_INITIATOR
public static final int ACCESS_CONTROL_SCANNER_INITIATOR
public static final int AJAX_SPIDER_INITIATOR
public static final int FORCED_BROWSE_INITIATOR
public static final int TOKEN_GENERATOR_INITIATOR
public static final int WEB_SOCKET_INITIATOR
public static final int AUTHENTICATION_HELPER_INITIATOR
public HttpSender(ConnectionParam connectionParam, boolean useGlobalState, int initiator)
HttpSender
.
If useGlobalState
is true
the HttpSender will use the HTTP state given by
ConnectionParam#getHttpState()
iff ConnectionParam#isHttpStateEnabled()
returns true
otherwise it doesn't have any state (i.e. cookies are disabled). If
useGlobalState
is false
it uses a non shared HTTP state. The actual state
used is overridden, per message, when HttpMessage#getRequestingUser()
returns non
null
.
The initiator
is used to indicate the component that is sending the messages when
the HttpSenderListener
s are notified of messages sent and received.
connectionParam
- the parameters used to setup the connections to target hostsuseGlobalState
- true
if the messages sent/received should use the global HTTP
state, false
if should use a non shared HTTP stateinitiator
- the ID of the initiator of the HTTP messages sentConnectionParam.getHttpState()
,
HttpSenderListener
,
HttpMessage.getRequestingUser()
public static SSLConnector getSSLConnector()
public void setUseGlobalState(boolean enableGlobalState)
Refer to HttpSender(ConnectionParam, boolean, int)
for details on how the global
state is used.
enableGlobalState
- true
if the global state should be used, false
otherwise.public int executeMethod(org.apache.commons.httpclient.HttpMethod method, org.apache.commons.httpclient.HttpState state) throws IOException
IOException
public void shutdown()
public void sendAndReceive(HttpMessage msg) throws IOException
IOException
public void sendAndReceive(HttpMessage msg, boolean isFollowRedirect) throws IOException
msg
- isFollowRedirect
- org.apache.commons.httpclient.HttpException
IOException
sendAndReceive(HttpMessage, HttpRequestConfig)
public User getUser(HttpMessage msg)
public void setFollowRedirect(boolean followRedirect)
public static String getUserAgent()
public static void setUserAgent(String userAgent)
userAgent
- The userAgent to set.public static void addListener(HttpSenderListener listener)
public static void removeListener(HttpSenderListener listener)
public void setUser(User user)
user
- @Deprecated public org.apache.commons.httpclient.HttpClient getClient()
public void setRemoveUserDefinedAuthHeaders(boolean removeHeaders)
If true
new authentication headers will be generated and the old ones removed
otherwise the authentication headers already present in the request will be used to
authenticate.
Default is false
, i.e. use the headers already present in the request header.
Processes that reuse messages previously sent should consider setting this to true
, otherwise new authentication challenges might fail.
removeHeaders
- true
if the the authentication headers already present should be
removed when challenged, false
otherwisepublic void setMaxRetriesOnIOError(int retries)
The default number of retries is 3.
retries
- the number of retriesIllegalArgumentException
- if retries
is negative.public void setMaxRedirects(int maxRedirects)
The default maximum number of redirects is 100.
maxRedirects
- the maximum number of redirectsIllegalArgumentException
- if maxRedirects
is negative.public void setAllowCircularRedirects(boolean allow)
Circular redirects happen when a request redirects to itself, or when a same request was already accessed in a chain of redirects.
Since 2.5.0, the default is to allow circular redirects.
allow
- true
if circular redirects should be allowed, false
otherwisepublic void sendAndReceive(HttpMessage message, HttpRequestConfig requestConfig) throws IOException
message
with the given configurations.message
- the message that will be sentrequestConfig
- the request configurations.IllegalArgumentException
- if any of the parameters is null
IOException
- if an error occurred while sending the message or following the
redirectionssendAndReceive(HttpMessage, boolean)