use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http2Requests method createTrailers.
public static Http2Trailers createTrailers(int streamId) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.SERVER, "trailing"));
Http2Trailers trailers = new Http2Trailers(headers);
trailers.setEndOfStream(true);
trailers.setStreamId(streamId);
return trailers;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ProxyHttpStream method incomingRequest.
@Override
public StreamRef incomingRequest(Http2Request request, ResponseStream stream) {
String expect = request.getSingleHeaderValue("Expect");
XFuture<StreamWriter> future = XFuture.completedFuture(null);
if (expect != null && "100-continue".equals(expect.toLowerCase())) {
Http2Response continueResponse = new Http2Response();
continueResponse.setEndOfStream(false);
continueResponse.addHeader(new Http2Header(Http2HeaderName.STATUS, "100"));
future = stream.process(continueResponse);
}
// This is only for streaming to backpressure clients IF we responded OR cancelled so we don't
// waste CPU on a client stream coming in
XFuture<ProxyWriter> futureWriter = new XFuture<>();
ProxyResponseStream proxy = new ProxyResponseStream(request, stream, futureWriter);
StreamRef streamRef = openStream.incomingRequest(request, proxy);
XFuture<StreamWriter> writer = future.thenCompose(w -> {
return createProxy(streamRef.getWriter(), futureWriter);
});
return new ProxyStreamRef(writer, streamRef);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class XFileReader method runFileRead.
public XFuture<Void> runFileRead(RequestInfo info, RenderStaticResponse renderStatic, ProxyStreamHandle handle) throws IOException {
VirtualFile fullFilePath = renderStatic.getFilePath();
if (!fullFilePath.exists()) {
throw new NotFoundException("File not found=" + fullFilePath);
} else if (fullFilePath.isDirectory()) {
throw new NotFoundException("File not found (it was a directory that can't be rendered)=" + fullFilePath);
}
String fileName = getNameToUse(fullFilePath);
String extension = null;
int lastDot = fileName.lastIndexOf(".");
if (lastDot > 0) {
extension = fileName.substring(lastDot + 1);
}
ResponseCreator.ResponseEncodingTuple tuple = responseCreator.createResponse(info.getRequest(), StatusCode.HTTP_200_OK, extension, "application/octet-stream", false);
Http2Response response = tuple.response;
// On startup, we protect developers from breaking clients. In http, all files that change
// must also change the hash automatically and the %%{ }%% tag generates those hashes so the
// files loaded are always the latest
Long timeSeconds = config.getStaticFileCacheTimeSeconds();
if (timeSeconds != null)
response.addHeader(new Http2Header(Http2HeaderName.CACHE_CONTROL, "max-age=" + timeSeconds));
ChunkReader reader = createFileReader(response, renderStatic, fileName, fullFilePath, info, extension, tuple, handle);
if (log.isDebugEnabled())
log.debug("sending chunked file via async read=" + reader);
ProxyStreamHandle stream = info.getResponseSender();
return futureUtil.finallyBlock(() -> stream.process(response).thenCompose(s -> readLoop(s, info.getPool(), reader, 0)), () -> handleClose(info, reader));
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class CompressionChunkingHandle method checkForCompression.
private Compression checkForCompression(Http2Response response) {
if (routerRequest == null) {
// as that is what the client accepts for compression
return new NoCompression();
}
if (compressionOff) {
// a file that is already compressed. In this case, don't compress on top of their cached compression
return new NoCompression();
}
Http2Header header = response.getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
String contentType = response.getSingleHeaderValue(Http2HeaderName.CONTENT_TYPE);
if (// could be a redirect or something with 0 bytes anyways or we don't know what it is so don't compress
contentType == null)
return new NoCompression();
MimeTypes.MimeTypeResult mimeType = mimeTypes.createMimeType(header.getValue());
Compression compression = compressionLookup.createCompressionStream(routerRequest.encodings, mimeType);
if (compression == null) {
return new NoCompression();
} else {
response.addHeader(new Http2Header(Http2HeaderName.CONTENT_ENCODING, compression.getCompressionType()));
return compression;
}
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class EScopedRouter method send403Response.
private void send403Response(ProxyStreamHandle handler, String reason) {
Http2Response response = new Http2Response();
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
response.addHeader(new Http2Header("Webpieces-Reason", reason));
XFuture<StreamWriter> process = handler.process(response);
try {
process.get(10, TimeUnit.SECONDS);
} catch (Exception e) {
throw SneakyThrow.sneak(e);
}
}
Aggregations