PB based webserver

Everything else that doesn't fall into one of the other PB categories.
kake26
Enthusiast
Enthusiast
Posts: 157
Joined: Sun Jan 25, 2004 7:21 pm
Contact:

PB based webserver

Post 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.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

i bet more than one person will be interested in the results!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

There is already a webserver in the example folder which works for linux and windows.
Fred - AlphaSND
kake26
Enthusiast
Enthusiast
Posts: 157
Joined: Sun Jan 25, 2004 7:21 pm
Contact:

Post 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.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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
kake26
Enthusiast
Enthusiast
Posts: 157
Joined: Sun Jan 25, 2004 7:21 pm
Contact:

Post 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.
kake26
Enthusiast
Enthusiast
Posts: 157
Joined: Sun Jan 25, 2004 7:21 pm
Contact:

Post 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.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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.
Post Reply