Search in sources :

Example 1 with UriMethod

use of com.tremolosecurity.proxy.http.UriMethod in project OpenUnison by TremoloSecurity.

the class UriRequestProcess method postProcess.

@Override
public void postProcess(HttpFilterRequest req, HttpFilterResponse resp, UrlHolder holder, HttpFilterChain chain) throws Exception {
    String proxyTo = holder.getUrl().getProxyTo();
    HashMap<String, String> uriParams = (HashMap<String, String>) req.getAttribute("TREMOLO_URI_PARAMS");
    Iterator<String> names;
    StringBuffer proxyToURL = ProxyTools.getInstance().getGETUrl(req, holder, uriParams);
    boolean first = true;
    for (NVP p : req.getQueryStringParams()) {
        if (first) {
            proxyToURL.append('?');
            first = false;
        } else {
            proxyToURL.append('&');
        }
        proxyToURL.append(p.getName()).append('=').append(URLEncoder.encode(p.getValue(), "UTF-8"));
    }
    com.tremolosecurity.proxy.HttpUpgradeRequestManager upgradeRequestManager = GlobalEntries.getGlobalEntries().getConfigManager().getUpgradeManager();
    if (req.getHeader("Connection") != null && req.getHeader("Connection").getValues().get(0).equalsIgnoreCase("Upgrade")) {
        ProxyResponse pr = (ProxyResponse) resp.getServletResponse();
        upgradeRequestManager.proxyWebSocket(req, (HttpServletResponse) pr.getResponse(), proxyToURL.toString());
    } else {
        CloseableHttpClient httpclient = this.getHttp(proxyTo, req.getServletRequest(), holder);
        // HttpGet httpget = new HttpGet(proxyToURL.toString());
        // this.getHttpMethod(proxyToURL.toString());
        HttpRequestBase httpMethod = new UriMethod(req.getMethod(), proxyToURL.toString());
        req.setAttribute("TREMOLO_FINAL_URL", proxyToURL.toString());
        setHeadersCookies(req, holder, httpMethod, proxyToURL.toString());
        HttpContext ctx = (HttpContext) req.getSession().getAttribute(ProxySys.HTTP_CTX);
        HttpResponse response = httpclient.execute(httpMethod, ctx);
        postProcess(req, resp, holder, response, proxyToURL.toString(), chain, httpMethod);
    }
}
Also used : ProxyResponse(com.tremolosecurity.proxy.ProxyResponse) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HashMap(java.util.HashMap) HttpContext(org.apache.http.protocol.HttpContext) NVP(com.tremolosecurity.util.NVP) HttpResponse(org.apache.http.HttpResponse) HttpUpgradeRequestManager(com.tremolosecurity.proxy.HttpUpgradeRequestManager) UriMethod(com.tremolosecurity.proxy.http.UriMethod)

Aggregations

HttpUpgradeRequestManager (com.tremolosecurity.proxy.HttpUpgradeRequestManager)1 ProxyResponse (com.tremolosecurity.proxy.ProxyResponse)1 UriMethod (com.tremolosecurity.proxy.http.UriMethod)1 NVP (com.tremolosecurity.util.NVP)1 HashMap (java.util.HashMap)1 HttpResponse (org.apache.http.HttpResponse)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 HttpContext (org.apache.http.protocol.HttpContext)1