use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ErrorCommonTest method testGetNotMatchPostRoute.
@Test
public void testGetNotMatchPostRoute() {
log.info("starting");
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/postroute");
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
verifyNotFoundRendered(response, contents);
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class RequestCreation method createHttpRequest.
public static Http2Request createHttpRequest(HttpMethod method, String path) {
Http2Request req = new Http2Request();
req.addHeader(new Http2Header(Http2HeaderName.METHOD, method.getCode()));
req.addHeader(new Http2Header(Http2HeaderName.PATH, path));
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "orderly.com"));
return req;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestProdRouter method testAsyncRouteAndMocking.
/**
* This test won't work in DevRoute right now as we need to do the following
* 1. create CompileOnDemand very early on
* 2. do a Thread.current().setContextClassLoader(compileOnDemand.getLatestClassloader())
*
* and this all needs to be done BEFORE TestModule is created and more importantly before
* the bind(SomeService.class) as SomeService will be loaded from one classloader and then
* when DEVrouter creates the controller, the compileOnDemand classloader is used resulting
* in a mismatch.
*/
@Test
public void testAsyncRouteAndMocking() {
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/async");
// setup returning a response
XFuture<Integer> future1 = new XFuture<Integer>();
overrides.mockService.addToReturn(future1);
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertFalse(future.isDone());
// no response yet...
Assert.assertNull(mockStream.getLastResponse());
// release controlleer
int id = 78888;
future1.complete(id);
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response resp = mockStream.getLastResponse();
Assert.assertNull(resp.getSingleHeaderValue(Http2HeaderName.AUTHORITY));
Assert.assertEquals("http://" + req.getAuthority() + "/meeting/" + id, resp.getSingleHeaderValue(Http2HeaderName.LOCATION));
// We did not send a keep alive so it should close
Assert.assertTrue(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class DefaultCorsProcessor method send403Response.
private void send403Response(ResponseStreamHandle responseStream, Http2Request request) {
Http2Response response = new Http2Response();
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
sendResponse(responseStream, response);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class HttpsJsonClient method createCurl2.
private String createCurl2(int port, Http2Request req, Supplier<String> supplier) {
String s = "";
s += "\n\n************************************************************\n";
s += " CURL REQUEST\n";
s += "***************************************************************\n";
s += "curl -k --request " + req.getKnownMethod().getCode() + " ";
for (Http2Header header : req.getHeaders()) {
if (header.getName().startsWith(":")) {
// base headers we can discard
continue;
}
s += "-H \"" + header.getName() + ":" + header.getValue() + "\" ";
}
String host = req.getSingleHeaderValue(Http2HeaderName.AUTHORITY);
String path = req.getSingleHeaderValue(Http2HeaderName.PATH);
s += supplier.get();
s += " \"https://" + host + ":" + port + path + "\"\n";
s += "***************************************************************\n";
return s;
}
Aggregations