Search in sources :

Example 6 with Header

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

the class HttpParserImpl method marshalToBytes.

public byte[] marshalToBytes(MarshalState s, HttpPayload payload) {
    MarshalStateImpl state = (MarshalStateImpl) s;
    if (state.getParsingDataSize() != null) {
        return parseData(state, payload);
    } else if (payload.getMessageType() == HttpMessageType.CHUNK || payload.getMessageType() == HttpMessageType.LAST_CHUNK) {
        return chunkedBytes((HttpChunk) payload);
    }
    HttpMessage msg = (HttpMessage) payload;
    String result = marshalHeaders(payload);
    Header header = msg.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    if (header != null && !header.getValue().equals("0")) {
        String value = header.getValue();
        int lengthOfBodyFromHeader = toInteger(value, "" + header);
        state.setParsingDataSize(lengthOfBodyFromHeader);
    }
    byte[] stringPiece = result.getBytes(iso8859_1);
    return stringPiece;
}
Also used : Header(org.webpieces.httpparser.api.common.Header) HttpMessage(org.webpieces.httpparser.api.dto.HttpMessage) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk)

Example 7 with Header

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

the class HeaderPriorityParserImpl method parseAcceptLangFromRequest.

@Override
public List<Locale> parseAcceptLangFromRequest(HttpRequest req) {
    Header langHeader = req.getHeaderLookupStruct().getHeader(KnownHeaderName.ACCEPT_LANGUAGE);
    if (langHeader == null)
        return new ArrayList<>();
    List<Locale> headerItems = parsePriorityItems(langHeader.getValue(), s -> parseItem(s));
    return headerItems;
}
Also used : Locale(java.util.Locale) Header(org.webpieces.httpparser.api.common.Header)

Example 8 with Header

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

the class HeaderPriorityParserImpl method parseAcceptFromRequest.

@Override
public List<AcceptType> parseAcceptFromRequest(HttpRequest req) {
    List<AcceptType> list = new ArrayList<>();
    Header header = req.getHeaderLookupStruct().getHeader(KnownHeaderName.ACCEPT);
    if (header == null)
        return list;
    String value = header.getValue();
    return parsePriorityItems(value, s -> parseAcceptSubitem(s));
}
Also used : Header(org.webpieces.httpparser.api.common.Header) ArrayList(java.util.ArrayList) AcceptType(org.webpieces.httpparser.api.subparsers.AcceptType)

Example 9 with Header

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

the class TestChunkedParsing method create400Response.

static HttpResponse create400Response() {
    Header header1 = new Header();
    header1.setName(KnownHeaderName.AGE);
    header1.setValue("CooolValue");
    HttpResponseStatus status = new HttpResponseStatus();
    status.setKnownStatus(KnownStatusCode.HTTP_400_BADREQUEST);
    HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
    statusLine.setStatus(status);
    HttpResponse resp = new HttpResponse();
    resp.setStatusLine(statusLine);
    resp.addHeader(header1);
    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 10 with Header

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

the class IntegColoradoEdu method createRequest.

private static HttpRequest createRequest(String host) {
    //		GET / HTTP/1.1
    //		Host: www.colorado.edu
    //		User-Agent: curl/7.43.0
    //		Accept: */*
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri("/"));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, host));
    req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
    req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

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