Page 1 of 1

PB based webserver

Posted: Mon Jan 31, 2005 8:08 am
by kake26
Hi all,
Out of sheer curiousity and my want to learn HTTP. I've decided to build a webserver in PB, using what I have learned from my perl proxy script that I used to spy on how my web browser interacts with the web. HTTP has proven simple enough to understand. I've decided to build a this PB webserver for grins and even try to implement CGI capability. Just piecing together what I learn from RFC's and my little proxy app. If anyone cares I'll release the source as I go along. Keep in mind I'm doing this for grins and learn what HTTP servers really do, which is seemingly very little. I noticed there was a sample webserver along with my PB install, which I have glanced at, but decided its better to just build from scratch rather than figure out existing code. Plus, that way I completly understand what the hell I wrote. I'll be more than happy to disclose what I've learned to those that want to know. After this I might just finish that mail server I've been working on.

Posted: Mon Jan 31, 2005 9:10 am
by blueznl
i bet more than one person will be interested in the results!

Posted: Mon Jan 31, 2005 1:30 pm
by Fred
There is already a webserver in the example folder which works for linux and windows.

Posted: Mon Jan 31, 2005 6:14 pm
by kake26
Fred wrote:There is already a webserver in the example folder which works for linux and windows.
Fred I know, but I'm talking about going above and beyond what that one can do. I'm talking CGI support and all kinds of stuff. I did look at the example, but decided to do a new one from scratch, since that be easier for me than to canabalize the existing code. Also supporting alot more than just serving a few simple HTML pages.

Posted: Tue Feb 01, 2005 6:13 pm
by Tommeh
Perl/Python/PHP is VERY easy to implement and support in a web server, How ever ASP/.net is not, I never managed to get it running with mine but i gave that up a long time ago,

PHP is by far the easiest to implement

1) When a requested file matches the MIME type for PHP, Get the real location of the file by using the Eviroment Veriable 'PATH_TRANSLATED'

2) Second, Open a pipe to php.exe (normally in C:\Php) and call the script location as a paremeter.

3) The output data from php.exe will be the result of the executed php file, Then you just send this information to the browser :-)

Enviroment Veriable, Opening a pipe and getting the ouput can be used very easily from El_Choni's CGI lib, or all the sources for opening pipe and env veriable is on the CodeArchiv :-)

For the others you will have to research it or tare an open source web server apart :D

Posted: Wed Feb 02, 2005 6:29 am
by kake26
That answers my question about PHP, lol. Thanks, PHP and Perl will be easy to support. Any perl CGI app can be feed the crap after the ? directly. Sounds like PHP can too if I pipe it. That won't be hard to do. Oh, fyi I'm not making this server under windows. Anyhow thanks for the info.

Posted: Wed Feb 02, 2005 6:57 am
by kake26
Well, as for piping looks like I'll need to reach into my bad of tricks and write myself a lib for that under linux. Most likely gonna write it in FPC, or if I feel adventurous C even.

Posted: Wed Feb 02, 2005 4:52 pm
by Tommeh
Ahh, I didnt relealise you were working under linux, Guess you can't use the CGI lib or any of the examples i suggested from the codearchiv.

Surly it wouldnt require to write a lib for it, Correct me if im wrong because i really don't know anything about Linux, But this should work?

Code: Select all

exec php.exe>stdout.out
As i said that may not work at all, but worth a shot? and maybe this page might help with redirecting pipes

http://www.cpqlinux.com/redirect.html


Also, If you wish i can give you the source to my partitaly coded web server, It has directory traverse protection, Directory listing, Mime types but i stopped because i got bored :s so its vulnerable to buffer overflows, I just extended the PB web server example.