in reply to Learning HTTP headers

I was under the impression that one should use
\r\n
as line terminators when playing with web servers, since this would signal end of line to Mac, Windows, and *NIX machines.

Replies are listed 'Best First'.
Re: Re: Learning HTTP headers
by Fastolfe (Vicar) on Nov 27, 2000 at 19:26 UTC
    Two misconceptions here (one in theory, the other in implementation). Most web servers adapt fine to different newline styles, so normally this isn't a problem, but you are correct in that the "correct" newline representation wasn't accurate in the original code.

    However, "\r\n" is not the way a correct newline should be represented. \n does not have a direct, portable mapping to a specific ASCII code. Instead, it's Perl's representation of a "newline", which WILL vary depending upon the OS being used. Thus, while "\r\n" will give you the desired results under Unix, it will break even more under Windows or on MacOS. If you want to be strict about your newlines, you need to use "\015\012".

      Ahh, right -- thanks.

      I knew there was something like this going on, and whenever I think about doing server/client type things I am reminded of the general philosophy that one should be strict in conforming (when initiating contact) and lax in demanding conformity (when receiving contact). It's nice to know how to do things "right" :)

      Of course, in most cases here, "right" will involve an LWP module :)