@Override public List<Cookie> cookies() { return req.cookies(); }
@Override public List<Upload> files(final String name) throws IOException { List<NativeUpload> files = req.files(name); List<Upload> uploads = files.stream() .map(upload -> new UploadImpl(injector, upload)) .collect(Collectors.toList()); return uploads; }
private static String method(final String methodParam, final NativeRequest request) throws Exception { Optional<String> header = request.header(methodParam); if (header.isPresent()) { return header.get(); } List<String> param = request.params(methodParam); return param.size() == 0 ? request.method() : param.get(0); }
String method = _method == null ? request.method() : method(_method, request); String path = normalizeURI(request.path()); if (rpath != null) { path = rpath.apply(path); Map<String, Object> nativeAttrs = request.attributes(); if (nativeAttrs.size() > 0) { locals.putAll(nativeAttrs); rendererMap, locals, req.charset(), request.header(REFERER), request.header(BYTE_RANGE)); Provider<Sse> sse = () -> Try.apply(() -> request.upgrade(Sse.class)).get(); scope.put(SSE, sse); Optional<WebSocket> sockets = findSockets(socketDefs, path); if (sockets.isPresent()) { NativeWebSocket ws = request.upgrade(NativeWebSocket.class); ws.onConnect(() -> ((WebSocketImpl) sockets.get()).connect(injector, req, ws)); return;
@Override public long length() { return req.header("Content-Length") .map(Long::parseLong) .orElse(-1L); }
private Mutant _header(final String name, final Function<String, String> xss) { requireNonNull(name, "Name required."); List<String> headers = req.headers(name); if (xss != null) { headers = headers.stream() .map(xss::apply) .collect(Collectors.toList()); } return new MutantImpl(require(ParserExecutor.class), new StrParamReferenceImpl("header", name, headers)); }
private List<String> paramNames() { try { return req.paramNames(); } catch (Exception ex) { throw new Err(Status.BAD_REQUEST, "Unable to get parameter names", ex); } }
@Override public Map<String, Mutant> headers() { Map<String, Mutant> headers = new LinkedHashMap<>(); req.headerNames().forEach(name -> headers.put(name, header(name))); return headers; }
@Override public String ip() { return req.ip(); }
@Override public Mutant body() throws Exception { long length = length(); if (length > 0) { MediaType type = type(); Config conf = require(Config.class); // TODO: sanitization of arguments File fbody = new File(conf.getString("application.tmpdir"), Integer.toHexString(System.identityHashCode(this))); files.add(fbody); int bufferSize = conf.getBytes("server.http.RequestBufferSize").intValue(); Parser.BodyReference body = new BodyReferenceImpl(length, charset(), fbody, req.in(), bufferSize); return new MutantImpl(require(ParserExecutor.class), type, body); } return new MutantImpl(require(ParserExecutor.class), type, new EmptyBodyReference()); }
String method = _method == null ? request.method() : method(_method, request); String path = normalizeURI(request.path()); if (rpath != null) { path = rpath.apply(path); Map<String, Object> nativeAttrs = request.attributes(); if (nativeAttrs.size() > 0) { locals.putAll(nativeAttrs); rendererMap, locals, req.charset(), request.header(REFERER), request.header(BYTE_RANGE)); Provider<Sse> sse = () -> Try.apply(() -> request.upgrade(Sse.class)).get(); scope.put(SSE, sse); Optional<WebSocket> sockets = findSockets(socketDefs, path); if (sockets.isPresent()) { NativeWebSocket ws = request.upgrade(NativeWebSocket.class); ws.onConnect(() -> ((WebSocketImpl) sockets.get()).connect(injector, req, ws)); return;
private boolean upgrade(final NativeRequest request) { Optional<String> upgrade = request.header(UPGRADE); return upgrade.isPresent() && upgrade.get().equalsIgnoreCase(WEB_SOCKET); }
private Mutant _header(final String name, final Function<String, String> xss) { requireNonNull(name, "Name required."); List<String> headers = req.headers(name); if (xss != null) { headers = headers.stream() .map(xss::apply) .collect(Collectors.toList()); } return new MutantImpl(require(ParserExecutor.class), new StrParamReferenceImpl("header", name, headers)); }
private List<String> paramNames() { try { return req.paramNames(); } catch (Exception ex) { throw new Err(Status.BAD_REQUEST, "Unable to get parameter names", ex); } }
@Override public Map<String, Mutant> headers() { Map<String, Mutant> headers = new LinkedHashMap<>(); req.headerNames().forEach(name -> headers.put(name, header(name))); return headers; }
@Override public String ip() { return req.ip(); }
@Override public Mutant body() throws Exception { long length = length(); if (length > 0) { MediaType type = type(); Config conf = require(Config.class); // TODO: sanitization of arguments File fbody = new File(conf.getString("application.tmpdir"), Integer.toHexString(System.identityHashCode(this))); files.add(fbody); int bufferSize = conf.getBytes("server.http.RequestBufferSize").intValue(); Parser.BodyReference body = new BodyReferenceImpl(length, charset(), fbody, req.in(), bufferSize); return new MutantImpl(require(ParserExecutor.class), type, body); } return new MutantImpl(require(ParserExecutor.class), type, new EmptyBodyReference()); }
private static String method(final String methodParam, final NativeRequest request) throws Exception { Optional<String> header = request.header(methodParam); if (header.isPresent()) { return header.get(); } List<String> param = request.params(methodParam); return param.size() == 0 ? request.method() : param.get(0); }
@Override public String hostname() { return req.header("host").map(host -> host.split(":")[0]).orElse(ip()); }
@Override public Mutant cookie(final String name) { List<String> values = req.cookies().stream().filter(c -> c.name().equalsIgnoreCase(name)) .findFirst() .map(cookie -> ImmutableList.of(cookie.value().get())) .orElse(ImmutableList.of()); return new MutantImpl(require(ParserExecutor.class), new StrParamReferenceImpl("cookie", name, values)); }