Re: PHP - I give up.

From: Michael Wojcik (mwojcik_at_newsguy.com)
Date: 03/01/04


Date: 1 Mar 2004 16:23:08 GMT


In article <c1q0mn$bli$1@sparta.btinternet.com>, Richard Heathfield <dontmail@address.co.uk.invalid> writes:
>
> #include <stdio.h>
> int main(void)
> {
> printf("Content-Type: text/html\n\n");

Bill's already noted that he no longer has the account to test this,
but I thought I'd point out that this program may not be correct,
depending on C implementation behavior. The HTTP specs (1.0 or 1.1)
require that headers be terminated with the sequence CR LF, and the
content-body be separated from the headers with an empty line
terminated with CR LF.

If the C implementation is one that translates \n into CR LF for
text-mode streams (typical for implementations on Windows), then
this printf will produce valid HTTP output. If the implementation
translates \n into a bare LF (typical for Unix), then it won't.

Servers may recognize bare LF as equivalent to CR LF, but they are
not obligated to by the HTTP (or CGI) standards.

The simple program Bill posted also had this implementation-defined
behavior, which could have been the source of his problem.

Unfortunately there's no portable solution to this, since there's no
portable way to determine what an implementation does with \n, or to
force standard output into binary mode, or to write to standard
output in binary mode regardless of how it's opened. Of course it's
relatively easy to handle once you know what your implementation
does.

-- 
Michael Wojcik                  michael.wojcik@microfocus.com
Most people believe that anything that is true is true for a reason.
These theorems show that some things are true for no reason at all,
i.e., accidentally, or at random.  -- G J Chaitin


Relevant Pages

  • Re: kids and their furniture?
    ... I would always honor and respect any house rules I was ... standards that differed significantly from the range of behaviors ... I think it's pretty close to the legal 'reasonable person' standard. ... too much work to reason one's way through every single ...
    (misc.kids)
  • Re: I dont get how the computer arrives at 2^31
    ... > Standard isn't always as careful with the language it uses. ... something that will make its functionality "equivalent" to fprintf(). ... function that created the va_list value passed to vfprintf(). ... The reason is that, unless ...
    (comp.std.c)
  • Re: How do you imagine future Common Lisp standard ?
    ... Scheme doesn't focus on good macro ... Goodness and Badness must be evaluated in a particular design-space ... It's fortunate that this can be done without change to the standard, ... There's no reason to define the old language away, ...
    (comp.lang.lisp)
  • Re: Understanding # and function variables
    ... That's the reason for my statement that I don't care whether a ... >>change is standard compliant or not. ... >>substantial revision of ANSI Common Lisp and would provide equally ... I will find out about an already existing language that is strictly ...
    (comp.lang.lisp)
  • Re: Bug? Download ueber script - Adresszeile bleibt haengen
    ... "Content-Disposition is not part of the HTTP standard, ... Dass es für MIME Standard ist bringt mir hierbei ja nicht viel. ... was in RFC 2616 zu diesem Header steht. ... Datei genau an und beschliesst dann zu streiken wenn der Inhalt ...
    (microsoft.public.de.german.inetexplorer.ie6)