DEAR PEOPLE FROM THE FUTURE: Here's what we've figured out so far...

Welcome! This is a Q&A website for computer programmers and users alike, focused on helping fellow programmers and users. Read more

What are you stuck on? Ask a question and hopefully somebody will be able to help you out!
+1 vote

It seems like when I curl an HTTP request, sometimes I get a newline and other times I do not.

In my shell, I use the -w "\n" option to append a newline, but using that also makes me wonder if there's a way to add the newline only when the response does not end with one.

In my shell, it sometimes breaks cycling back through history and the reverse search if the response does not have a newline.

by

1 Answer

+1 vote
 
Best answer

Messages consist of headers, an empty line, and optional body (4.1 Message Types). Some responses such as 304 Not Modified do not have a body, and they end at the first empty line. If there is a body, the message ends where Content-Length says so (but there are other cases: 4.4 Message Length). If there is a body and the message ends with a newline, the newline is part of the body and not of the request/response. If the request/response itself is prefaced or followed by additional newlines, it's a buggy implementation.

by
selected by
Contributions licensed under CC0
...