shreemaan-abhishek commented on code in PR #11988:
URL: https://github.com/apache/apisix/pull/11988#discussion_r1968801292


##########
apisix/plugins/grpc-web.lua:
##########
@@ -68,6 +68,46 @@ function _M.check_schema(conf)
     return core.schema.check(schema, conf)
 end
 
+local function exit(ctx, status)
+    ctx.grpc_web_skip_body_filter = true
+    return status
+end
+
+--- Build gRPC-Web trailer chunk
+-- grpc-web trailer format reference:
+--     
envoyproxy/envoy/source/extensions/filters/http/grpc_web/grpc_web_filter.cc
+--
+-- Format for grpc-web trailer
+--     1 byte: 0x80
+--     4 bytes: length of the trailer
+--     n bytes: trailer
+-- It using upstream_trailer_* variables from nginx, it is available since 
NGINX version 1.13.10
+-- 
https://nginx.org/en/docs/http/ngx_http_upstream_module.html#var_upstream_trailer_
+--
+-- @param grpc_status number grpc status code
+-- @param grpc_message string grpc message
+-- @return string grpc-web trailer chunk in raw string
+local build_trailer = function (grpc_status, grpc_message)
+    local status_str = "grpc-status:" .. grpc_status
+    local status_msg = "grpc-message:" .. ( grpc_message or "")
+    local grpc_web_trailer = status_str .. "\r\n" .. status_msg .. "\r\n"
+    local len = #grpc_web_trailer
+
+    -- 1 byte: 0x80
+    local trailer_buf = string.char(0x80)
+    -- 4 bytes: length of the trailer
+    trailer_buf = trailer_buf .. string.char(
+        bit.band(bit.rshift(len, 24), 0xff),
+        bit.band(bit.rshift(len, 16), 0xff),
+        bit.band(bit.rshift(len, 8), 0xff),
+        bit.band(len, 0xff)
+    )
+    -- n bytes: trailer
+    trailer_buf = trailer_buf .. grpc_web_trailer
+
+    return  trailer_buf

Review Comment:
   this is a good first issue, hopefully someone from the community can fix 
this.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to