Search in sources :

Example 6 with HttpQueryParams

use of com.netflix.zuul.message.http.HttpQueryParams in project zuul by Netflix.

the class ProxyEndpoint method massageRequestURI.

private static HttpRequestMessage massageRequestURI(HttpRequestMessage request) {
    final SessionContext context = request.getContext();
    String modifiedPath;
    HttpQueryParams modifiedQueryParams = null;
    String uri = null;
    if (context.get("requestURI") != null) {
        uri = (String) context.get("requestURI");
    }
    // If another filter has specified an overrideURI, then use that instead of requested URI.
    final Object override = context.get("overrideURI");
    if (override != null) {
        uri = override.toString();
    }
    if (null != uri) {
        int index = uri.indexOf('?');
        if (index != -1) {
            // Strip the query string off of the URI.
            String paramString = uri.substring(index + 1);
            modifiedPath = uri.substring(0, index);
            try {
                paramString = URLDecoder.decode(paramString, "UTF-8");
                modifiedQueryParams = new HttpQueryParams();
                StringTokenizer stk = new StringTokenizer(paramString, "&");
                while (stk.hasMoreTokens()) {
                    String token = stk.nextToken();
                    int idx = token.indexOf("=");
                    if (idx != -1) {
                        String key = token.substring(0, idx);
                        String val = token.substring(idx + 1);
                        modifiedQueryParams.add(key, val);
                    }
                }
            } catch (UnsupportedEncodingException e) {
                LOG.error("Error decoding url query param - " + paramString, e);
            }
        } else {
            modifiedPath = uri;
        }
        request.setPath(modifiedPath);
        if (null != modifiedQueryParams) {
            request.setQueryParams(modifiedQueryParams);
        }
    }
    return request;
}
Also used : StringTokenizer(java.util.StringTokenizer) HttpQueryParams(com.netflix.zuul.message.http.HttpQueryParams) SessionContext(com.netflix.zuul.context.SessionContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

HttpQueryParams (com.netflix.zuul.message.http.HttpQueryParams)6 SessionContext (com.netflix.zuul.context.SessionContext)4 Headers (com.netflix.zuul.message.Headers)3 HttpResponseMessageImpl (com.netflix.zuul.message.http.HttpResponseMessageImpl)3 HttpRequestMessageImpl (com.netflix.zuul.message.http.HttpRequestMessageImpl)2 Before (org.junit.Before)2 DynamicStringProperty (com.netflix.config.DynamicStringProperty)1 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)1 HttpResponseMessage (com.netflix.zuul.message.http.HttpResponseMessage)1 HttpRequestBuilder (com.netflix.zuul.message.util.HttpRequestBuilder)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StringTokenizer (java.util.StringTokenizer)1 Test (org.junit.Test)1