0

I am currently developing a HTTP server application, and I am struggling with the size of body payloads.

According to the spec (and also What's the “Content-Length” field in HTTP header?), the HTTP header Content-Length contains the actual number of bytes of the whole body payload.

Now, say I'm firing this:

curl --header "Content-Type: text/plain" --request POST --data 'test' http://localhost:5555/

my server will receive a Content-Length header which contains the value 4. Since I am sending a string, and the string including null-byte will have 5 bytes, I would expect the Content-Length to be 5, and the request body to contain the null-byte as well.

Is my assumption wrong? Or is this some kind of curl issue? I tried with another tool (Paw on Mac), which actually has the option of sending text payloads, with the same result.

user826955
  • 3,137
  • 2
  • 30
  • 71
  • The string that you're sending here doesn't contain a null byte, so 4 is the correct length. – Julian Reschke Sep 07 '18 at 15:54
  • Okay so you mean both those tools send only 4 bytes although I am giving them a string which is having 5 bytes in total? I mean thats the definition of string (that it includes a nullbyte beyond the character count). So is this to be expected/normal that clients will **not** send a nullbyte when they are (knowingly) sending string data? – user826955 Sep 10 '18 at 06:04
  • No, that's not the definition of "String". How string lengths are handled (end-of-string marker vs length counter) depends on the programming language/environment. – Julian Reschke Sep 10 '18 at 09:59

0 Answers0