Search in sources :

Example 46 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class HttpParserImpl method parseHeader.

private Header parseHeader(String line) {
    //can't use split in case there are two ':' ...one in the value and one as the delimeter
    int indexOf = line.indexOf(":");
    if (indexOf < 0)
        throw new IllegalArgumentException("bad header line=" + line);
    String value = line.substring(indexOf + 1).trim();
    String name = line.substring(0, indexOf);
    Header header = new Header();
    header.setName(name.trim());
    header.setValue(value.trim());
    return header;
}
Also used : Header(org.webpieces.httpparser.api.common.Header)

Example 47 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class TestRequestParsing method createPostRequest.

static HttpRequest createPostRequest() {
    Header header1 = new Header();
    header1.setName(KnownHeaderName.ACCEPT);
    header1.setValue("CooolValue");
    Header header2 = new Header();
    //let's keep the case even though name is case-insensitive..
    header2.setName("CustomerHEADER");
    header2.setValue("betterValue");
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.POST);
    requestLine.setUri(new HttpUri("http://myhost.com"));
    HttpRequest request = new HttpRequest();
    request.setRequestLine(requestLine);
    request.addHeader(header1);
    request.addHeader(header2);
    return request;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Header(org.webpieces.httpparser.api.common.Header) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 48 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class TestResponseParsing method createOkResponse.

static HttpResponse createOkResponse() {
    Header header1 = new Header();
    header1.setName(KnownHeaderName.ACCEPT);
    header1.setValue("CooolValue");
    Header header2 = new Header();
    //let's keep the case even though name is case-insensitive..
    header2.setName("CustomerHEADER");
    header2.setValue("betterValue");
    HttpResponseStatus status = new HttpResponseStatus();
    status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
    HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
    statusLine.setStatus(status);
    HttpResponse resp = new HttpResponse();
    resp.setStatusLine(statusLine);
    resp.addHeader(header1);
    resp.addHeader(header2);
    return resp;
}
Also used : Header(org.webpieces.httpparser.api.common.Header) HttpResponseStatus(org.webpieces.httpparser.api.dto.HttpResponseStatus) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpResponseStatusLine(org.webpieces.httpparser.api.dto.HttpResponseStatusLine)

Example 49 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class MockTcpChannel method hasValidContentLength.

private boolean hasValidContentLength(HttpResponse response) {
    Integer contentLen = null;
    Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    if (header != null) {
        contentLen = Integer.parseInt(header.getValue());
    }
    if (contentLen != null && contentLen > 0)
        return true;
    return false;
}
Also used : Header(org.webpieces.httpparser.api.common.Header)

Example 50 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class FullResponse method extractCharset.

private Charset extractCharset() {
    Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_TYPE);
    if (header == null)
        throw new IllegalArgumentException("no ContentType header could be found");
    ContentType ct = ContentType.parse(header);
    Charset charset = DEFAULT_CHARSET;
    if (ct.getCharSet() != null)
        charset = Charset.forName(ct.getCharSet());
    return charset;
}
Also used : Header(org.webpieces.httpparser.api.common.Header) ContentType(org.webpieces.httpparser.api.dto.ContentType) Charset(java.nio.charset.Charset)

Aggregations

Header (org.webpieces.httpparser.api.common.Header)64 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)32 Test (org.junit.Test)24 DataWrapper (org.webpieces.data.api.DataWrapper)18 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)16 FullResponse (org.webpieces.webserver.test.FullResponse)16 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)13 WebserverForTest (org.webpieces.webserver.WebserverForTest)12 HttpData (org.webpieces.httpparser.api.dto.HttpData)11 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)10 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)10 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)10 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)9 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)9 Http2Response (com.webpieces.hpack.api.dto.Http2Response)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)7 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)7 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)5 HttpResponseStatus (org.webpieces.httpparser.api.dto.HttpResponseStatus)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4