[OT] minimalist web server

  • Thread starter Daniel Fetchinson
  • Start date
D

Daniel Fetchinson

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
 
P

Paul Rubin

Daniel Fetchinson said:
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
 
D

Daniel Fetchinson

I'm looking for the most minimalist web server ever that does nothing
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.
 
D

David Tweet

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)
 
D

Dave Benjamin

Daniel said:
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
 
M

Mel

Daniel said:
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.
 
P

Paul Rubin

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.
 
I

I V

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?
 
M

Michael Ströder

Paul said:
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.
 
G

ghirai

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.
 
D

Daniel Fetchinson

The reason I need this is that my current best strategy to avoid ads in
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.
 
M

MonkeeSage

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top