Feature: serve static http, from a dir

Now, it is possible to serve static http from the files
of one dir. Just configure like:

[static-http]
enable = True
dir_path = /home/panos/build/openerp/doc/build/html

and the contents of that directory will be served as a
default at our http port ;)

Conflicts:

	bin/service/http_server.py

bzr revid: p_christ@hol.gr-20100726093334-2xr5mg0c9xvm68ej
This commit is contained in:
P. Christeas
2010-07-26 12:33:34 +03:00
parent 7d1f26cdd2
commit ea4bb98140
2 changed files with 44 additions and 0 deletions
+1
View File
@@ -108,6 +108,7 @@ if not ( tools.config["stop_after_init"] or \
tools.config["translate_out"] ):
service.http_server.init_servers()
service.http_server.init_xmlrpc()
service.http_server.init_static_http()
import service.netrpc_server
service.netrpc_server.init_servers()
+43
View File
@@ -34,6 +34,8 @@ import netsvc
import errno
import threading
import tools
import posixpath
import urllib
import os
import select
import socket
@@ -273,6 +275,47 @@ def init_xmlrpc():
netsvc.Logger().notifyChannel('web-services', netsvc.LOG_INFO,
"Registered XML-RPC over HTTPS")
class StaticHTTPHandler(HTTPHandler):
def __init__(self,request, client_address, server):
HTTPHandler.__init__(self,request,client_address,server)
dir_path = tools.config.get_misc('static-http', 'dir_path', False)
assert dir_path
self.__basepath = dir_path
def translate_path(self, path):
"""Translate a /-separated PATH to the local filename syntax.
Components that mean special things to the local file system
(e.g. drive or directory names) are ignored. (XXX They should
probably be diagnosed.)
"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words)
path = self.__basepath
for word in words:
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
return path
def init_static_http():
if not tools.config.get_misc('static-http','enable', True):
return
dir_path = tools.config.get_misc('static-http', 'dir_path', False)
assert dir_path
base_path = tools.config.get_misc('static-http', 'base_path', '/')
reg_http_service(HTTPDir(base_path,StaticHTTPHandler))
netsvc.Logger().notifyChannel("web-services", netsvc.LOG_INFO,
"Registered HTTP dir %s for %s" % (dir_path, base_path))
class OerpAuthProxy(AuthProxy):
""" Require basic authentication..