shreemaan-abhishek commented on code in PR #11988:
URL: https://github.com/apache/apisix/pull/11988#discussion_r1968781193
##########
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:
```suggestion
return trailer_buf
```
##########
apisix/plugins/grpc-web.lua:
##########
@@ -110,16 +150,17 @@ function _M.access(conf, ctx)
-- set grpc body
local body, err = core.request.get_body()
- if err then
+ if err or not body then
core.log.error("failed to read request body, err: ", err)
- return 400
+ return exit(ctx, 400)
end
if encoding == CONTENT_ENCODING_BASE64 then
body = decode_base64(body)
+ ngx.log(ngx.WARN, "DECODE BODY: ", body)
Review Comment:
1. why do we need warn log here?
2. we can use core.log.warn instead
--
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]