dulwich.web module

HTTP server for dulwich that implements the git smart HTTP protocol.

class dulwich.web.GunzipFilter(application)

Bases: object

WSGI middleware that unzips gzip-encoded requests before passing on to the underlying application.

class dulwich.web.HTTPGitApplication(backend, dumb=False, handlers=None, fallback_app=None)

Bases: object

Class encapsulating the state of a git WSGI application.

Variables:backend – the Backend object backing this application
services = {('GET', <_sre.SRE_Pattern object>): <function get_text_file>, ('GET', <_sre.SRE_Pattern object>): <function get_pack_file>, ('GET', <_sre.SRE_Pattern object>): <function get_idx_file>, ('GET', <_sre.SRE_Pattern object>): <function get_text_file>, ('GET', <_sre.SRE_Pattern object>): <function get_info_refs>, ('GET', <_sre.SRE_Pattern object>): <function get_loose_object>, ('GET', <_sre.SRE_Pattern object>): <function get_text_file>, ('GET', <_sre.SRE_Pattern object>): <function get_info_packs>, ('POST', <_sre.SRE_Pattern object>): <function handle_service_request>, ('POST', <_sre.SRE_Pattern object>): <function handle_service_request>}
class dulwich.web.HTTPGitRequest(environ, start_response, dumb=False, handlers=None)

Bases: object

Class encapsulating the state of a single git HTTP request.

Variables:environ – the WSGI environment for the request.
add_header(name, value)

Add a header to the response.


Set the response to be cached forever by the client.


Begin a HTTP 500 response and return the text of a message.


Begin a HTTP 403 response and return the text of a message.


Set the response to never be cached by the client.


Begin a HTTP 404 response and return the text of a message.

respond(status='200 OK', content_type=None, headers=None)

Begin a response with the given status and other headers.

class dulwich.web.LimitedInputFilter(application)

Bases: object

WSGI middleware that limits the input length of a request to that specified in Content-Length.

class dulwich.web.ServerHandlerLogger(stdin, stdout, stderr, environ, multithread=True, multiprocess=False)

Bases: wsgiref.simple_server.ServerHandler

ServerHandler that uses dulwich’s logger for logging exceptions.

log_message(format, *args)
class dulwich.web.WSGIRequestHandlerLogger(request, client_address, server)

Bases: wsgiref.simple_server.WSGIRequestHandler

WSGIRequestHandler that uses dulwich’s logger for logging exceptions.


Handle a single HTTP request

log_message(format, *args)
class dulwich.web.WSGIServerLogger(server_address, RequestHandlerClass, bind_and_activate=True)

Bases: wsgiref.simple_server.WSGIServer

Constructor. May be extended, do not override.

handle_error(request, client_address)

Handle an error.

dulwich.web.get_idx_file(req, backend, mat)
dulwich.web.get_info_packs(req, backend, mat)
dulwich.web.get_info_refs(req, backend, mat)
dulwich.web.get_loose_object(req, backend, mat)
dulwich.web.get_pack_file(req, backend, mat)
dulwich.web.get_repo(backend, mat)

Get a Repo instance for the given backend and URL regex match.

dulwich.web.get_text_file(req, backend, mat)
dulwich.web.handle_service_request(req, backend, mat)
dulwich.web.main(argv=['/usr/bin/sphinx-build', '-b', 'html', '-d', 'build/doctrees', '.', 'build/html'])

Entry point for starting an HTTP git server.

dulwich.web.make_wsgi_chain(*args, **kwargs)

Factory function to create an instance of HTTPGitApplication, correctly wrapped with needed middleware.

dulwich.web.send_file(req, f, content_type)

Send a file-like object to the request output.

  • req – The HTTPGitRequest object to send output to.
  • f – An open file-like object to send; will be closed.
  • content_type – The MIME type for the file.

Iterator over the contents of the file, as chunks.


Extract the URL prefix from a regex match.

Parameters:mat – A regex match object.
Returns:The URL prefix, defined as the text before the match in the original string. Normalized to start with one leading slash and end with zero.