use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class IntegColoradoEdu method main.
public static void main(String[] args) throws InterruptedException {
boolean isHttp = true;
String host = "www.colorado.edu";
int port = 443;
if (isHttp)
port = 80;
Http2Request req = createRequest(host);
log.info("starting socket");
ChunkedResponseListener listener = new ChunkedResponseListener();
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = IntegSingleRequest.createHttpClient("oneTimerHttp2Socket", isHttp, addr);
socket.connect(addr).thenAccept(socet -> socket.openStream().process(req, listener)).exceptionally(e -> reportException(socket, e));
Thread.sleep(100000);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class Translations2 method translate.
public static HttpFullRequest translate(FullRequest request) {
// String scheme = request.getHeaders().getScheme();
Http2Request headers = request.getHeaders();
String authority = headers.getAuthority();
String path = headers.getPath();
String methodString = headers.getMethodString();
if (methodString == null)
throw new IllegalArgumentException("http2 :method header is required");
else if (authority == null) {
throw new IllegalArgumentException("http1 required host header so http2 message must have :authority header set");
}
HttpRequestLine reqLine = new HttpRequestLine();
reqLine.setUri(new HttpUri(path));
reqLine.setMethod(new HttpRequestMethod(methodString));
reqLine.setVersion(new HttpVersion());
HttpRequest httpReq = new HttpRequest();
httpReq.setRequestLine(reqLine);
DataWrapper data = request.getPayload();
// translate all other headers here as well...
for (Http2Header header : headers.getHeaders()) {
if (// All standard headers go elsewhere except HOST which we do below
!header.getName().startsWith(":"))
httpReq.addHeader(new Header(header.getName(), header.getValue()));
}
httpReq.addHeader(new Header(KnownHeaderName.HOST, authority));
HttpFullRequest req = new HttpFullRequest(httpReq, data);
return req;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ProxyRequestStreamHandle method process.
@Override
public StreamRef process(Http2Request request, ResponseStreamHandle responseListener) {
ProxyResponseStream proxyResponse = new ProxyResponseStream(responseListener, frontendSocket);
Map<String, Object> context = Context.copyContext();
// clear context so server uses a clean context
Context.restoreContext(new HashMap<>());
try {
StreamRef streamRef = stream.incomingRequest(request, proxyResponse);
return new MockProxyStreamRef(streamRef);
} finally {
// client still in this context
Context.restoreContext(context);
}
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ProxyStreamHandle method createBaseResponse.
@Override
public Http2Response createBaseResponse(Http2Request req, String mimeType, int statusCode, String statusReason) {
Http2Response response = responseCreator.addCommonHeaders2(req, mimeType, statusCode, statusReason);
// This is for streaming so set eos=false;
response.setEndOfStream(false);
return response;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ResponseCreator method createContentResponseImpl.
private ResponseEncodingTuple createContentResponseImpl(Http2Request request, int statusCode, String reason, boolean isDynamicPartOfWebsite, MimeTypeResult mimeType) {
Http2Response response = addCommonHeaders(request, mimeType.mime, isDynamicPartOfWebsite, statusCode, reason);
response.setEndOfStream(false);
response.addHeader(new Http2Header("reason", reason));
return new ResponseEncodingTuple(response, mimeType);
}
Aggregations