private ReverseProxy createReverseProxy() { List<ProxyUpstream> proxyUpstreams = U.list(); U.notNull(upstreams, "proxy upstreams"); for (String upstream : upstreams) { proxyUpstreams.add(new ProxyUpstream(upstream)); } LoadBalancer balancer = loadBalancer != null ? loadBalancer : new RoundRobinLoadBalancer(); ProxyMapping mapping = new ProxyMapping(uriPrefix, balancer, proxyUpstreams); return new ReverseProxy(mapping); }
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); } }); }
private void process(final Req req, final Resp resp, final ProxyMapping mapping, final int attempts, final long since) { final String targetUrl = mapping.getTargetUrl(req);
private ReverseProxy createReverseProxy() { List<ProxyUpstream> proxyUpstreams = U.list(); U.notNull(upstreams, "proxy upstreams"); for (String upstream : upstreams) { proxyUpstreams.add(new ProxyUpstream(upstream)); } LoadBalancer balancer = loadBalancer != null ? loadBalancer : new RoundRobinLoadBalancer(); ProxyMapping mapping = new ProxyMapping(uriPrefix, balancer, proxyUpstreams); return new ReverseProxy(mapping); }