use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class CustomScanDialog method populateRequestField.
private void populateRequestField(SiteNode node) {
try {
if (node == null || node.getHistoryReference() == null || node.getHistoryReference().getHttpMessage() == null) {
this.getRequestField().setText("");
} else {
// Populate the custom vectors http pane
HttpMessage msg = node.getHistoryReference().getHttpMessage();
String header = msg.getRequestHeader().toString();
StringBuilder sb = new StringBuilder();
sb.append(header);
this.headerLength = header.length();
// Ignore <METHOD> http(s)://host:port/
this.urlPathStart = header.indexOf("/", header.indexOf("://") + 2) + 1;
sb.append(msg.getRequestBody().toString());
this.getRequestField().setText(sb.toString());
// Only set the recurse option if the node has children, and disable it otherwise
JCheckBox recurseChk = (JCheckBox) this.getField(FIELD_RECURSE);
recurseChk.setEnabled(node.getChildCount() > 0);
recurseChk.setSelected(node.getChildCount() > 0);
}
this.setFieldStates();
} catch (HttpMalformedHeaderException | DatabaseException e) {
//
this.getRequestField().setText("");
}
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class View method displayMessage.
/**
* {@inheritDoc}
* <p>
* <strong>Note:</strong> Current implementation just supports {@link HttpMessage HTTP messages}. Attempting to display
* other message types has no effect.
*/
@Override
public void displayMessage(Message message) {
if (message == null) {
getRequestPanel().clearView(true);
getResponsePanel().clearView(false);
return;
}
if (!(message instanceof HttpMessage)) {
logger.warn("Unable to display message: " + message.getClass().getCanonicalName());
return;
}
HttpMessage httpMessage = (HttpMessage) message;
if (httpMessage.getRequestHeader().isEmpty()) {
getRequestPanel().clearView(true);
} else {
getRequestPanel().setMessage(httpMessage);
}
if (httpMessage.getResponseHeader().isEmpty()) {
getResponsePanel().clearView(false);
} else {
getResponsePanel().setMessage(httpMessage, true);
}
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class SessionStructure method addStructure.
private static RecordStructure addStructure(Session session, String host, HttpMessage msg, List<String> paths, int size, int historyId) throws DatabaseException, URIException {
//String nodeUrl = pathsToUrl(host, paths, size);
String nodeName = getNodeName(session, host, msg, paths, size);
String parentName = pathsToUrl(host, paths, size - 1);
String url = "";
if (msg != null) {
url = msg.getRequestHeader().getURI().toString();
String params = getParams(session, msg);
if (params.length() > 0) {
nodeName = nodeName + " " + params;
}
}
String method = HttpRequestHeader.GET;
if (msg != null) {
method = msg.getRequestHeader().getMethod();
}
RecordStructure msgRs = Model.getSingleton().getDb().getTableStructure().find(session.getSessionId(), nodeName, method);
if (msgRs == null) {
long parentId = -1;
if (!nodeName.equals("Root")) {
HttpMessage tmpMsg = null;
int parentHistoryId = -1;
if (!parentName.equals("Root")) {
tmpMsg = getTempHttpMessage(session, parentName, msg);
parentHistoryId = tmpMsg.getHistoryRef().getHistoryId();
}
RecordStructure parentRs = addStructure(session, host, tmpMsg, paths, size - 1, parentHistoryId);
parentId = parentRs.getStructureId();
}
msgRs = Model.getSingleton().getDb().getTableStructure().insert(session.getSessionId(), parentId, historyId, nodeName, url, method);
}
return msgRs;
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class SpiderTextParserUnitTest method shouldNotParseTextResponseIfAlreadyParsed.
@Test
public void shouldNotParseTextResponseIfAlreadyParsed() {
// Given
SpiderTextParser spiderParser = new SpiderTextParser();
HttpMessage messageHtmlResponse = createMessageWith(EMPTY_BODY);
boolean parsed = true;
// When
boolean canParse = spiderParser.canParseResource(messageHtmlResponse, ROOT_PATH, parsed);
// Then
assertThat(canParse, is(equalTo(false)));
}
use of org.parosproxy.paros.network.HttpMessage in project zaproxy by zaproxy.
the class SpiderTextParserUnitTest method createMessageWith.
private static HttpMessage createMessageWith(String statusCodeMessage, String contentType, String body) {
HttpMessage message = new HttpMessage();
try {
message.setRequestHeader("GET / HTTP/1.1\r\nHost: example.com\r\n");
message.setResponseHeader("HTTP/1.1 " + statusCodeMessage + "\r\n" + "Content-Type: " + contentType + "; charset=UTF-8\r\n" + "Content-Length: " + body.length());
message.setResponseBody(body);
} catch (Exception e) {
throw new RuntimeException(e);
}
return message;
}
Aggregations