public void filter()

in sample/src/main/java/org/apache/apisix/plugin/runner/filter/RewriteRequestDemoFilter.java [63:98]


    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
        /*
         * If the conf you configured is of type json, you can convert it to Map or json.
         */

        String configStr = request.getConfig(this);
        Gson gson = new Gson();
        Map<String, Object> conf = new HashMap<>();
        conf = gson.fromJson(configStr, conf.getClass());

        /*
         * You can use the parameters in the configuration.
         */

        // note: the path to the rewrite must start with '/'
        request.setPath((String) conf.get("rewrite_path"));
        request.setHeader((String) conf.get("conf_header_name"), (String) conf.get("conf_header_value"));
        /* note: The value of the parameter is currently a string type.
                 If you need the json type, you need the upstream service to parse the string value to json.
                 For example, if the arg is set as below
                 request.setArg("new arg", "{\"key1\":\"value1\",\"key2\":2}");

                 The arg received by the upstream service will be as below
                 "new arg": "{\"key1\":\"value1\",\"key2\":2}"
         */
        request.setArg((String) conf.get("conf_arg_name"), (String) conf.get("conf_arg_value"));

        /*
         * You can fetch the Nginx variables, and the request body
         */
        String remoteAddr = request.getVars("remote_addr");
        String serverPort = request.getVars("server_port");
        String body = request.getBody();

        chain.filter(request, response);
    }