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 2020/12/16 11:21:37 UTC

[GitHub] [apisix] ziyou434 opened a new issue #3062: request help: core.request.get_body()

ziyou434 opened a new issue #3062:
URL: https://github.com/apache/apisix/issues/3062


   ### Issue description
   When I was debugging Apisix with app colleagues, I found that core.requ.get_body () could not read the whole body. Our body length was over 40,000 characters, but the body printed from the log was only over 10,000 characters.
   I found the fuction was upgrade in 2.1 version.
   ```
   function _M.get_body(max_size, ctx)
       -- TODO: improve the check with set client_max_body dynamically
       -- which requires to change Nginx source code
   ```
   Then I change the client_max_body in config.yaml
   ```yaml
   client_max_body_size: 512m        # The maximum allowed size of the client request body.
   ```
   But I still can only get those 10,000 characters, How should I set it?
   ### Environment
   
   * apisix version (cmd: `apisix version`): 2.1
   * OS: linux
   


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

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



[GitHub] [apisix] ziyou434 edited a comment on issue #3062: request help: core.request.get_body()

Posted by GitBox <gi...@apache.org>.
ziyou434 edited a comment on issue #3062:
URL: https://github.com/apache/apisix/issues/3062#issuecomment-747150775


   ```lua
   function _M.get_body(max_size, ctx)
       -- TODO: improve the check with set client_max_body dynamically
       -- which requires to change Nginx source code
       if max_size then
           local var = ctx and ctx.var or ngx.var
           local content_length = tonumber(var.http_content_length)
           if content_length then
               local ok, err = check_size(content_length, max_size)
               if not ok then
                   -- When client_max_body_size is exceeded, Nginx will set r->expect_tested = 1 to
                   -- avoid sending the 100 CONTINUE.
                   -- We use trick below to imitate this behavior.
                   if test_expect(var) then
                       clear_header("expect")
                   end
   
                   return nil, err
               end
           end
       end
   
       req_read_body()
   
       local req_body = req_get_body_data()
       if req_body then
           local ok, err = check_size(#req_body, max_size)
           if not ok then
               return nil, err
           end
   
           return req_body
       end
   
       local file_name = req_get_body_file()
       if not file_name then
           return nil
       end
   
       log.info("attempt to read body from file: ", file_name)
   
       if max_size then
           local size, err = lfs.attributes (file_name, "size")
           if not size then
               return nil, err
           end
   
           local ok, err = check_size(size, max_size)
           if not ok then
               return nil, err
           end
       end
   
       local req_body, err = get_file(file_name)
       return req_body, err
   end
   ```
   In my opinion, ngx.req_get_body_data() can't handle 40,000 characters. 
   I guess ngx.req_get_body_file() takes effect, but I can't find client_body_buffer_size in nginx.conf .
   Is the buffer not large enough to display only 12,000 characters ?
   


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

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



[GitHub] [apisix] spacewander closed issue #3062: request help: core.request.get_body()

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #3062:
URL: https://github.com/apache/apisix/issues/3062


   


-- 
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] ziyou434 commented on issue #3062: request help: core.request.get_body()

Posted by GitBox <gi...@apache.org>.
ziyou434 commented on issue #3062:
URL: https://github.com/apache/apisix/issues/3062#issuecomment-747163765


   I redid some experiments and found that 12,000 characters was what ngx.req_get_body_data() got.
   So I use ngx.req_get_body_file() to find
   ```lua
    ngx.req.read_body()
       local body_file = ngx.req.get_body_file()
       if body_file then
           local data = core.request.get_file(body_file)
       end
       core.log.warn("data: ",data)
   ```
   data: nil


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

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



[GitHub] [apisix] ziyou434 commented on issue #3062: request help: core.request.get_body()

Posted by GitBox <gi...@apache.org>.
ziyou434 commented on issue #3062:
URL: https://github.com/apache/apisix/issues/3062#issuecomment-747272459


   finally I find ngx.log cut the body ,get_body() can receive all charactors.
   I will close this issue.


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

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



[GitHub] [apisix] ziyou434 commented on issue #3062: request help: core.request.get_body()

Posted by GitBox <gi...@apache.org>.
ziyou434 commented on issue #3062:
URL: https://github.com/apache/apisix/issues/3062#issuecomment-747150775


   ```lua
   function _M.get_body(max_size, ctx)
       -- TODO: improve the check with set client_max_body dynamically
       -- which requires to change Nginx source code
       if max_size then
           local var = ctx and ctx.var or ngx.var
           local content_length = tonumber(var.http_content_length)
           if content_length then
               local ok, err = check_size(content_length, max_size)
               if not ok then
                   -- When client_max_body_size is exceeded, Nginx will set r->expect_tested = 1 to
                   -- avoid sending the 100 CONTINUE.
                   -- We use trick below to imitate this behavior.
                   if test_expect(var) then
                       clear_header("expect")
                   end
   
                   return nil, err
               end
           end
       end
   
       req_read_body()
   
       local req_body = req_get_body_data()
       if req_body then
           local ok, err = check_size(#req_body, max_size)
           if not ok then
               return nil, err
           end
   
           return req_body
       end
   
       local file_name = req_get_body_file()
       if not file_name then
           return nil
       end
   
       log.info("attempt to read body from file: ", file_name)
   
       if max_size then
           local size, err = lfs.attributes (file_name, "size")
           if not size then
               return nil, err
           end
   
           local ok, err = check_size(size, max_size)
           if not ok then
               return nil, err
           end
       end
   
       local req_body, err = get_file(file_name)
       return req_body, err
   end
   ```
   In my opinion, ngx.req.read_body() can't handle 40,000 characters. 
   I guess ngx.req_get_body_file() takes effect, but I can't find client_body_buffer_size in nginx.conf .
   Is the buffer not large enough to display only 12,000 characters ?
   


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

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