private URI getBaseUri(final Request request) { try { final String hostHeader = request.getValue("Host"); if (hostHeader != null) { final String scheme = request.isSecure() ? "https" : "http"; return new URI(scheme + "://" + hostHeader + "/"); } else { final Address address = request.getAddress(); return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null, null); } } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
if (!"gzip".equals(req.getValue("Accept-Encoding"))) { throw new IllegalStateException("Should accept gzip");
@Override public void handle(final Request request, final Response response) { final ResponseWriter responseWriter = new ResponseWriter(response, scheduler); final URI baseUri = getBaseUri(request); final URI requestUri = getRequestUri(request, baseUri); try { final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, request.getMethod(), getSecurityContext(request), new MapPropertiesDelegate()); requestContext.setEntityStream(request.getInputStream()); for (final String headerName : request.getNames()) { requestContext.headers(headerName, request.getValue(headerName)); } requestContext.setWriter(responseWriter); requestContext.setRequestScopedInitializer(injectionManager -> { injectionManager.<Ref<Request>>getInstance(RequestTYPE).set(request); injectionManager.<Ref<Response>>getInstance(ResponseTYPE).set(response); }); appHandler.handle(requestContext); } catch (final Exception ex) { throw new RuntimeException(ex); } finally { if (!responseWriter.isSuspended()) { close(response); } } }
@Override public String getRequestHeader(Header header) { return baseRequest.getValue(header.code); }
@Override public String header(String name) { return request.getValue(name); }
public String getHeaderValue(String name) { return request.getValue(name); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma seperated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * * @return this returns the value that the HTTP message header */ public String getValue(String name) { return request.getValue(name); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma separated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * @param index if there are multiple values this selects one * * @return this returns the value that the HTTP message header */ public String getValue(String name, int index) { return request.getValue(name, index); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma seperated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * * @return this returns the value that the HTTP message header */ public String getValue(String name) { return request.getValue(name); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma seperated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * * @return this returns the value that the HTTP message header */ public String getValue(String name) { return request.getValue(name); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma separated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * @param index if there are multiple values this selects one * * @return this returns the value that the HTTP message header */ public String getValue(String name, int index) { return request.getValue(name, index); }
/** * This can be used to get the value of the first message header * that has the specified name. The value provided from this will * be trimmed so there is no need to modify the value, also if * the header name specified refers to a comma separated list of * values the value returned is the first value in that list. * This returns null if theres no HTTP message header. * * @param name the HTTP message header to get the value from * @param index if there are multiple values this selects one * * @return this returns the value that the HTTP message header */ public String getValue(String name, int index) { return request.getValue(name, index); }
/** * This is used to determine if the request is a valid WebSocket * handshake of the correct version. This also checks to see if * the request contained the required handshake token. * * @return this returns true if the request is a valid handshake */ private boolean isProtocol() { String protocol = request.getValue(SEC_WEBSOCKET_VERSION); String token = request.getValue(SEC_WEBSOCKET_KEY); if(token != null) { return version.equals(protocol); } return false; }
@Override public Optional<String> getHeader(String headerName) { return Optional.fromNullable(request.getValue(headerName)); }
/** * This is used to determine if the request is a valid WebSocket * handshake of the correct version. This also checks to see if * the request contained the required handshake token. * * @return this returns true if the request is a valid handshake */ private boolean isProtocol() { String protocol = request.getValue(SEC_WEBSOCKET_VERSION); String token = request.getValue(SEC_WEBSOCKET_KEY); if(token != null) { return version.equals(protocol); } return false; }
@Override public Optional<String> getHeader(String headerName) { return Optional.fromNullable(request.getValue(headerName)); }
public Map<String, String> getHeaders() { Map<String, String> headers = new HashMap<String, String>(); for (String s : baseRequest.getNames()) { String val = baseRequest.getValue(s); headers.put(s, val); } return headers; }
private InBoundHeaders getHeaders(Request request) { InBoundHeaders header = new InBoundHeaders(); List<String> names = request.getNames(); for (String name : names) { String value = request.getValue(name); header.add(name, value); } return header; }
private URI getBaseUri(final Request request) { try { final String hostHeader = request.getValue("Host"); if (hostHeader != null) { final String scheme = request.isSecure() ? "https" : "http"; return new URI(scheme + "://" + hostHeader + "/"); } else { final Address address = request.getAddress(); return new URI(address.getScheme(), null, address.getDomain(), address.getPort(), "/", null, null); } } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
/** * Returns the list of request headers. * * @return The list of request headers. */ @Override public Series<Parameter> getRequestHeaders() { final Series<Parameter> result = super.getRequestHeaders(); if (!this.requestHeadersAdded) { final List<String> names = this.request.getNames(); for (String name : names) { result.add(new Parameter(name, this.request.getValue(name))); } this.requestHeadersAdded = true; } return result; }