URGENT: Prevent default HTTP headers from being sent

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lisa Pearlson

    URGENT: Prevent default HTTP headers from being sent

    Hi,

    I have a php script with no more than this:

    <?php echo "Hello World!"; ?>

    When a webbrowser client requests data, it receives Apache server headers,
    followed by my data:

    HTTP/1.1 200 OK
    Date: Tue, 28 Jun 2005 06:02:56 GMT
    Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b
    DAV/1.0.2 PHP/4.1.2 mod_perl/1.26
    X-Powered-By: PHP/4.1.2
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: text/html

    c
    Hello World!
    0

    =============== ========
    QUESTIONS:
    - Where do the 'c' and '0' come from? '0' just denoting the end of the data?
    - How do I prevent HTTP headers sent back to the client? I wish to only send
    "Hello World!", without any headers. The reason is that the client will be a
    piece of hardware that expects binary data as response, not HTTP headers.
    I don't think this can be done with PHP, as it is probably handled by
    apache.
    If so, can I use Apache's RewriteEngine to accomplish this, in case
    User-Agent is "^MyThinHardwar e.*" ?
    How can I keep Apache from sending these headers?
    =============== ========

    I use the following php script to simulate a client requesting the php page,
    and display the headers:

    $header = "POST $cgi HTTP/1.1\r\n";
    $header .= "Host: $host\r\n";
    $header .= "User-Agent: MyThinHardware/1.0\r\n";
    $header .= "Content-Type: application/octet-stream\r\n";
    $header .= "Content-Length: $size\r\n";
    $header .= "Connection : close\r\n";
    $header .= "\r\n";


    /* post data */
    $fp = fsockopen($host , 80, $errno, $errstr, 30);
    if (!$fp) {
    die("$errstr ($errno)");
    }
    else {
    fwrite($fp, $header);
    fwrite($fp, $data, $size);
    while (!feof($fp)) {
    $response .= fgets($fp, 128);
    }
    fclose($fp);
    }
    echo $response;


  • Colin McKinnon

    #2
    Re: URGENT: Prevent default HTTP headers from being sent

    Lisa Pearlson wrote:
    [color=blue]
    > Hi,
    >
    > I have a php script with no more than this:
    >
    > <?php echo "Hello World!"; ?>
    >[/color]
    <snip>[color=blue]
    >
    > c
    > Hello World!
    > 0
    >
    > =============== ========
    > QUESTIONS:
    > - Where do the 'c' and '0' come from? '0' just denoting the end of the
    > data? -[/color]

    They shouldn't be there - most likely a charset issue - from the shell try
    cat -v myscript.php
    [color=blue]
    > How do I prevent HTTP headers sent back to the client? I wish to
    > only send "Hello World!", without any headers.[/color]

    Then you can't do it via HTTP / an apache module (actually, you probably
    could, but it would ned a lot of hacking). Without HTTP though, there's no
    defined way of getting parameters into your script.
    [color=blue]
    > The reason is that the
    > client will be a piece of hardware that expects binary data as response,[/color]
    <snip>[color=blue]
    >
    > I use the following php script to simulate a client requesting the php
    > page, and display the headers:
    >
    > $header = "POST $cgi HTTP/1.1\r\n";
    > $header .= "Host: $host\r\n";[/color]
    <snip>

    There's something very broken here - the client wants to talk HTTP, but you
    say that it won't listen to HTTP. R U sure?

    C.

    Comment

    • Alvaro G Vicario

      #3
      Re: URGENT: Prevent default HTTP headers from being sent

      *** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):[color=blue]
      > - How do I prevent HTTP headers sent back to the client? I wish to only send
      > "Hello World!", without any headers. The reason is that the client will be a
      > piece of hardware that expects binary data as response, not HTTP headers.[/color]

      Then, why use HTTP if the response must not follow the protocol rules? As
      far as I know Apache will always send, at a minimum, the status line with
      the numeric status code. Can't your write a simple daemon that listens in a
      port? As you probably know you can write shell scripts in PHP.



      --
      -- Álvaro G. Vicario - Burgos, Spain
      -- http://bits.demogracia.com - Mi sitio sobre programación web
      -- Don't e-mail me your questions, post them to the group
      --

      Comment

      • Daniel Tryba

        #4
        Re: URGENT: Prevent default HTTP headers from being sent

        Lisa Pearlson <no@spam.plz> wrote:[color=blue]
        > Transfer-Encoding: chunked
        >
        > c
        > Hello World!
        > 0
        >
        > - Where do the 'c' and '0' come from? '0' just denoting the end of the data?[/color]

        That is the chunked transfer encoding. See RFC 2616. Can be solved by
        either supplying a content-length or by making http/1.0 requests instead
        of http/1.1
        [color=blue]
        > - How do I prevent HTTP headers sent back to the client? I wish to only send
        > "Hello World!", without any headers. The reason is that the client will be a
        > piece of hardware that expects binary data as response, not HTTP headers.
        > I don't think this can be done with PHP, as it is probably handled by
        > apache.[/color]

        Then don't use a http daemon. You can run a serversocket with PHP and
        have your system connect to that. OR you could simple evolve your
        embedded system to understand HTTP. If the client makes a HTTP/1.0
        request it can simply ignore output till after the first \r\n\r\n
        sequence.

        Comment

        • Lisa Pearlson

          #5
          Re: URGENT: Prevent default HTTP headers from being sent

          the client is dumb, it has no use for the http headers, it always expects a
          fixed length binary data.
          It can send headers just to please apache and make sure it gets to the right
          script on the right domain.

          I use http instead of writing my own daemon, so I can take advantage of
          apache's features, such as handling a lot of simultaneous connections and
          other tools meant for http, such as logging software etc. if I can use a
          standard solution, it's always better than writing my own.. especially if it
          suits all my needs except one minor one, useless headers.

          Getting rid of these headers is only important because communication is very
          expensive, per kilobyte of data.. so every byte I can save, leads to quite a
          big saving.


          "Colin McKinnon" <colin.deleteth is@andthis.mms3 .com> wrote in message
          news:d9r0a8$69d $1$8300dec7@new s.demon.co.uk.. .[color=blue]
          > Lisa Pearlson wrote:
          >[color=green]
          >> Hi,
          >>
          >> I have a php script with no more than this:
          >>
          >> <?php echo "Hello World!"; ?>
          >>[/color]
          > <snip>[color=green]
          >>
          >> c
          >> Hello World!
          >> 0
          >>
          >> =============== ========
          >> QUESTIONS:
          >> - Where do the 'c' and '0' come from? '0' just denoting the end of the
          >> data? -[/color]
          >
          > They shouldn't be there - most likely a charset issue - from the shell try
          > cat -v myscript.php
          >[color=green]
          >> How do I prevent HTTP headers sent back to the client? I wish to
          >> only send "Hello World!", without any headers.[/color]
          >
          > Then you can't do it via HTTP / an apache module (actually, you probably
          > could, but it would ned a lot of hacking). Without HTTP though, there's no
          > defined way of getting parameters into your script.
          >[color=green]
          >> The reason is that the
          >> client will be a piece of hardware that expects binary data as response,[/color]
          > <snip>[color=green]
          >>
          >> I use the following php script to simulate a client requesting the php
          >> page, and display the headers:
          >>
          >> $header = "POST $cgi HTTP/1.1\r\n";
          >> $header .= "Host: $host\r\n";[/color]
          > <snip>
          >
          > There's something very broken here - the client wants to talk HTTP, but
          > you
          > say that it won't listen to HTTP. R U sure?
          >
          > C.[/color]


          Comment

          • Lisa Pearlson

            #6
            Re: URGENT: Prevent default HTTP headers from being sent

            Writing my own server is risky.. both performance and stability with
            concurrent connections is an issue. I prefer to use apache. Just need to
            limit unused overhead as much as possible.

            "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> wrote in
            message news:1kwuoykm3h b6g$.1awx2mafb1 xc9$.dlg@40tude .net...[color=blue]
            > *** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):[color=green]
            >> - How do I prevent HTTP headers sent back to the client? I wish to only
            >> send
            >> "Hello World!", without any headers. The reason is that the client will
            >> be a
            >> piece of hardware that expects binary data as response, not HTTP headers.[/color]
            >
            > Then, why use HTTP if the response must not follow the protocol rules? As
            > far as I know Apache will always send, at a minimum, the status line with
            > the numeric status code. Can't your write a simple daemon that listens in
            > a
            > port? As you probably know you can write shell scripts in PHP.
            >
            >
            >
            > --
            > -- Álvaro G. Vicario - Burgos, Spain
            > -- http://bits.demogracia.com - Mi sitio sobre programación web
            > -- Don't e-mail me your questions, post them to the group
            > --[/color]


            Comment

            • Lisa Pearlson

              #7
              Re: URGENT: Prevent default HTTP headers from being sent

              > You can run a serversocket with PHP and[color=blue]
              > have your system connect to that.[/color]

              Can you elaborate on this?

              Lisa


              Comment

              • Daniel Tryba

                #8
                Re: URGENT: Prevent default HTTP headers from being sent

                Lisa Pearlson <no@spam.plz> wrote:[color=blue][color=green]
                >> You can run a serversocket with PHP and
                >> have your system connect to that.[/color]
                >
                > Can you elaborate on this?[/color]

                http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
                good idea.

                Comment

                • Alvaro G Vicario

                  #9
                  Re: URGENT: Prevent default HTTP headers from being sent

                  *** Lisa Pearlson wrote/escribió (Wed, 29 Jun 2005 02:36:09 +0200):[color=blue]
                  > Writing my own server is risky.. both performance and stability with
                  > concurrent connections is an issue. I prefer to use apache. Just need to
                  > limit unused overhead as much as possible.[/color]

                  It seems unlikely to me that Apache+PHP offers better performance than only
                  PHP but of course's we'd need to benchmark the specific case. However, a
                  faster web server* may be a solution then (given that your embedded system
                  can finally understand HTTP).

                  (*) You have thttpd and some others

                  --
                  -- Álvaro G. Vicario - Burgos, Spain
                  -- http://bits.demogracia.com - Mi sitio sobre programación web
                  -- Don't e-mail me your questions, post them to the group
                  --

                  Comment

                  • Lisa Pearlson

                    #10
                    Re: URGENT: Prevent default HTTP headers from being sent

                    Interesting..
                    Hoever, like the article suggest, you need to take a lot of security
                    measures into account. I can't be messing with that.
                    Apache has evolved over many years..
                    I mean, it would take you only 2 days to write an HTTP web server in PHP,
                    but .. I wouldn't trust it, woud you?

                    Lisa

                    "Daniel Tryba" <partmapsswen@i nvalid.tryba.nl > wrote in message
                    news:42c201a8$0 $58579$c5fe704e @news6.xs4all.n l...[color=blue]
                    > Lisa Pearlson <no@spam.plz> wrote:[color=green][color=darkred]
                    >>> You can run a serversocket with PHP and
                    >>> have your system connect to that.[/color]
                    >>
                    >> Can you elaborate on this?[/color]
                    >
                    > http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
                    > good idea.
                    >[/color]


                    Comment

                    • Lisa Pearlson

                      #11
                      Re: URGENT: Prevent default HTTP headers from being sent

                      Writing a HTTP server in PHP sounded so easy, I figured someone else already
                      thought of doing this:





                      "Lisa Pearlson" <no@spam.plz> wrote in message
                      news:42c411c2$0 $29189$e4fe514c @dreader24.news .xs4all.nl...[color=blue]
                      > Interesting..
                      > Hoever, like the article suggest, you need to take a lot of security
                      > measures into account. I can't be messing with that.
                      > Apache has evolved over many years..
                      > I mean, it would take you only 2 days to write an HTTP web server in PHP,
                      > but .. I wouldn't trust it, woud you?
                      >
                      > Lisa
                      >
                      > "Daniel Tryba" <partmapsswen@i nvalid.tryba.nl > wrote in message
                      > news:42c201a8$0 $58579$c5fe704e @news6.xs4all.n l...[color=green]
                      >> Lisa Pearlson <no@spam.plz> wrote:[color=darkred]
                      >>>> You can run a serversocket with PHP and
                      >>>> have your system connect to that.
                      >>>
                      >>> Can you elaborate on this?[/color]
                      >>
                      >> http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
                      >> good idea.
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      Working...