[OT] minimalist web server

Discussion in 'Python' started by Daniel Fetchinson, Dec 2, 2007.

  1. 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
     
    Daniel Fetchinson, Dec 2, 2007
    #1
    1. Advertising

  2. Daniel Fetchinson

    Paul Rubin Guest

    "Daniel Fetchinson" <> 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
     
    Paul Rubin, Dec 2, 2007
    #2
    1. Advertising

  3. > > 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.
     
    Daniel Fetchinson, Dec 2, 2007
    #3
  4. 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 <> 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.
    >
     
    Daniel Fetchinson, Dec 2, 2007
    #4
  5. Daniel Fetchinson

    David Tweet Guest

    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.SimpleHTTPRequestHandler):
    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 <> 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
     
    David Tweet, Dec 2, 2007
    #5
  6. 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
     
    Dave Benjamin, Dec 2, 2007
    #6
  7. Daniel Fetchinson

    Mel Guest

    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.
     
    Mel, Dec 2, 2007
    #7
  8. Daniel Fetchinson

    Paul Rubin Guest

    > 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.
     
    Paul Rubin, Dec 2, 2007
    #8
  9. Daniel Fetchinson

    I V Guest

    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?
     
    I V, Dec 2, 2007
    #9
  10. 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.
     
    Michael Ströder, Dec 2, 2007
    #10
  11. Daniel Fetchinson

    Guest


    > On Dec 1, 2007 7:02 PM, Daniel Fetchinson <> 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.
    >>


    Running this will start a server on port 80 which will serve files in
    the current folder:

    import SimpleHTTPServer
    import SocketServer
    SocketServer.TCPServer(("",80),SimpleHTTPServer.SimpleHTTPRequestHandler).serve_forever()


    Regards,
    Ghirai.
     
    , Dec 2, 2007
    #11
  12. > > 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?


    Not quite, because if the browser doesn't get a response from the
    server it will keep trying for a while and will only give up after
    that. And then will display a "server not found, blablablabla" message
    depending on the browser, which will appear in place of every ad.
    That's ugly and it's better to have an empty page.

    Concerning the python solutions posted by several guys, they are too
    heavyweight compared to a ~ 1-3 hundred lines of C code that one can
    obtain from cheetah's source code.
     
    Daniel Fetchinson, Dec 3, 2007
    #12
  13. Daniel Fetchinson

    MonkeeSage Guest

    Re: minimalist web server

    On Dec 2, 10:13 pm, "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?

    >
    > Not quite, because if the browser doesn't get a response from the
    > server it will keep trying for a while and will only give up after
    > that. And then will display a "server not found, blablablabla" message
    > depending on the browser, which will appear in place of every ad.
    > That's ugly and it's better to have an empty page.
    >
    > Concerning the python solutions posted by several guys, they are too
    > heavyweight compared to a ~ 1-3 hundred lines of C code that one can
    > obtain from cheetah's source code.


    Then use those lines of source, heh. No need to try to force python to
    fit every problem. If you have a solution that works better in some
    other language, then use it; we won't be angry. :)

    Regards,
    Jordan
     
    MonkeeSage, Dec 3, 2007
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Uncle Bob (Robert C. Martin)

    Use Cases -- A minimalist's View

    Uncle Bob (Robert C. Martin), Jul 2, 2003, in forum: Java
    Replies:
    0
    Views:
    780
    Uncle Bob (Robert C. Martin)
    Jul 2, 2003
  2. Sam

    Minimalist executable

    Sam, Aug 15, 2003, in forum: C Programming
    Replies:
    3
    Views:
    564
    Mark McIntyre
    Aug 16, 2003
  3. Replies:
    10
    Views:
    569
  4. Chris Thomasson

    Very Simple, Minimalist Technique For OOP in C...

    Chris Thomasson, Jun 21, 2007, in forum: C Programming
    Replies:
    10
    Views:
    700
    Johan Bengtsson
    Jun 24, 2007
  5. rtk
    Replies:
    16
    Views:
    1,059
    Cameron Laird
    Jul 6, 2007
Loading...

Share This Page