You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/10/07 16:07:04 UTC

[GitHub] [apisix-java-plugin-runner] tzssangglass opened a new pull request, #200: feat: support for getting upstream response body

tzssangglass opened a new pull request, #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200

   Please answer these questions before submitting a pull request
   
   - Why submit this pull request?
   - [ ] Bugfix
   - [x] New feature provided
   - [ ] Improve performance
   
   - Related issues
   
   ___
   ### Bugfix
   - Description
   
   - How to fix?
   
   ___
   ### New feature or improvement
   - Describe the details and related test reports.
   
   - Source branch
   
   - Related commits and pull requests
   
   - Target branch
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] soulbird commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990650283


##########
tests/e2e/plugins/plugins_post_with_vars_test.go:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package plugins_test
+
+import (
+	"github.com/gavv/httpexpect/v2"
+	"github.com/onsi/ginkgo"
+	"github.com/onsi/ginkgo/extensions/table"
+	"net/http"
+
+	"github.com/apache/apisix-java-plugin-runner/tests/e2e/tools"
+)
+
+var _ = ginkgo.Describe("Post", func() {
+	table.DescribeTable("test route create and update",
+		func(tc tools.HttpTestCase) {
+			tools.RunTestCase(tc)
+		},
+		table.Entry("create java runner post plugin route success", tools.HttpTestCase{
+			Object: tools.PutA6Conf(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/1",
+			Body: `{
+				"uri":"/test/java/runner/postvars",
+				"plugins":{
+					"ext-plugin-pre-req":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					},
+					"ext-plugin-post-resp":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					}
+				},
+				"upstream":{
+					"nodes":{
+						"web:8888":1
+					},
+					"type":"roundrobin"
+				}
+			}`,
+			Headers:           map[string]string{"X-API-KEY": tools.GetAdminToken()},
+			ExpectStatusRange: httpexpect.Status2xx,
+		}),
+		table.Entry("test java runner post plugin route success", tools.HttpTestCase{
+			Object:       tools.GetA6Expect(),
+			Method:       http.MethodGet,
+			Path:         "/test/java/runner/postvars",
+			ExpectStatus: http.StatusOK,
+		}),
+	)
+})

Review Comment:
   The test case doesn't seem to have anything to do with the plugin. such as how you use `vars`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] soulbird commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990650161


##########
runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java:
##########
@@ -106,6 +107,62 @@ protected void channelRead0(ChannelHandlerContext ctx, A6Request request) {
         }
     }
 
+    private Boolean[] fetchExtraInfo(ChannelHandlerContext ctx, PluginFilterChain chain) {
+        // fetch the nginx variables
+        Set<String> varKeys = new HashSet<>();
+        boolean requiredBody = false;

Review Comment:
   Better to use `requiredReqBody`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990731399


##########
sample/src/main/java/org/apache/apisix/plugin/runner/filter/PostReqWithVarsFilter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.apisix.plugin.runner.filter;
+
+import com.google.gson.Gson;
+import org.apache.apisix.plugin.runner.HttpRequest;
+import org.apache.apisix.plugin.runner.HttpResponse;
+import org.apache.apisix.plugin.runner.PostRequest;
+import org.apache.apisix.plugin.runner.PostResponse;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class PostReqWithVarsFilter implements PluginFilter {
+    @Override
+    public String name() {
+        return "PostReqWithVarsFilter";
+    }
+
+    @Override
+    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        request.setPath((String) conf.get("rewrite_path"));
+        chain.filter(request, response);
+    }
+
+    @Override
+    public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        String bodyStr = request.getBody();
+        Map<String, Object> body = new HashMap<>();
+        body = gson.fromJson(bodyStr, body.getClass());
+        assert body.get("url").toString().endsWith((String) conf.get("rewrite_path"));
+        chain.postFilter(request, response);
+    }
+
+    @Override
+    public List<String> requiredVars() {
+        List<String> vars = new ArrayList<>();
+        vars.add("sent_http_content_type");
+        vars.add("upstream_response_length");

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#issuecomment-1272465615

   > Should update [`main`/docs/en/latest/installation-guide.md#prerequisites](https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/installation-guide.md?rgh-link-date=2022-10-09T05%3A25%3A52Z#prerequisites).
   
   done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990723967


##########
tests/e2e/plugins/plugins_post_with_vars_test.go:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package plugins_test
+
+import (
+	"github.com/gavv/httpexpect/v2"
+	"github.com/onsi/ginkgo"
+	"github.com/onsi/ginkgo/extensions/table"
+	"net/http"
+
+	"github.com/apache/apisix-java-plugin-runner/tests/e2e/tools"
+)
+
+var _ = ginkgo.Describe("Post", func() {
+	table.DescribeTable("test route create and update",
+		func(tc tools.HttpTestCase) {
+			tools.RunTestCase(tc)
+		},
+		table.Entry("create java runner post plugin route success", tools.HttpTestCase{
+			Object: tools.PutA6Conf(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/1",
+			Body: `{
+				"uri":"/test/java/runner/postvars",
+				"plugins":{
+					"ext-plugin-pre-req":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					},
+					"ext-plugin-post-resp":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					}
+				},
+				"upstream":{
+					"nodes":{
+						"web:8888":1
+					},
+					"type":"roundrobin"
+				}
+			}`,
+			Headers:           map[string]string{"X-API-KEY": tools.GetAdminToken()},
+			ExpectStatusRange: httpexpect.Status2xx,
+		}),
+		table.Entry("test java runner post plugin route success", tools.HttpTestCase{
+			Object:       tools.GetA6Expect(),
+			Method:       http.MethodGet,
+			Path:         "/test/java/runner/postvars",
+			ExpectStatus: http.StatusOK,
+		}),
+	)
+})

Review Comment:
   1. `PostReqWithVarsFilter` change the request path from `/test/java/runner/postvars` to `/get` in `filter` by `ext-plugin-pre-req`;
   
   2. `PostReqWithVarsFilter` **get the upstream response body(from the httpbin)** and check the `url` in the body, the `url` should be `/get`
   
   3. the response body also one of `vars` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] soulbird commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990726052


##########
sample/src/main/java/org/apache/apisix/plugin/runner/filter/PostReqWithVarsFilter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.apisix.plugin.runner.filter;
+
+import com.google.gson.Gson;
+import org.apache.apisix.plugin.runner.HttpRequest;
+import org.apache.apisix.plugin.runner.HttpResponse;
+import org.apache.apisix.plugin.runner.PostRequest;
+import org.apache.apisix.plugin.runner.PostResponse;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class PostReqWithVarsFilter implements PluginFilter {
+    @Override
+    public String name() {
+        return "PostReqWithVarsFilter";
+    }
+
+    @Override
+    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        request.setPath((String) conf.get("rewrite_path"));
+        chain.filter(request, response);
+    }
+
+    @Override
+    public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        String bodyStr = request.getBody();
+        Map<String, Object> body = new HashMap<>();
+        body = gson.fromJson(bodyStr, body.getClass());
+        assert body.get("url").toString().endsWith((String) conf.get("rewrite_path"));
+        chain.postFilter(request, response);
+    }
+
+    @Override
+    public List<String> requiredVars() {
+        List<String> vars = new ArrayList<>();
+        vars.add("sent_http_content_type");
+        vars.add("upstream_response_length");

Review Comment:
   What is this useful for? It is not used in the test case. What information do you want to tell the user?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] soulbird commented on pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
soulbird commented on PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#issuecomment-1272459646

   Should update https://github.com/apache/apisix-java-plugin-runner/blob/main/docs/en/latest/installation-guide.md#prerequisites.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990728072


##########
sample/src/main/java/org/apache/apisix/plugin/runner/filter/PostReqWithVarsFilter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.apisix.plugin.runner.filter;
+
+import com.google.gson.Gson;
+import org.apache.apisix.plugin.runner.HttpRequest;
+import org.apache.apisix.plugin.runner.HttpResponse;
+import org.apache.apisix.plugin.runner.PostRequest;
+import org.apache.apisix.plugin.runner.PostResponse;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class PostReqWithVarsFilter implements PluginFilter {
+    @Override
+    public String name() {
+        return "PostReqWithVarsFilter";
+    }
+
+    @Override
+    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        request.setPath((String) conf.get("rewrite_path"));
+        chain.filter(request, response);
+    }
+
+    @Override
+    public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        String bodyStr = request.getBody();
+        Map<String, Object> body = new HashMap<>();
+        body = gson.fromJson(bodyStr, body.getClass());
+        assert body.get("url").toString().endsWith((String) conf.get("rewrite_path"));
+        chain.postFilter(request, response);
+    }
+
+    @Override
+    public List<String> requiredVars() {
+        List<String> vars = new ArrayList<>();
+        vars.add("sent_http_content_type");
+        vars.add("upstream_response_length");

Review Comment:
   I will continue to update and verify in another way



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] soulbird commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
soulbird commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990726134


##########
tests/e2e/plugins/plugins_post_with_vars_test.go:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package plugins_test
+
+import (
+	"github.com/gavv/httpexpect/v2"
+	"github.com/onsi/ginkgo"
+	"github.com/onsi/ginkgo/extensions/table"
+	"net/http"
+
+	"github.com/apache/apisix-java-plugin-runner/tests/e2e/tools"
+)
+
+var _ = ginkgo.Describe("Post", func() {
+	table.DescribeTable("test route create and update",
+		func(tc tools.HttpTestCase) {
+			tools.RunTestCase(tc)
+		},
+		table.Entry("create java runner post plugin route success", tools.HttpTestCase{
+			Object: tools.PutA6Conf(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/routes/1",
+			Body: `{
+				"uri":"/test/java/runner/postvars",
+				"plugins":{
+					"ext-plugin-pre-req":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					},
+					"ext-plugin-post-resp":{
+						"conf":[
+							{
+								"name":"PostReqWithVarsFilter",
+								"value":"{\"rewrite_path\":\"/get\"}"
+							}
+						]
+					}
+				},
+				"upstream":{
+					"nodes":{
+						"web:8888":1
+					},
+					"type":"roundrobin"
+				}
+			}`,
+			Headers:           map[string]string{"X-API-KEY": tools.GetAdminToken()},
+			ExpectStatusRange: httpexpect.Status2xx,
+		}),
+		table.Entry("test java runner post plugin route success", tools.HttpTestCase{
+			Object:       tools.GetA6Expect(),
+			Method:       http.MethodGet,
+			Path:         "/test/java/runner/postvars",
+			ExpectStatus: http.StatusOK,
+		}),
+	)
+})

Review Comment:
   Got it !



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass commented on a diff in pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200#discussion_r990727126


##########
sample/src/main/java/org/apache/apisix/plugin/runner/filter/PostReqWithVarsFilter.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.apisix.plugin.runner.filter;
+
+import com.google.gson.Gson;
+import org.apache.apisix.plugin.runner.HttpRequest;
+import org.apache.apisix.plugin.runner.HttpResponse;
+import org.apache.apisix.plugin.runner.PostRequest;
+import org.apache.apisix.plugin.runner.PostResponse;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class PostReqWithVarsFilter implements PluginFilter {
+    @Override
+    public String name() {
+        return "PostReqWithVarsFilter";
+    }
+
+    @Override
+    public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        request.setPath((String) conf.get("rewrite_path"));
+        chain.filter(request, response);
+    }
+
+    @Override
+    public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
+        String configStr = request.getConfig(this);
+        Gson gson = new Gson();
+        Map<String, Object> conf = new HashMap<>();
+        conf = gson.fromJson(configStr, conf.getClass());
+        String bodyStr = request.getBody();
+        Map<String, Object> body = new HashMap<>();
+        body = gson.fromJson(bodyStr, body.getClass());
+        assert body.get("url").toString().endsWith((String) conf.get("rewrite_path"));
+        chain.postFilter(request, response);
+    }
+
+    @Override
+    public List<String> requiredVars() {
+        List<String> vars = new ArrayList<>();
+        vars.add("sent_http_content_type");
+        vars.add("upstream_response_length");

Review Comment:
   tells the user that they can get some variables related to upstream this way. However, I can't figure out how to verify that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix-java-plugin-runner] tzssangglass merged pull request #200: feat: support for getting upstream response body

Posted by GitBox <gi...@apache.org>.
tzssangglass merged PR #200:
URL: https://github.com/apache/apisix-java-plugin-runner/pull/200


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org