Skip to content

Instantly share code, notes, and snippets.

@GrahamDumpleton
Created October 2, 2012 01:16
Show Gist options
  • Save GrahamDumpleton/3815596 to your computer and use it in GitHub Desktop.
Save GrahamDumpleton/3815596 to your computer and use it in GitHub Desktop.
PyCon US 2013 Talk Proposal 2

Title

How well do you really understand the WSGI specification?

Category

Web Frameworks

Audience Level

Intermediate

Extreme

No

Duration

30 minute slot.

Brief Outline

The WSGI specification is coming up to 10 years old. Because of it, we now have many more and much higher quality production grade deployment mechanisms for Python web applications. Even so, both application developers and server implementors keep implementing it wrongly. This talk will recap the fundamentals of WSGI, but also shine a light on the often misunderstood dark corners as well.

Detailed Abstract

The WSGI specification was originally detailed in PEP 333 in 2003 and subsequently revised with support for Python 3 as PEP 3333 in 2010.

Although the preferred path for developing Python web applications is to use a high level framework which already performs all the hard work and hides many of the specific details, newbies often still choose the harder path of working directly at the WSGI layer.

Despite the WSGI specification being around for 10 years though there is still no one authoritative guide on all things WSGI. Besides the WSGI specification itself, information about implementing to the WSGI specification tends to be scattered across the Internet and not always easily findable.

The intent of this talk is to provide a tour of all the key points of the WSGI specification pertinent to developers needing to implement to it. This includes various aspects of the WSGI specification which aren't really well understood and are often a source of incorrect application, middleware and server implementations.

Outline of topics to be covered by this talk.

Application:

  • Prototypical WSGI application for Python 2.
  • Prototypical WSGI application for Python 3.
  • Functions vs objects vs classes for WSGI application.

Request:

  • Per request WSGI environ dictionary.
  • Bytes strings vs native strings vs Unicode strings.
  • ASCII vs Latin-1 vs UTF-8 encodings in key/values.
  • URL encodings, SCRIPT_NAME and PATH_INFO.
  • File system path encoding and SCRIPT_NAME.
  • Application specific encoding of HTTP_COOKIE.
  • CONTENT_LENGTH and reading request content from 'wsgi.input'.
  • Empty string as end sentinel for request content.
  • Exceptions when reading request content.
  • Input filters changing request content length.
  • Unknown request content length and chunked transfer encoding.

Response:

  • Starting the response using start_response().
  • Lists vs iterables vs generators for generating response content.
  • Implicit flush between each response content block.
  • Streaming responses with chunked transfer encoding.
  • Flushing of headers only on first non empty response content block.
  • Changing response status and headers upon catching an exception.
  • Response content when receiving a HEAD vs GET request.
  • Automatically calculated content length for response.
  • Optimised file response using 'wsgi.file_wrapper'.

Middleware:

  • Prototypical WSGI middleware.
  • Responsibility to call close() on application response.
  • Cleaning up resources on completion of sending the response content.
  • Passing only amount of response content defined by 'Content-Length' header.
  • Passing through empty blocks to support multiplexed systems.
  • Default value for 'exc_info' argument of start_response().

Additional Notes

...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment