View previous topic :: View next topic |
Author |
Message |
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Tue Nov 07, 2006 6:01 pm Post subject: HTTP headers |
|
|
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 |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Tue Nov 07, 2006 8:02 pm Post subject: |
|
|
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 |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Tue Nov 07, 2006 8:05 pm Post subject: |
|
|
Double post removed. |
|
Back to top |
|
|
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Tue Nov 07, 2006 9:58 pm Post subject: |
|
|
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 |
|
|
Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Wed Nov 08, 2006 9:11 am Post subject: |
|
|
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 |
|
|
|