@Override public long length() { return req.header("Content-Length") .map(Long::parseLong) .orElse(-1L); }
private boolean upgrade(final NativeRequest request) { Optional<String> upgrade = request.header(UPGRADE); return upgrade.isPresent() && upgrade.get().equalsIgnoreCase(WEB_SOCKET); }
@Override public String hostname() { return req.header("host").map(host -> host.split(":")[0]).orElse(ip()); }
@Override public int port() { return req.header("host").map(host -> { String[] parts = host.split(":"); if (parts.length > 1) { return Integer.parseInt(parts[1]); } // fallback to default ports return secure() ? 443 : 80; }).orElse(port); }
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); }
public RequestImpl(final Injector injector, final NativeRequest req, final String contextPath, final int port, final Route route, final Charset charset, final List<Locale> locales, final Map<Object, Object> scope, final Map<String, Object> locals, final long timestamp) { this.injector = injector; this.req = req; this.route = route; this.scope = scope; this.locals = locals; this.contextPath = contextPath; Optional<String> accept = req.header("Accept"); this.accept = accept.isPresent() ? MediaType.parse(accept.get()) : MediaType.ALL; this.lang = req.header("Accept-Language"); this.locales = locales; this.port = port; Optional<String> type = req.header("Content-Type"); this.type = type.isPresent() ? MediaType.valueOf(type.get()) : MediaType.all; String cs = this.type.params().get("charset"); this.charset = cs != null ? Charset.forName(cs) : charset; this.files = new ArrayList<>(); this.timestamp = timestamp; }
@Override public long length() { return req.header("Content-Length") .map(Long::parseLong) .orElse(-1L); }
private boolean upgrade(final NativeRequest request) { Optional<String> upgrade = request.header(UPGRADE); return upgrade.isPresent() && upgrade.get().equalsIgnoreCase(WEB_SOCKET); }
@Override public int port() { return req.header("host").map(host -> { String[] parts = host.split(":"); if (parts.length > 1) { return Integer.parseInt(parts[1]); } // fallback to default ports return secure() ? 443 : 80; }).orElse(port); }
@Override public String hostname() { return req.header("host").map(host -> host.split(":")[0]).orElse(ip()); }
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); }
public RequestImpl(final Injector injector, final NativeRequest req, final String contextPath, final int port, final Route route, final Charset charset, final List<Locale> locales, final Map<Object, Object> scope, final Map<String, Object> locals, final long timestamp) { this.injector = injector; this.req = req; this.route = route; this.scope = scope; this.locals = locals; this.contextPath = contextPath; Optional<String> accept = req.header("Accept"); this.accept = accept.isPresent() ? MediaType.parse(accept.get()) : MediaType.ALL; this.lang = req.header("Accept-Language"); this.locales = locales; this.port = port; Optional<String> type = req.header("Content-Type"); this.type = type.isPresent() ? MediaType.valueOf(type.get()) : MediaType.all; String cs = this.type.params().get("charset"); this.charset = cs != null ? Charset.forName(cs) : charset; this.files = new ArrayList<>(); this.timestamp = timestamp; }