Bad characters in request body

23 views
Skip to first unread message

edrezen

unread,
Feb 28, 2018, 4:26:33 AM2/28/18
to ngrest
Hello,

I am trying to retrieve a request body (supposed to be some json object) and I receveive some null characters. Here is  a snippet :
    // *method: POST
   
void echo (ngrest::MessageContext& context)
   
{
        ngrest
::HttpRequest*  request  = static_cast<ngrest::HttpRequest*> (context.request);
       
       
for (size_t i=0; i<request->bodySize; i++)  
       
{
            printf
("%d ", request->body[i]);
       
}
        printf
("\n");
   
}


For instance, I send:
curl -X POST -H 'Content-Type: application/json' -i http://localhost:9098/foobar --data '{"aaa":"bbb"}'

and my 'echo' service displays:
123 34 97 97 97 0 58 34 98 98 98 0 0

I receive the correct number of characters, but there are 3 zero values that are obviously wrong.

Am I missing something ?

Thank you in advance



Dmitry Utkin

unread,
Mar 1, 2018, 4:27:05 AM3/1/18
to ngrest
Hi,

It's ok, because of JSON parser modifies source buffer upon parsing. It replaces some characters to NUL, to make it possible to re-use source buffer for node names and values. This is as designed for performance optimization.

среда, 28 февраля 2018 г., 12:26:33 UTC+3 пользователь edrezen написал:
Reply all
Reply to author
Forward
0 new messages