HTTP headers

 
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions
View previous topic :: View next topic  
Author Message
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Tue Nov 07, 2006 6:01 pm    Post subject: HTTP headers Reply with quote

How are http headers seperated from content?
I am learning python, and decided to make a small webserver.

Here is my code:
Code:

#---------------SEND DATA---------------#

     if header == 200:
          contents = f.read()
          clientsocket.send('200 OK\r\n')
          clientsocket.send('Content-type: '+mime+'\r\n')
          clientsocket.send('\r\n')
          clientsocket.send(contents)
          f.close()
     else:
          clientsocket.send('404 File Not Found\r\n')
          clientsocket.send('Content-type: text/html\r\n')
          clientsocket.send('404 File Not Found')


But it just displays the page like this:
Code:
200 OK
Content-type: text/html

Hello There!



<edit>
If i view the site through a proxy, this dosnt happen.
Can someone else have a look for me?
http://83.100.209.105
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Tue Nov 07, 2006 8:02 pm    Post subject: Reply with quote

The header is separated from the content with a single empty line.

You may want to check out the source code of a webserver I wrote in PHP using the php_sockets extension.

Edit*
I think I crashed your server by requesting /..


Last edited by cmxflash on Tue Nov 07, 2006 8:05 pm; edited 1 time in total
Back to top View user's profile Send private message
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Tue Nov 07, 2006 8:05 pm    Post subject: Reply with quote

Double post removed.
Back to top View user's profile Send private message
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Tue Nov 07, 2006 9:58 pm    Post subject: Reply with quote

cmxflash wrote:
The header is separated from the content with a single empty line.

You may want to check out the source code of a webserver I wrote in PHP using the php_sockets extension.

Edit*
I think I crashed your server by requesting /..


I think you did, since that would be requesting E:/programming/python/httpd/../index.html, which is sub root and dosnt exist.
I'll have to fix that.
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
Mikor
-


Joined: 21 Aug 2006
Posts: 144
Location: Hull, England

PostPosted: Wed Nov 08, 2006 9:11 am    Post subject: Reply with quote

Another question now, I am trying to add PHP support to it now;

Code:
cmd = '"'+path_to_php+'" '+hostfiles+file


This outputs, for example:
Code:
"E:/Servers/Abyss/PHP5/php-cgi.exe" E:/programming/python/httpd/subfolder/2/phptext.php


I then execute it with:
Code:
contents = commands.getoutput(cmd)


But when the command is executed, I always get:
Code:
'{' is not recognised as an internal or external command, operable program, or batch file.


Any ideas?
_________________
Yarrt.com - Free Arcade
RypNet.co.uk - Online Game

MSN:
michael_walker_2004 <at> hotmail <dot> com
Back to top View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Off Topic Discussions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group