How to add the headers of the original request in IG's static request filter

Hi, I wonder when using the static request filter, how to add the headers of the original request to the header section of the static request filter. Since the filter will not set up any headers for the new request by default, information might lost during the rewrite.

Hi @Wenhao_LIU,

Can you describe in which context the Static Request Filter is used, what is the route functionality? What are you trying to achieve?

Regards
Patrick

Hi Patrick,

The original functionality I want to achieve by using this route is to rewrite uri path to do the redirection. For example,
/path1/to/abc => /patha/t0/aBcd
/path2/subpath/defg => /pathb/subpath2/hijk.jsp?QUERYPARAMETER=VALUE.
I am trying to use UriRewriteFilter to achieve this and it works fine when no query parameter is involved. However, when query parameter is added to the UriRewriteFilter, the question mark will be URL encoded twice and the final result can’t be recognized by the resource server and return 404 error. To solve this, I would like to use a Static Request filter with the function “formDecodeParameterNameOrValue()” to decode the request uri path first to avoid double encoding. But the header and other elements of the Static Request filter need to be configured or it will remain empty and lost during the rewrite. So I need a method to keep the original request details and pass it to the static request filter and that is what I am trying to achieve.

Hi @Wenhao_LIU,

The UriPathRewriteFilter mappings apply to paths, so the query string is not included. As I understand it, from the example you provide, the query string was not originally in the request, and is added to the redirection, is that correct? In this particular case, yes there is no place for that in the UriRewritePathFilter - this should be handled by another filter.

On the other hand, the uri property in a static request filter can include the query string. However I am confused about you would need to decode it: are you re-injecting the query string from the request into the re-direction? If that’s the case, then you can access the original query string with ${request.uri.query} so consider using a uri such as: "http://host/path/to/target?${request.uri.query}".

However, if the computation is too cumbersome to be achieved in a single expression, or the OOTB filters does not fit exactly the requirement, then you should consider using a ScriptableFilter.

Regards
Patrick

Hi Patrick,

I am trying to add brand new query parameters rather than re-inject the original query string. The question mark of the outcome of the UriRewritePathFilter will be encoded twice before being sent out. That will cause the destination server to mix up the query parameter and the uri path and fail the request. That is why I need a Static Request filter to decode request uri before sending it out.

Now, if the UriPathRewriteFilter is not the best option. Do you know how should I add these query parameters to a new request? If using the static request filter, then do you know how to add the headers and other elements of the original request to the static request filter, which is my original question? So this info won’t lost during rebasing. Or the ScriptableFilter is the only option?