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