Skip to content

Commit

Permalink
bugfix: got 500 error when using post method in grpc-transcode plugin(a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nic-chen authored May 11, 2020
1 parent 64fcb9f commit 0300304
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apisix/plugins/grpc-transcode/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local function get_from_request(name, kind)
local request_table
if ngx.req.get_method() == "POST" then
if string.find(ngx.req.get_headers()["Content-Type"] or "",
"application/json", true) then
"application/json", 1, true) then
request_table = json.decode(ngx.req.get_body_data())
else
request_table = ngx.req.get_post_args()
Expand Down
50 changes: 37 additions & 13 deletions t/plugin/grpc-transcode.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ passed
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"methods": ["GET", "POST"],
"uri": "/grpctest",
"service_protocol": "grpc",
"plugins": {
Expand Down Expand Up @@ -125,7 +125,31 @@ qr/\{"message":"Hello world"\}/
=== TEST 4: wrong service protocol
=== TEST 4: hit route by post
--- request
POST /grpctest
name=world
--- response_body eval
qr/\{"message":"Hello world"\}/
--- no_error_log
[error]
=== TEST 5: hit route by post json
--- request
POST /grpctest
{"name": "world"}
--- more_headers
Content-Type: application/json
--- response_body eval
qr/\{"message":"Hello world"\}/
--- no_error_log
[error]
=== TEST 6: wrong service protocol
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -166,7 +190,7 @@ GET /t
=== TEST 5: wrong upstream address
=== TEST 7: wrong upstream address
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -208,7 +232,7 @@ passed
=== TEST 6: hit route (Connection refused)
=== TEST 8: hit route (Connection refused)
--- request
GET /grpctest
--- response_body eval
Expand All @@ -219,7 +243,7 @@ Connection refused) while connecting to upstream
=== TEST 7: update proto(id: 1)
=== TEST 9: update proto(id: 1)
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -266,7 +290,7 @@ passed
=== TEST 8: set routes(id: 2)
=== TEST 10: set routes(id: 2)
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -309,7 +333,7 @@ passed
=== TEST 9: hit route
=== TEST 11: hit route
--- request
GET /grpc_plus?a=1&b=2
--- response_body eval
Expand All @@ -319,7 +343,7 @@ qr/\{"result":3\}/
=== TEST 10: hit route
=== TEST 12: hit route
--- request
GET /grpc_plus?a=1&b=2251799813685260
--- response_body eval
Expand All @@ -329,7 +353,7 @@ qr/\{"result":"#2251799813685261"\}/
=== TEST 11: set route3 deadline nodelay
=== TEST 13: set route3 deadline nodelay
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -371,7 +395,7 @@ passed
=== TEST 12: hit route
=== TEST 14: hit route
--- request
GET /grpc_deadline?name=apisix
--- response_body eval
Expand All @@ -381,7 +405,7 @@ qr/\{"message":"Hello apisix"\}/
=== TEST 13: set route4 deadline delay
=== TEST 15: set route4 deadline delay
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -423,14 +447,14 @@ passed
=== TEST 14: hit route
=== TEST 16: hit route
--- request
GET /grpc_delay?name=apisix
--- error_code: 504
=== TEST 15: set routes: missing method
=== TEST 17: set routes: missing method
--- config
location /t {
content_by_lua_block {
Expand Down

0 comments on commit 0300304

Please sign in to comment.