# evennia.server.webserver

This implements resources for Twisted webservers using the WSGI interface of Django. This alleviates the need of running e.g. an Apache server to serve Evennia’s web presence (although you could do that too if desired).

The actual servers are started inside server.py as part of the Evennia application.

(Lots of thanks to http://github.com/clemesha/twisted-wsgi-django for a great example/aid on how to do this.)

class `evennia.server.webserver.``LockableThreadPool`(*args, **kwargs)

  Bases: `twisted.python.threadpool.ThreadPool`

  Threadpool that can be locked from accepting new requests.

  `__init__`(*args, **kwargs)

    Create a new threadpool.

    @param minthreads: minimum number of threads in the pool @type minthreads: L{int}

    @param maxthreads: maximum number of threads in the pool @type maxthreads: L{int}

    @param name: The name to give this threadpool; visible in log messages. @type name: native L{str}

  `lock`()
  `callInThread`(func, *args, **kwargs)

    called in the main reactor thread. Makes sure the pool is not locked before continuing.

class `evennia.server.webserver.``HTTPChannelWithXForwardedFor`

  Bases: `twisted.web.http.HTTPChannel`

  HTTP xforward class

  `allHeadersReceived`()

    Check to see if this is a reverse proxied connection.

class `evennia.server.webserver.``EvenniaReverseProxyResource`(host, port, path, reactor=<twisted.internet.epollreactor.EPollReactor object>)

  Bases: `twisted.web.proxy.ReverseProxyResource`

  `getChild`(path, request)

    Create and return a proxy resource with the same proxy configuration as this one, except that its path also contains the segment given by path at the end.

    Parameters

      - path (str) – Url path.

      - request (Request object) – Incoming request.

    Returns

      resource (EvenniaReverseProxyResource) – A proxy resource.

  `render`(request)

    Render a request by forwarding it to the proxied server.

    Parameters

      request (Request) – Incoming request.

    Returns

      not_done (char) – Indicator to note request not yet finished.

class `evennia.server.webserver.``DjangoWebRoot`(pool)

  Bases: `twisted.web.resource.Resource`

  This creates a web root (/) that Django understands by tweaking the way child instances are recognized.

  `__init__`(pool)

    Setup the django+twisted resource.

    Parameters

      pool (ThreadPool) – The twisted threadpool.

  `empty_threadpool`()

    Converts our _pending_requests list of deferreds into a DeferredList

    Returns

      deflist (DeferredList) – Contains all deferreds of pending requests.

  `getChild`(path, request)

    To make things work we nudge the url tree to make this the root.

    Parameters

      - path (str) – Url path.

      - request (Request object) – Incoming request.

    Notes

    We make sure to save the request queue so that we can safely kill the threadpool on a server reload.

class `evennia.server.webserver.``Website`(resource, requestFactory=None, *args, **kwargs)

  Bases: `twisted.web.server.Site`

  This class will only log http requests if settings.DEBUG is True.

  `noisy` = False
  `logPrefix`()

    How to be named in logs

  `log`(request)

    Conditional logging

class `evennia.server.webserver.``WSGIWebServer`(pool, *args, **kwargs)

  Bases: `twisted.application.internet.TCPServer`

  This is a WSGI webserver. It makes sure to start the threadpool after the service itself started, so as to register correctly with the twisted daemon.

  call with WSGIWebServer(threadpool, port, wsgi_resource)

  `__init__`(pool, *args, **kwargs)

    This just stores the threadpool.

    Parameters

      - pool (ThreadPool) – The twisted threadpool.

      - args (any) – Passed on to the TCPServer.

      - kwargs (any) – Passed on to the TCPServer.

  `startService`()

    Start the pool after the service starts.

  `stopService`()

    Safely stop the pool after the service stops.

class `evennia.server.webserver.``PrivateStaticRoot`(path, defaultType='text/html', ignoredExts=(), registry=None, allowExt=0)

  Bases: `twisted.web.static.File`

  This overrides the default static file resource so as to not make the directory listings public (that is, if you go to /media or /static you won’t see an index of all static/media files on the server).

  `directoryListing`()

    Return a resource that generates an HTML listing of the directory this path represents.

    @return: A resource that renders the directory to HTML. @rtype: L{DirectoryLister}