TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN | http compliance if post with content-length:0

3 pointsby waxzcealmost 12 years ago
Hi<p>I have a corner case :-)<p>A library client do a POST request on my server, with 2 headers : &gt; Content-type: application&#x2F;json &gt; Content-length: 0<p>So ATM the server response is 400 (bad request) because json is invalid<p>So the question is : When the content-length of a request is 0, should we parse the body or not ?

2 comments

clementdalmost 12 years ago
To my mind, as long as the Content-type header is set, the server should try to parse the body accordingly.<p>In the case of JSON, an empty body cannot be a JSON representation, but for other formats an empty body can have a meaning.
评论 #6020233 未加载
dalkealmost 12 years ago
What does it matter?<p>What you should do is have the error messages be the same for detecting a length 0 submission and of attempting to parse the empty string as JSON.<p>You can think of the check for length==0 and length==1 as a sort of optimization (no JSON document can be 1 byte long), rather than a corner case.