Skip to content
Snippets Groups Projects
Commit ea4bb981 authored by Panos Christeas's avatar Panos Christeas
Browse files

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
parent 7d1f26cd
Branches
Tags
No related merge requests found
......@@ -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()
......
......@@ -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..
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment