use of org.parosproxy.paros.network.HttpSender in project zaproxy by zaproxy.
the class AbstractPluginUnitTest method shouldSendMessageWithoutScanRuleIdHeaderIfDisabled.
@Test
void shouldSendMessageWithoutScanRuleIdHeaderIfDisabled() throws IOException {
// Given
AbstractPlugin plugin = createDefaultPlugin();
ScannerParam scannerParam = mock(ScannerParam.class);
given(scannerParam.isInjectPluginIdInHeader()).willReturn(false);
given(parent.getScannerParam()).willReturn(scannerParam);
HttpSender httpSender = mock(HttpSender.class);
given(parent.getHttpSender()).willReturn(httpSender);
plugin.init(message, parent);
HttpMessage message = new HttpMessage(new URI("http://example.com/", true));
// When
plugin.sendAndReceive(message, true, true);
// Then
assertThat(message.getRequestHeader().getHeader(HttpHeader.X_ZAP_SCAN_ID), is(nullValue()));
}
use of org.parosproxy.paros.network.HttpSender in project zaproxy by zaproxy.
the class HttpPanelSender method getDelegate.
private HttpSender getDelegate() {
if (delegate == null) {
delegate = new HttpSender(Model.getSingleton().getOptionsParam().getConnectionParam(), getButtonUseTrackingSessionState().isSelected(), HttpSender.MANUAL_REQUEST_INITIATOR);
delegate.setUseCookies(getButtonUseCookies().isSelected());
}
return delegate;
}
use of org.parosproxy.paros.network.HttpSender in project zaproxy by zaproxy.
the class Spider method start.
/* SPIDER PROCESS maintenance - pause, resume, shutdown, etc. */
/**
* Starts the Spider crawling.
*/
public void start() {
log.info("Starting spider...");
this.timeStarted = System.currentTimeMillis();
fetchFilterSeeds();
// seeds and will not stop.
if (seedList == null || seedList.isEmpty()) {
log.warn("No seeds available for the Spider. Cancelling scan...");
notifyListenersSpiderComplete(false);
notifyListenersSpiderProgress(100, 0, 0);
return;
}
if (scanUser != null)
log.info("Scan will be performed from the point of view of User: " + scanUser.getName());
this.controller.init();
this.stopped = false;
this.paused = false;
this.initialized = false;
// Initialize the thread pool
this.threadPool = Executors.newFixedThreadPool(spiderParam.getThreadCount(), new SpiderThreadFactory("ZAP-SpiderThreadPool-" + id + "-thread-"));
// Initialize the HTTP sender
httpSender = new HttpSender(connectionParam, connectionParam.isHttpStateEnabled() ? true : !spiderParam.isAcceptCookies(), HttpSender.SPIDER_INITIATOR);
// Do not follow redirections because the request is not updated, the redirections will be
// handled manually.
httpSender.setFollowRedirect(false);
// Add the seeds
for (URI uri : seedList) {
if (log.isDebugEnabled()) {
log.debug("Adding seed for spider: " + uri);
}
controller.addSeed(uri, HttpRequestHeader.GET);
}
// Mark the process as completely initialized
initialized = true;
}
use of org.parosproxy.paros.network.HttpSender in project zaproxy by zaproxy.
the class CoreAPI method sendRequest.
private static void sendRequest(HttpMessage request, boolean followRedirects, Processor<HttpMessage> processor) throws IOException, ApiException {
HttpSender sender = null;
try {
sender = createHttpSender();
if (followRedirects) {
ModeRedirectionValidator redirector = new ModeRedirectionValidator(processor);
sender.sendAndReceive(request, HttpRequestConfig.builder().setRedirectionValidator(redirector).build());
if (!redirector.isRequestValid()) {
throw new ApiException(ApiException.Type.MODE_VIOLATION);
}
} else {
sender.sendAndReceive(request, false);
persistMessage(request);
processor.process(request);
}
} finally {
if (sender != null) {
sender.shutdown();
}
}
}
use of org.parosproxy.paros.network.HttpSender in project zaproxy by zaproxy.
the class AbstractPluginUnitTest method shouldSendMessageWithScanRuleIdHeaderIfEnabled.
@Test
void shouldSendMessageWithScanRuleIdHeaderIfEnabled() throws IOException {
// Given
AbstractPlugin plugin = createDefaultPlugin();
ScannerParam scannerParam = mock(ScannerParam.class);
given(scannerParam.isInjectPluginIdInHeader()).willReturn(true);
given(parent.getScannerParam()).willReturn(scannerParam);
HttpSender httpSender = mock(HttpSender.class);
given(parent.getHttpSender()).willReturn(httpSender);
plugin.init(message, parent);
HttpMessage message = new HttpMessage(new URI("http://example.com/", true));
// When
plugin.sendAndReceive(message, true, true);
// Then
assertThat(message.getRequestHeader().getHeader(HttpHeader.X_ZAP_SCAN_ID), is(equalTo("123456789")));
}
Aggregations