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;
}
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;
}
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));
}
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;
}
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;
}
Aggregations