use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http11ToHttp2 method requestToHeaders.
private static Http2Request requestToHeaders(HttpRequest request, boolean fromSslChannel) {
HttpRequestLine requestLine = request.getRequestLine();
List<Header> requestHeaders = request.getHeaders();
LinkedList<Http2Header> headerList = new LinkedList<>();
// add special headers
headerList.add(new Http2Header(":method", requestLine.getMethod().getMethodAsString()));
UrlInfo urlInfo = requestLine.getUri().getUriBreakdown();
headerList.add(new Http2Header(":path", requestLine.getUri().getUri()));
// Figure out scheme
if (urlInfo.getPrefix() != null) {
headerList.add(new Http2Header(":scheme", urlInfo.getPrefix()));
} else if (fromSslChannel) {
headerList.add(new Http2Header(":scheme", "https"));
} else {
headerList.add(new Http2Header(":scheme", "http"));
}
// Figure out authority
Header hostHeader = request.getHeaderLookupStruct().getHeader(KnownHeaderName.HOST);
if (hostHeader == null)
throw new IllegalArgumentException("Host header is required in http1.1");
// Add regular headers
for (Header header : requestHeaders) {
if (header.getKnownName() == KnownHeaderName.HOST) {
// keeps headers in order of http1 headers
String h = hostHeader.getValue();
headerList.add(new Http2Header(":authority", h));
continue;
}
headerList.add(new Http2Header(header.getName().toLowerCase(), header.getValue()));
}
Http2Request headers = new Http2Request(headerList);
Header contentLen = request.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (request.isHasChunkedTransferHeader()) {
headers.setEndOfStream(false);
} else if (contentLenGreaterThanZero(contentLen)) {
headers.setEndOfStream(false);
} else
headers.setEndOfStream(true);
return headers;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http11ToHttp2 method responseToHeaders.
public static Http2Response responseToHeaders(HttpResponse response) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.STATUS, response.getStatusLine().getStatus().getCode().toString()));
for (Header header : response.getHeaders()) {
if (header.getKnownName() == KnownHeaderName.TRANSFER_ENCODING) {
if ("chunked".equals(header.getValue())) {
// skip as http2 does not allow this header
continue;
}
}
headers.add(new Http2Header(header.getName(), header.getValue()));
}
Http2Response resp = new Http2Response(headers);
Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (header != null) {
int len = Integer.parseInt(header.getValue());
if (len == 0) {
resp.setEndOfStream(true);
} else {
resp.setEndOfStream(false);
}
} else if (response.isHasChunkedTransferHeader()) {
resp.setEndOfStream(false);
} else
resp.setEndOfStream(true);
return resp;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HeaderEncoding method translateToFrames.
public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Headers headers) {
HeadersFrame frame = new HeadersFrame();
frame.setStreamId(headers.getStreamId());
frame.setEndOfStream(headers.isEndOfStream());
frame.setPriorityDetails(headers.getPriorityDetails());
List<Http2Header> headerList = headers.getHeaders();
List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
return headerFrames;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HeaderEncoding method translateToFrames.
public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Push p) {
PushPromiseFrame frame = new PushPromiseFrame();
frame.setStreamId(p.getStreamId());
frame.setPromisedStreamId(p.getPromisedStreamId());
List<Http2Header> headerList = p.getHeaders();
List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
return headerFrames;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http2ToHttp11 method translateResponse.
public static HttpResponse translateResponse(Http2Response headers) {
HttpResponseStatus status = new HttpResponseStatus();
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse response = new HttpResponse();
response.setStatusLine(statusLine);
for (Http2Header header : headers.getHeaders()) {
if (header.getKnownName() == Http2HeaderName.STATUS) {
fillStatus(header, status);
} else if ("reason".equals(header.getName())) {
fillReason(header, status);
} else if (header.getKnownName() == Http2HeaderName.SCHEME) {
// do nothing and drop it
} else {
Header http1Header = convertHeader(header);
response.addHeader(http1Header);
}
}
if (headers.getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_LENGTH) == null) {
if (headers.isEndOfStream()) {
// firefox really needs content length!!! if end of stream
response.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
} else {
response.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
}
}
if (status.getCode() == null)
throw new IllegalArgumentException("The header :status is required to send the response");
// Do a queue instead with last few frames that can be enabled
log.debug("response=" + response);
return response;
}
Aggregations