I can think of one very good case where you may wish to send headers by
themselves: When doing session management, so you can keep the
Set-Cookie code out of the main bulk of code, and don't need to remember
that you need to put that header in. Another case could be toggling
debug data like what FirePHP does.
I'm moreso in favour of having:
resp.sendStatus(...);
resp.setHeader(...);
resp.send(...);
> Err, typo. It's "sendHeader" which I think is a fine name. You send
> the header of the http message - the first line of which includes the
> status code... The nomenclature is: The "http message" usually has two
> parts, a "header" and a "body". The "header" consists of a "request
> line" or a "status line" and several "header lines".
Hi Ryan, sorry to take so long to respond; been swamped at work. I
hope it's not too late to resurrect this thread!
So, the point I've been trying to make in this thread is that in a
HTTP library, using the terminology "header" in a different way from
how it's used in HTTP is confusing and causes dissonance.
HTTP has something called a "header", and it's not the thing you
describe above. In fact, HTTP doesn't have the thing you describe
above at all. You said the HTTP message "usually has two parts", but
actually a HTTP message is comprised of 3 possible parts: the
start-line, the headers, and the body. [1]
Anyway, I don't want any of us to spend any more time debating how to
read the HTTP spec. I personally believe that Node's HTTP library
would be better if ServerResponse.sendHeader() had a different name;
for now let's call it begin(). So I've made the changes in my fork:
http://github.com/aviflax/node and I'd be happy if you'd consider
accepting them, or some version of them. And of course if you choose a
different name that'd be great too, as long as it didn't include the
word "header".
[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
Thanks,
Avi
The HTTP spec provides a little guidance here. It specifies a method
for requesting only the status line + headers be sent: HEAD. It's what
I've always called status + headers and what I've always heard it
referred to as. My vote is for sendHead().
> The HTTP spec provides a little guidance here. It specifies a method
> for requesting only the status line + headers be sent: HEAD. It's what
> I've always called status + headers and what I've always heard it
> referred to as. My vote is for sendHead().
I could live with that!
Although Christopher Lenz's suggestion of begin() as nicely
symmetrical to finish() is pretty nice. OTOH, I do see how using
"send" is clearer and more concrete about what's actually going to
happen.
Meh. I think the term "header" is an appropriate name for the data
before the message body. However, I don't want to grind at the
sensibilities of users, so I will rename the method to something less
controversial, soon.
I will rename the method to something lesscontroversial, soon.