use of org.eclipse.jetty.server.Request in project jphp by jphp-compiler.
the class PHttpGzipFilter method __invoke.
@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws IOException, ServletException {
Request baseRequest = Request.getBaseRequest(request.getRequest());
gzipHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse());
}
use of org.eclipse.jetty.server.Request in project jphp by jphp-compiler.
the class PHttpResourceHandler method __invoke.
@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws Exception {
final boolean[] once = { false };
ResourceHandler resourceHandler = new ResourceHandler() {
@Override
public Resource getResource(String path) {
if (!once[0]) {
once[0] = true;
Object attr = request.getRequest().getAttribute("**");
File file;
if (attr != null) {
file = new File(PHttpResourceHandler.this.file, "/" + attr);
} else {
file = new File(PHttpResourceHandler.this.file);
}
if (file.exists()) {
return new PathResource(file.getAbsoluteFile());
} else {
return null;
}
} else {
return null;
}
}
};
resourceHandler.doStart();
resourceHandler.setResourceBase(file());
if (cacheControl() != null) {
resourceHandler.setCacheControl(cacheControl());
}
resourceHandler.setRedirectWelcome(redirectWelcome());
resourceHandler.setPathInfoOnly(pathInfoOnly());
resourceHandler.setDirectoriesListed(directoriesListed());
resourceHandler.setDirAllowed(dirAllowed());
resourceHandler.setAcceptRanges(acceptRanges());
resourceHandler.setEtags(etags());
Request baseRequest = Request.getBaseRequest(request.getRequest());
resourceHandler.handle(request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse());
}
use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.
the class RedirectTest method setUpGlobal.
@BeforeClass
@Override
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector1 = addHttpConnector(server);
ServerConnector connector2 = addHttpConnector(server);
HandlerList list = new HandlerList();
list.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
if (request.getLocalPort() == port2) {
httpServletResponse.sendRedirect(getTargetUrl());
}
}
});
list.addHandler(configureHandler());
server.setHandler(list);
server.start();
port1 = connector1.getLocalPort();
port2 = connector2.getLocalPort();
logger.info("Local HTTP server started successfully");
}
use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.
the class NonAsciiContentLengthTest method setUpGlobal.
@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
server.setHandler(new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
// Can only handle bodies of up to 1024 bytes.
int MAX_BODY_SIZE = 1024;
byte[] b = new byte[MAX_BODY_SIZE];
int offset = 0;
int numBytesRead;
try (ServletInputStream is = request.getInputStream()) {
while ((numBytesRead = is.read(b, offset, MAX_BODY_SIZE - offset)) != -1) {
offset += numBytesRead;
}
}
assertEquals(request.getContentLength(), offset);
response.setStatus(200);
response.setCharacterEncoding(request.getCharacterEncoding());
response.setContentLength(request.getContentLength());
try (ServletOutputStream os = response.getOutputStream()) {
os.write(b, 0, offset);
}
}
});
server.start();
port1 = connector.getLocalPort();
}
use of org.eclipse.jetty.server.Request in project async-http-client by AsyncHttpClient.
the class AsyncStreamLifecycleTest method configureHandler.
@Override
public AbstractHandler configureHandler() throws Exception {
return new AbstractHandler() {
public void handle(String s, Request request, HttpServletRequest req, final HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain;charset=utf-8");
resp.setStatus(200);
final AsyncContext asyncContext = request.startAsync();
final PrintWriter writer = resp.getWriter();
executorService.submit(() -> {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
logger.error("Failed to sleep for 100 ms.", e);
}
logger.info("Delivering part1.");
writer.write("part1");
writer.flush();
});
executorService.submit(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
logger.error("Failed to sleep for 200 ms.", e);
}
logger.info("Delivering part2.");
writer.write("part2");
writer.flush();
asyncContext.complete();
});
request.setHandled(true);
}
};
}
Aggregations