private RequestAttributes getRequestAttributes() {
   RequestAttributes attributes = request.get(RequestAttributes.class);
   if (attributes == null) {
     attributes = new RequestAttributes();
     request.add(attributes);
   }
   return attributes;
 }
  private String generateRedirectLocation(Context context, Request request, String path) {
    // Rules
    // 1. Given absolute URL use it
    // 2. Given Starting Slash prepend public facing domain:port if provided if not use base URL of
    // request
    // 3. Given relative URL prepend public facing domain:port plus parent path of request URL
    // otherwise full parent path

    PublicAddress publicAddress = context.get(PublicAddress.class);
    String generatedPath;
    URI host = publicAddress.getAddress(context);

    if (ABSOLUTE_PATTERN.matcher(path).matches()) {
      // Rule 1 - Path is absolute
      generatedPath = path;
    } else {
      if (path.charAt(0) == '/') {
        // Rule 2 - Starting Slash
        generatedPath = host.toString() + path;
      } else {
        // Rule 3
        generatedPath = host.toString() + getParentPath(request.getUri()) + path;
      }
    }

    return generatedPath;
  }
 @Override
 public Collection<Cookie> getRequestCookies() {
   final List<Cookie> newCookies = new ArrayList<>();
   final Set<io.netty.handler.codec.http.cookie.Cookie> cookies = request.getCookies();
   for (final io.netty.handler.codec.http.cookie.Cookie cookie : cookies) {
     final Cookie newCookie = new Cookie(cookie.name(), cookie.value());
     newCookie.setDomain(cookie.domain());
     newCookie.setPath(cookie.path());
     newCookie.setMaxAge((int) cookie.maxAge());
     newCookie.setSecure(cookie.isSecure());
     newCookie.setHttpOnly(cookie.isHttpOnly());
     newCookies.add(newCookie);
   }
   return newCookies;
 }
 @Override
 public String getRequestHeader(String name) {
   return request.getHeaders().get(name);
 }
 @Override
 public Map<String, String[]> getRequestParameters() {
   return flattenMap(combineMaps(request.getQueryParams(), form));
 }
 @Override
 public String getRequestParameter(String name) {
   return Optional.ofNullable(request.getQueryParams().get(name)).orElseGet(() -> form.get(name));
 }
 private static boolean isFormAvailable(Request request, TypedData body) {
   HttpMethod method = request.getMethod();
   return body.getContentType().isForm() && (method.isPost() || method.isPut());
 }
 @Override
 public String getPath() {
   return request.getPath();
 }
 @Override
 public String getFullRequestURL() {
   return getAddress().toString() + request.getUri();
 }
Beispiel #10
0
 @Override
 public String getRemoteAddr() {
   return request.getRemoteAddress().getHostText();
 }
Beispiel #11
0
 @Override
 public String getRequestMethod() {
   return request.getMethod().getName();
 }