Search in sources :

Example 1 with HttpHeaderField

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

the class VariantHeader method setMessage.

/**
     * @throws IllegalArgumentException if {@code message} is {@code null}.
     */
@Override
public void setMessage(HttpMessage message) {
    if (message == null) {
        throw new IllegalArgumentException("Parameter message must not be null.");
    }
    ArrayList<NameValuePair> extractedParameters = new ArrayList<>();
    List<HttpHeaderField> httpHeaders = message.getRequestHeader().getHeaders();
    for (HttpHeaderField header : httpHeaders) {
        if (!NON_INJECTABLE_HEADERS.contains(header.getName().toLowerCase(Locale.ROOT))) {
            extractedParameters.add(new NameValuePair(NameValuePair.TYPE_HEADER, header.getName(), header.getValue(), extractedParameters.size()));
        }
    }
    if (extractedParameters.isEmpty()) {
        params = Collections.emptyList();
    } else {
        extractedParameters.trimToSize();
        params = Collections.unmodifiableList(extractedParameters);
    }
}
Also used : HttpHeaderField(org.parosproxy.paros.network.HttpHeaderField) ArrayList(java.util.ArrayList)

Example 2 with HttpHeaderField

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

the class HarUtils method createHarHeaders.

public static HarHeaders createHarHeaders(HttpHeader httpHeader) {
    HarHeaders harHeaders = new HarHeaders();
    List<HttpHeaderField> headers = httpHeader.getHeaders();
    for (HttpHeaderField headerField : headers) {
        harHeaders.addHeader(new HarHeader(headerField.getName(), headerField.getValue()));
    }
    return harHeaders;
}
Also used : HttpHeaderField(org.parosproxy.paros.network.HttpHeaderField) HarHeaders(edu.umass.cs.benchlab.har.HarHeaders) HarHeader(edu.umass.cs.benchlab.har.HarHeader)

Example 3 with HttpHeaderField

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

the class VariantHeaderUnitTest method containsHeader.

private static Matcher<HttpMessage> containsHeader(final String name, final String value) {
    return new BaseMatcher<HttpMessage>() {

        @Override
        public boolean matches(Object actualValue) {
            HttpMessage message = (HttpMessage) actualValue;
            List<HttpHeaderField> headers = message.getRequestHeader().getHeaders();
            if (headers.isEmpty()) {
                return false;
            }
            for (HttpHeaderField header : headers) {
                if (name.equals(header.getName()) && value.equals(header.getValue())) {
                    return true;
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("header ").appendValue(name + ": " + value);
        }

        public void describeMismatch(Object item, Description description) {
            HttpMessage message = (HttpMessage) item;
            List<HttpHeaderField> headers = message.getRequestHeader().getHeaders();
            if (headers.isEmpty()) {
                description.appendText("has no headers");
            } else {
                description.appendText("was ").appendValue(headers);
            }
        }
    };
}
Also used : HttpHeaderField(org.parosproxy.paros.network.HttpHeaderField) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) HttpMessage(org.parosproxy.paros.network.HttpMessage)

Aggregations

HttpHeaderField (org.parosproxy.paros.network.HttpHeaderField)3 HarHeader (edu.umass.cs.benchlab.har.HarHeader)1 HarHeaders (edu.umass.cs.benchlab.har.HarHeaders)1 ArrayList (java.util.ArrayList)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1 HttpMessage (org.parosproxy.paros.network.HttpMessage)1