Search in sources :

Example 6 with HttpRequestHeader

use of org.parosproxy.paros.network.HttpRequestHeader in project zaproxy by zaproxy.

the class FilterIfModifiedSince method onHttpRequestSend.

@Override
public void onHttpRequestSend(HttpMessage httpMessage) {
    HttpRequestHeader reqHeader = httpMessage.getRequestHeader();
    if (!reqHeader.isEmpty() && reqHeader.isText()) {
        String ifModifed = reqHeader.getHeader(HttpHeader.IF_MODIFIED_SINCE);
        if (ifModifed != null) {
            reqHeader.setHeader(HttpHeader.IF_MODIFIED_SINCE, null);
        }
        String ifNoneMatch = reqHeader.getHeader(HttpHeader.IF_NONE_MATCH);
        if (ifNoneMatch != null) {
            reqHeader.setHeader(HttpHeader.IF_NONE_MATCH, null);
        }
    }
}
Also used : HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader)

Example 7 with HttpRequestHeader

use of org.parosproxy.paros.network.HttpRequestHeader in project zaproxy by zaproxy.

the class FilterLogCookie method onHttpRequestSend.

@Override
public void onHttpRequestSend(HttpMessage msg) {
    HttpRequestHeader header = msg.getRequestHeader();
    if (header != null) {
        String cookie = header.getHeader("Cookie");
        synchronized (cookieList) {
            if (cookie != null && cookieList.indexOf(cookie) == -1) {
                try {
                    // ZAP: catch CloneNotSupportedException as introduced with version 3.1 of HttpClient
                    URI uri;
                    try {
                        uri = (URI) header.getURI().clone();
                    } catch (CloneNotSupportedException e) {
                        throw new URIException(e.getMessage());
                    }
                    uri.setQuery(null);
                    String sUri = uri.toString();
                    cookieList.add(cookie);
                    getView().getOutputPanel().append(sUri + DELIM + cookie + "\n");
                } catch (URIException e) {
                    // ZAP: Print stack trace to Output tab
                    getView().getOutputPanel().append(e);
                }
            }
        }
    }
}
Also used : URIException(org.apache.commons.httpclient.URIException) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI)

Example 8 with HttpRequestHeader

use of org.parosproxy.paros.network.HttpRequestHeader in project zaproxy by zaproxy.

the class FilterLogGetQuery method onHttpRequestSend.

@Override
public void onHttpRequestSend(HttpMessage httpMessage) {
    HttpRequestHeader reqHeader = httpMessage.getRequestHeader();
    if (reqHeader != null && reqHeader.isText() && !reqHeader.isImage()) {
        if (reqHeader.getMethod().equalsIgnoreCase(HttpRequestHeader.GET)) {
            try {
                URI uri = reqHeader.getURI();
                // ZAP: Removed unused variable (int pos).
                String firstline;
                URI newURI = (URI) uri.clone();
                String query = newURI.getQuery();
                if (query != null) {
                    newURI.setQuery(null);
                    firstline = newURI.toString();
                    // ZAP: Added type arguments.
                    Hashtable<String, String> param = parseParameter(query);
                    writeLogFile(firstline, param);
                } else {
                    firstline = uri.toString();
                    writeLogFile(firstline, null);
                }
            } catch (Exception aa) {
                logger.error(aa.getMessage(), aa);
            }
        }
    }
}
Also used : HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) URI(org.apache.commons.httpclient.URI) IOException(java.io.IOException)

Example 9 with HttpRequestHeader

use of org.parosproxy.paros.network.HttpRequestHeader in project zaproxy by zaproxy.

the class FilterZapRequestId method onHttpRequestSend.

@Override
public void onHttpRequestSend(HttpMessage httpMessage) {
    HttpRequestHeader rhead = httpMessage.getRequestHeader();
    if (rhead.getHeader(HttpHeader.X_ZAP_REQUESTID) == null) {
        String sessname = "zap-session";
        try {
            sessname = URLEncoder.encode(model.getSession().getSessionName(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            log.error("UTF8 is not supported?! Using fallback session name.", e);
        }
        rhead.addHeader(HttpHeader.X_ZAP_REQUESTID, sessname + "-" + Long.toString(requestCounter.getAndIncrement()));
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader)

Example 10 with HttpRequestHeader

use of org.parosproxy.paros.network.HttpRequestHeader in project zaproxy by zaproxy.

the class HarUtils method createHttpMessage.

public static HttpMessage createHttpMessage(HarRequest harRequest) throws HttpMalformedHeaderException {
    StringBuilder strBuilderReqHeader = new StringBuilder();
    strBuilderReqHeader.append(harRequest.getMethod()).append(' ').append(harRequest.getUrl()).append(' ').append(harRequest.getHttpVersion()).append("\r\n");
    for (HarHeader harHeader : harRequest.getHeaders().getHeaders()) {
        strBuilderReqHeader.append(harHeader.getName()).append(": ").append(harHeader.getValue()).append("\r\n");
    }
    strBuilderReqHeader.append("\r\n");
    StringBuilder strBuilderReqBody = new StringBuilder();
    final HarPostData harPostData = harRequest.getPostData();
    if (harPostData != null) {
        final String text = harPostData.getText();
        if (text != null && !text.isEmpty()) {
            strBuilderReqBody.append(harRequest.getPostData().getText());
        } else if (harPostData.getParams() != null && !harPostData.getParams().getPostDataParams().isEmpty()) {
            for (HarPostDataParam param : harRequest.getPostData().getParams().getPostDataParams()) {
                if (strBuilderReqBody.length() > 0) {
                    strBuilderReqBody.append('&');
                }
                strBuilderReqBody.append(param.getName()).append('=').append(param.getValue());
            }
        }
    }
    return new HttpMessage(new HttpRequestHeader(strBuilderReqHeader.toString()), new HttpRequestBody(strBuilderReqBody.toString()));
}
Also used : HarPostData(edu.umass.cs.benchlab.har.HarPostData) HttpRequestBody(org.zaproxy.zap.network.HttpRequestBody) HarHeader(edu.umass.cs.benchlab.har.HarHeader) HarQueryString(edu.umass.cs.benchlab.har.HarQueryString) HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpRequestHeader(org.parosproxy.paros.network.HttpRequestHeader) HarPostDataParam(edu.umass.cs.benchlab.har.HarPostDataParam)

Aggregations

HttpRequestHeader (org.parosproxy.paros.network.HttpRequestHeader)15 URI (org.apache.commons.httpclient.URI)8 HttpMessage (org.parosproxy.paros.network.HttpMessage)6 IOException (java.io.IOException)3 URIException (org.apache.commons.httpclient.URIException)3 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)3 HarPostData (edu.umass.cs.benchlab.har.HarPostData)2 HarPostDataParam (edu.umass.cs.benchlab.har.HarPostDataParam)2 HarQueryString (edu.umass.cs.benchlab.har.HarQueryString)2 HttpRequestBody (org.zaproxy.zap.network.HttpRequestBody)2 HarCookie (edu.umass.cs.benchlab.har.HarCookie)1 HarCookies (edu.umass.cs.benchlab.har.HarCookies)1 HarHeader (edu.umass.cs.benchlab.har.HarHeader)1 HarPostDataParams (edu.umass.cs.benchlab.har.HarPostDataParams)1 HarQueryParam (edu.umass.cs.benchlab.har.HarQueryParam)1 HarRequest (edu.umass.cs.benchlab.har.HarRequest)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HttpCookie (java.net.HttpCookie)1