Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > [OT] minimalist web server

Reply
Thread Tools

[OT] minimalist web server

 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-02-2007
Hi list,

This is waaaaay off topic but maybe somebody knowledgeable can help.

I'm looking for the most minimalist web server ever that does nothing
else than return a fixed static page for every request. Regardless of
what the request is, it just needs to be an HTTP request to port 80,
the web server should return always the same html document. What would
be the best choice for this? The goal is of course to minimize system
resources in terms of memory, cpu, etc, etc.

Cheers,
Daniel
 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      12-02-2007
"Daniel Fetchinson" <(E-Mail Removed)> writes:
> I'm looking for the most minimalist web server ever that does nothing
> else than return a fixed static page for every request. Regardless of
> what the request is, it just needs to be an HTTP request to port 80,
> the web server should return always the same html document. What would
> be the best choice for this? The goal is of course to minimize system
> resources in terms of memory, cpu, etc, etc.


If you're running linux, maybe you want tux.

publicfile isn't exactly what you describe, but its description might
be of some interest:

http://cr.yp.to/publicfile.html
 
Reply With Quote
 
 
 
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-02-2007
> > I'm looking for the most minimalist web server ever that does nothing
> > else than return a fixed static page for every request. Regardless of
> > what the request is, it just needs to be an HTTP request to port 80,
> > the web server should return always the same html document. What would
> > be the best choice for this? The goal is of course to minimize system
> > resources in terms of memory, cpu, etc, etc.

>
> If you're running linux, maybe you want tux.
>
> publicfile isn't exactly what you describe, but its description might
> be of some interest:
>
> http://cr.yp.to/publicfile.html



Thanks, tux looks good, the only problem is that one needs to
recompile the kernel which I really don't want to do (so yes, I'm on
linux). Publicfile seems to "know" already too much.

The reason I need this is that my current best strategy to avoid ads
in web pages is putting all ad server names into /etc/hosts and stick
my local ip number next to them (127.0.0.1) so every ad request goes
to my machine. I run apache which has an empty page for 404 errors so
I'll just see that blank page for every ad. Now I guess apache is a
pretty heavy weight guy so I'm looking for a lightweight alternative.
Lighttpd, nginx and company are all too complex and "know" too much. I
even considered just putting netcat into an infinite loop but I'm
afraid if there is a security hole in netcat I might be screwed.

Maybe now that I outlined a little more why I need this others can
come up with more suggestions.
 
Reply With Quote
 
Daniel Fetchinson
Guest
Posts: n/a
 
      12-02-2007
Maybe I found what I'm looking for: cheetah, a web server that is 600
lines of C code and that's it

http://freshmeat.net/projects/cheetahd/


On 12/1/07, Daniel Fetchinson <(E-Mail Removed)> wrote:
> > > I'm looking for the most minimalist web server ever that does nothing
> > > else than return a fixed static page for every request. Regardless of
> > > what the request is, it just needs to be an HTTP request to port 80,
> > > the web server should return always the same html document. What would
> > > be the best choice for this? The goal is of course to minimize system
> > > resources in terms of memory, cpu, etc, etc.

> >
> > If you're running linux, maybe you want tux.
> >
> > publicfile isn't exactly what you describe, but its description might
> > be of some interest:
> >
> > http://cr.yp.to/publicfile.html

>
>
> Thanks, tux looks good, the only problem is that one needs to
> recompile the kernel which I really don't want to do (so yes, I'm on
> linux). Publicfile seems to "know" already too much.
>
> The reason I need this is that my current best strategy to avoid ads
> in web pages is putting all ad server names into /etc/hosts and stick
> my local ip number next to them (127.0.0.1) so every ad request goes
> to my machine. I run apache which has an empty page for 404 errors so
> I'll just see that blank page for every ad. Now I guess apache is a
> pretty heavy weight guy so I'm looking for a lightweight alternative.
> Lighttpd, nginx and company are all too complex and "know" too much. I
> even considered just putting netcat into an infinite loop but I'm
> afraid if there is a security hole in netcat I might be screwed.
>
> Maybe now that I outlined a little more why I need this others can
> come up with more suggestions.
>

 
Reply With Quote
 
David Tweet
Guest
Posts: n/a
 
      12-02-2007
Running this in Python should create a server running on localhost
port 80 that only serves blank pages:

import SimpleHTTPServer
import SocketServer

class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandle r):
def do_GET(self):
print >> self.wfile, ""

server = SocketServer.TCPServer(("", 80), MyHandler)
server.serve_forever()

(also see http://effbot.org/librarybook/simplehttpserver.htm)

On Dec 1, 2007 7:02 PM, Daniel Fetchinson <(E-Mail Removed)> wrote:
> > > I'm looking for the most minimalist web server ever that does nothing
> > > else than return a fixed static page for every request. Regardless of
> > > what the request is, it just needs to be an HTTP request to port 80,
> > > the web server should return always the same html document. What would
> > > be the best choice for this? The goal is of course to minimize system
> > > resources in terms of memory, cpu, etc, etc.

> >
> > If you're running linux, maybe you want tux.
> >
> > publicfile isn't exactly what you describe, but its description might
> > be of some interest:
> >
> > http://cr.yp.to/publicfile.html

>
>
> Thanks, tux looks good, the only problem is that one needs to
> recompile the kernel which I really don't want to do (so yes, I'm on
> linux). Publicfile seems to "know" already too much.
>
> The reason I need this is that my current best strategy to avoid ads
> in web pages is putting all ad server names into /etc/hosts and stick
> my local ip number next to them (127.0.0.1) so every ad request goes
> to my machine. I run apache which has an empty page for 404 errors so
> I'll just see that blank page for every ad. Now I guess apache is a
> pretty heavy weight guy so I'm looking for a lightweight alternative.
> Lighttpd, nginx and company are all too complex and "know" too much. I
> even considered just putting netcat into an infinite loop but I'm
> afraid if there is a security hole in netcat I might be screwed.
>
> Maybe now that I outlined a little more why I need this others can
> come up with more suggestions.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>




--
-David
 
Reply With Quote
 
Dave Benjamin
Guest
Posts: n/a
 
      12-02-2007
Daniel Fetchinson wrote:
> The reason I need this is that my current best strategy to avoid ads
> in web pages is putting all ad server names into /etc/hosts and stick
> my local ip number next to them (127.0.0.1) so every ad request goes
> to my machine. I run apache which has an empty page for 404 errors so
> I'll just see that blank page for every ad. Now I guess apache is a
> pretty heavy weight guy so I'm looking for a lightweight alternative.
> Lighttpd, nginx and company are all too complex and "know" too much. I
> even considered just putting netcat into an infinite loop but I'm
> afraid if there is a security hole in netcat I might be screwed.


I don't know if this qualifies as "lightweight", but my current best
strategy is to block ads using a Squid proxy. My /etc/squid/squid.conf has:

acl ads dstdom_regex -i "/etc/squid/squid.adservers"
http_access deny ads
deny_info javascript:void(0) ads

/etc/squid/squid.adservers came from this site:
http://pgl.yoyo.org/adservers/

Ads completely disappear with no visible errors or unnecessary HTTP
requests. (Sorry, no Python needed for this one.)

Dave
 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      12-02-2007
Daniel Fetchinson wrote:
> Maybe I found what I'm looking for: cheetah, a web server that is 600
> lines of C code and that's it
>
> http://freshmeat.net/projects/cheetahd/


For the sake of on-topicness, there is this:



#!/usr/bin/env python
# -*- coding: ASCII -*-
'''$Id$
'''
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleRequestHandler

handler = HTTPServer (('', 8000), SimpleRequestHandler)
handler.handle_forever()



Mel.
 
Reply With Quote
 
Paul Rubin
Guest
Posts: n/a
 
      12-02-2007
> from SimpleHTTPServer import SimpleRequestHandler
> handler = HTTPServer (('', 8000), SimpleRequestHandler)



I think you mean SimpleHTTPRequestHandler. Note that actually reads
the url path and looks in the file system to get the file of that
name, which isn't what the OP wanted.

The OP might also try the junkbuster proxy (google for it) which I
think was renamed a while back.
 
Reply With Quote
 
I V
Guest
Posts: n/a
 
      12-02-2007
On Sat, 01 Dec 2007 19:02:41 -0800, Daniel Fetchinson wrote:
> The reason I need this is that my current best strategy to avoid ads in
> web pages is putting all ad server names into /etc/hosts and stick my
> local ip number next to them (127.0.0.1) so every ad request goes to my
> machine. I run apache which has an empty page for 404 errors so I'll


In this case, do you need a webserver at all? If your browser tries to
access a web server on 127.0.0.1 and there isn't one, won't the result,
in most cases, be more or less the same as if the server returned a 404?
 
Reply With Quote
 
Michael Ströder
Guest
Posts: n/a
 
      12-02-2007
Paul Rubin wrote:
>> from SimpleHTTPServer import SimpleRequestHandler
>> handler = HTTPServer (('', 8000), SimpleRequestHandler)

>
>
> I think you mean SimpleHTTPRequestHandler. Note that actually reads
> the url path and looks in the file system to get the file of that
> name, which isn't what the OP wanted.


But it's very easy to override the handler method and return the 404 for
each and every request.

Ciao, Michael.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tiny/small/minimalist Python? rtk Python 16 07-06-2007 05:02 PM
Very Simple, Minimalist Technique For OOP in C... Chris Thomasson C Programming 10 06-24-2007 07:53 PM
minimalist regular expression borges2003xx@yahoo.it Python 10 08-26-2005 07:12 PM
Minimalist executable Sam C Programming 3 08-15-2003 11:32 PM
Use Cases -- A minimalist's View Uncle Bob (Robert C. Martin) Java 0 07-02-2003 02:45 PM



Advertisments