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/01/11 02:05:17 UTC

[GitHub] [apisix] shuaijinchao opened a new pull request #6070: chore(grpc-web): update mime of response to mime of request

shuaijinchao opened a new pull request #6070:
URL: https://github.com/apache/apisix/pull/6070


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   update mime of response to mime of request
   
   ### Pre-submission checklist:
   
   <!--
   Please follow the PR manners:
   1. Use Draft if the PR is not ready to be reviewed
   2. Test is required for the feat/fix PR, unless you have a good reason
   3. Doc is required for the feat PR
   4. Use a new commit to resolve review instead of `push -f`
   5. If you need to resolve merge conflicts after the PR is reviewed, please merge master but do not rebase
   6. Use "request review" to notify the reviewer once you have resolved the review
   7. Only reviewer can click "Resolve conversation" to mark the reviewer's review resolved
   -->
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [ ] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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] shuaijinchao commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r782003733



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -60,6 +59,9 @@ function _M.check_schema(conf)
 end
 
 function _M.access(conf, ctx)
+    -- set context variable mime
+    ctx.grpc_web_mime = core.request.header(ctx, "Content-Type")

Review comment:
       added




-- 
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] tzssangglass commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781861816



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -60,6 +59,9 @@ function _M.check_schema(conf)
 end
 
 function _M.access(conf, ctx)
+    -- set context variable mime
+    ctx.grpc_web_mime = core.request.header(ctx, "Content-Type")

Review comment:
       better to add a comment explaining why you need to set the ctx.grpc_web_mime in advance




-- 
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] shuaijinchao commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781790462



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -123,8 +122,14 @@ function _M.header_filter(conf, ctx)
         core.response.set_header("Access-Control-Allow-Methods", DEFAULT_CORS_ALLOW_METHODS)
         core.response.set_header("Access-Control-Allow-Headers", DEFAULT_CORS_ALLOW_HEADERS)
     end
+
     core.response.set_header("Access-Control-Allow-Origin", DEFAULT_CORS_ALLOW_ORIGIN)
-    core.response.set_header("Content-Type", ctx.grpc_web_mime or DEFAULT_CORS_CONTENT_TYPE)
+
+    local response_mime = ctx.grpc_web_mime
+    if not response_mime then
+        response_mime = core.request.header(ctx, "Content-Type")
+    end
+    core.response.set_header("Content-Type", response_mime)

Review comment:
       I moved mime type extraction to the plugin's entry point to ensure it is always available in context.




-- 
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] shuaijinchao commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781716736



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -123,8 +122,14 @@ function _M.header_filter(conf, ctx)
         core.response.set_header("Access-Control-Allow-Methods", DEFAULT_CORS_ALLOW_METHODS)
         core.response.set_header("Access-Control-Allow-Headers", DEFAULT_CORS_ALLOW_HEADERS)
     end
+
     core.response.set_header("Access-Control-Allow-Origin", DEFAULT_CORS_ALLOW_ORIGIN)
-    core.response.set_header("Content-Type", ctx.grpc_web_mime or DEFAULT_CORS_CONTENT_TYPE)
+
+    local response_mime = ctx.grpc_web_mime
+    if not response_mime then
+        response_mime = core.request.header(ctx, "Content-Type")
+    end
+    core.response.set_header("Content-Type", response_mime)

Review comment:
       If it is judged that only gRPC-Web type requests can get MIME, I am not sure if this is friendly to other requests.




-- 
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] spacewander merged pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6070:
URL: https://github.com/apache/apisix/pull/6070


   


-- 
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] spacewander commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781712851



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -123,8 +122,14 @@ function _M.header_filter(conf, ctx)
         core.response.set_header("Access-Control-Allow-Methods", DEFAULT_CORS_ALLOW_METHODS)
         core.response.set_header("Access-Control-Allow-Headers", DEFAULT_CORS_ALLOW_HEADERS)
     end
+
     core.response.set_header("Access-Control-Allow-Origin", DEFAULT_CORS_ALLOW_ORIGIN)
-    core.response.set_header("Content-Type", ctx.grpc_web_mime or DEFAULT_CORS_CONTENT_TYPE)
+
+    local response_mime = ctx.grpc_web_mime
+    if not response_mime then
+        response_mime = core.request.header(ctx, "Content-Type")
+    end
+    core.response.set_header("Content-Type", response_mime)

Review comment:
       We can set the type only when ctx.grpc_web_mime is given?




-- 
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] spacewander commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781783925



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -123,8 +122,14 @@ function _M.header_filter(conf, ctx)
         core.response.set_header("Access-Control-Allow-Methods", DEFAULT_CORS_ALLOW_METHODS)
         core.response.set_header("Access-Control-Allow-Headers", DEFAULT_CORS_ALLOW_HEADERS)
     end
+
     core.response.set_header("Access-Control-Allow-Origin", DEFAULT_CORS_ALLOW_ORIGIN)
-    core.response.set_header("Content-Type", ctx.grpc_web_mime or DEFAULT_CORS_CONTENT_TYPE)
+
+    local response_mime = ctx.grpc_web_mime
+    if not response_mime then
+        response_mime = core.request.header(ctx, "Content-Type")
+    end
+    core.response.set_header("Content-Type", response_mime)

Review comment:
       I am confused. The current code just get and reset the Content-Type when the grpc_web_mime is missing.




-- 
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] shuaijinchao commented on a change in pull request #6070: chore(grpc-web): update mime of response to mime of request

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6070:
URL: https://github.com/apache/apisix/pull/6070#discussion_r781716736



##########
File path: apisix/plugins/grpc-web.lua
##########
@@ -123,8 +122,14 @@ function _M.header_filter(conf, ctx)
         core.response.set_header("Access-Control-Allow-Methods", DEFAULT_CORS_ALLOW_METHODS)
         core.response.set_header("Access-Control-Allow-Headers", DEFAULT_CORS_ALLOW_HEADERS)
     end
+
     core.response.set_header("Access-Control-Allow-Origin", DEFAULT_CORS_ALLOW_ORIGIN)
-    core.response.set_header("Content-Type", ctx.grpc_web_mime or DEFAULT_CORS_CONTENT_TYPE)
+
+    local response_mime = ctx.grpc_web_mime
+    if not response_mime then
+        response_mime = core.request.header(ctx, "Content-Type")
+    end
+    core.response.set_header("Content-Type", response_mime)

Review comment:
       this way Nginx will set the default value `text/html` to `Content-Type`, which doesn't look particularly friendly.




-- 
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