public static boolean isGetReq(Req req) { return req.verb().equals(GET); }
public static boolean isPostReq(Req req) { return req.verb().equals(POST); }
@Override public String verb() { return req().verb(); }
public static TokenAuthData getAuth(Req req) { TokenAuthData auth = req.hasToken() ? Tokens.getAuth(req.token()) : null; // check if the route is outside of scope if (auth != null && U.notEmpty(auth.scope) && !auth.scope.contains(req.verb() + " " + req.path())) auth = null; return auth; }
private void process(final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) { final String targetUrl = mapping.getTargetUrl(req); Map<String, String> headers = U.map(req.headers()); headers.remove("transfer-encoding"); headers.remove("content-length"); addExtraRequestHeaders(req, headers); HttpClient client = getOrCreateClient(); client.req() .verb(req.verb()) .url(targetUrl) .headers(headers) .cookies(req.cookies()) .body(req.body()) .raw(true) .execute((result, error) -> { if (error == null) { resp.code(result.code()); resp.body(result.bodyBytes()); // process the response headers SimpleHttpResp proxyResp = new SimpleHttpResp(); HttpUtils.proxyResponseHeaders(result.headers(), proxyResp); if (proxyResp.contentType != null) resp.contentType(proxyResp.contentType); if (proxyResp.headers != null) resp.headers().putAll(proxyResp.headers); if (proxyResp.cookies != null) resp.cookies().putAll(proxyResp.cookies); resp.done(); } else { handleError(error, req, resp, mapping, attempts, since); } }); }
public static boolean isGetReq(Req req) { return req.verb().equals(GET); }
public static boolean isPostReq(Req req) { return req.verb().equals(POST); }
@Override public String verb() { return req().verb(); }
public static TokenAuthData getAuth(Req req) { TokenAuthData auth = req.hasToken() ? Tokens.getAuth(req.token()) : null; // check if the route is outside of scope if (auth != null && U.notEmpty(auth.scope) && !auth.scope.contains(req.verb() + " " + req.path())) auth = null; return auth; }
@Override public Object execute(Req req, Resp resp) { return U.map("verb", req.verb(), "uri", req.uri(), "path", req.path(), "data", req.data(), "headers", req.headers(), "cookies", req.cookies(), "token", req.token()); }
.verb(req.verb()) .url(targetUrl) .headers(headers)