Commit Graph

118 Commits (807a4876393961f3eb9c6a873e243ec5b2f87b6c)

Author SHA1 Message Date
Dustin 807a487639 app: Map HEAD requests to GET
After much discussion, the WSGI community has mostly agreed that
applications should not treat GET and HEAD requests differently. The
HTTP specification practically demands that they are handled the same
way by applications, with the exception that responses to HEAD requests
do not send a body. When they are handled differently, there is an
unfortunate tendency to over-optimize the HEAD request, causing
discrepancies between the headers it returns and those returned by GET.
Further, WSGI middleware may need access to the response body in order
to properly manipulate the response (e.g. to rewrite links, etc.), which
could effect the response to HEAD requests as well.

This commit changes the behavior of `BaseApplication` to change the
method of all `HEAD` requests to `GET` prior to dispatching them.
`Request` objects now have a `real_method` attribute, which indicates
the original method of the request.

http://blog.dscpl.com.au/2009/10/wsgi-issues-with-http-head-requests.html
2016-07-14 12:37:48 -05:00
Dustin ff27f3a917 app: Don't check Python version for every request
Checking for the `basestring` name takes a nonzero amount of time, the
result of the check never changes. As such, is not appropriate to do
this for every request.
2016-07-14 12:37:47 -05:00
Dustin 71d00e4207 app: Make HTTP POST method emulation optional
For some applications, the HTTP method emulation for POST requests is
undesirable, particularly when the request contains a large payload
(e.g. file uploads, etc.). For these applications, this feature can be
disabled by setting the `post_method_emulation` attribute of their
application objects to `False`.
2016-07-14 12:37:47 -05:00
Dustin 83971013d0 app: Update module docstring 2016-07-14 12:37:47 -05:00
Dustin 44a28fda68 app: Add BaseApplication class
The `Application` class is now a sub-class of `BaseApplication`.
Applications that require more control of the framework's behavior can
extend `BaseApplication` instead of `Application`. The `BaseApplication`
class also provides some new features:

* `BaseApplication.setup_routes` is always called when an instance is
  created, and can be used to configure the request dispatcher
* `BaseApplication.update_config` updates the application configuration
  from a configuration file

The major difference between `BaseApplication` and `Application` is that
the latter requires a request dispatcher, while the former does not.
This pattern allows simple applications to construct a `Router` or root
object and then initialize the `Application` without needing to define a
sub-class.
2016-07-14 12:37:47 -05:00
Dustin 4090df1286 Begin 1.0 development 2016-07-14 12:37:47 -05:00
Dustin 95caf1020b Add .gitignore 2016-07-14 12:37:47 -05:00
Dustin a593bb762f Rename README for GitLab compatibility? 2016-07-06 20:58:27 -05:00
Dustin 40ede10425 doc: Update changelog for 0.3 release 2015-04-25 13:54:46 -05:00
Dustin 634c914f6d dispatch: routing: Remove Generator class 2015-04-25 13:54:42 -05:00
Dustin 3beca18523 controllers: Add HTTPVerbController
The `HTTPVerbController` base class can be used by controllers to delegate
request handling to different instance methods based on the HTTP request
method.
2015-04-25 13:48:49 -05:00
Dustin da406fcce8 app: Refactor Application class
This commit breaks up the `Application.__call__` method into smaller methods
that can be overridden by subclasses. These methods allow customization of
various steps of the request/response handling process:

* `make_request`: Create the `Request` object from the WSGI environment
  dictionary. The default implementation creates a `milla.Request` object,
  copies the application configuration to its `config` attribute, and handles
  "emulated" HTTP methods from POST data.
* `resolve_path`: Locates a controller callable from the given path info. The
  default implementation calls the `resolve` method on the application's
  `dispatcher` attribute. If `UnresolvePath` is raised, it returns a callable
  that raises `HTTPNotFound`.
* `handle_error`: Called inside the exception handler when a controller
  callable raises an exception. The method should return a callable WSGI
  application (such as a `Response` or `WSGIHTTPException` object). To access
  the exception that was raised, use the `sys.exc_info` function. The default
  implementation returns the exception if it is an instance of
  `WSGIHTTPException`, or re-raises the exception otherwise. This allows
  middleware applications to handle the exception, if desired.
2015-04-25 12:42:42 -05:00
Dustin 922a82e4e8 FaviconController: Work without pkg_resources (fixes #4)
If the `pkg_resources` module is not available, the `FaviconController` will
fall back to finding the default image in the same directory on the filesystem
as the `milla` package.
2015-04-15 20:08:50 -05:00
Dustin 94b98a0620 auth: Allow Python classes as request validators (see #4)
In addition to setuptools entry point names, the authentication subsystem now
accepts Python classes directly as the value of the `milla.request_validator`
configuration setting. This removes the dependency on setuptools for
authentication, and allows more flexibility in application configuration.
2015-04-15 19:47:24 -05:00
Dustin 86b19bb9e7 Whitespace cleanup 2015-04-15 19:45:17 -05:00
Dustin 6519cfbb9e Remove deprecated CLI tool 2015-04-15 20:11:25 -05:00
Dustin fc04300140 Bump to version 0.3 2015-04-15 20:10:47 -05:00
Dustin C. Hatch f2602388e3 Bump to version 0.2.2 2015-02-21 10:31:27 -06:00
Dustin C. Hatch 4ffb3f3707 Added tag 0.2.1 for changeset 3b8acd86b010 2015-02-21 10:29:48 -06:00
Dustin C. Hatch f972382d12 doc: Update changelog 2015-02-21 00:09:10 -06:00
Dustin C. Hatch 1018519d73 doc: Update copyright date 2015-02-19 21:28:28 -06:00
Dustin C. Hatch 0754f4b823 meta: ignore coverage cache 2015-02-19 20:39:57 -06:00
Dustin C. Hatch 230da47d5b app: Use _find_attr to locate controller's allowed_methods
Using the `milla.app.Application._find_attr` method to find the
`allowed_methods` of returned controller callables allows the attribute to be
defined e.g. on the class for instance methods, etc.
2015-02-19 20:37:39 -06:00
Dustin C. Hatch 922778ee4c test: Fix tests broken by move 2015-02-19 20:29:01 -06:00
Dustin C. Hatch 7cfb10066e Move tests outside distribution 2015-02-19 20:13:27 -06:00
Dustin C. Hatch e6774204a6 app: Return an empty string for HEAD requests
Some WSGI servers, e.g. Werkzeug, unconditionally attempt to iterate over the
application response, even for HEAD requests. If `None` is returned, then the
server will crash in this case, because it is not iterable. This commit alters
the behavior of `milla.Application` to return an empty string, which is
iterable and has the same effect of not sending a body.
2015-02-19 20:01:05 -06:00
Dustin C. Hatch c69dbed7ee routing: Correctly redirect when path info is empty (fixes #7)
When the application path info is empty (e.g. the WSGI script is mounted
somewhere other than the root), appending a trailing slash and redirecting
causes the new location to be calculated incorrectly. This is because the part
of the request URL before the application path is not taken into account, so
the new path always ends up being a literal `/`. This commit changes the
behavior of the `redir` function that is returned by
`milla.dispatch.routing.Router.resolve` to calculate the new path info
correctly in the redirect response.
2015-02-19 19:58:03 -06:00
Dustin C. Hatch cf94a4d600 app: Fixed an issue with unicode responses in Python 2.7
If a controller callable returns a string, it needs to be wrapped in a
Response object. To determine if this is the case, the Application tests to
see if the returned object is an instance of `basestring`. Since `basestring`
doesn't exist in Python 3, only `str` is a valid return type.

Unfortunately, my way of testing whether the `basestring` type existed was
flawed. Instead of raising `NameError` when it doesn't exist,
`UnboundLocalError` (a subclass `NameError`) is *always* raised. Since the
exception handler sets `basestring` equal to `str` assuming this is Python 3,
most of the time this isn't a problem. If, however, the controller returns a
`unicode` object in Python 2, the `isinstance` call returns `False`, so the
response is not wrapped in a Response object.

Rather than try to reassign the `basestring` name, now we just use `_string`,
which will either be `basestring` (in Python 2) or `str` (in Python 3).

Apparently, the unit tests didn't cover this case...
2014-02-07 23:22:50 -06:00
Dustin C. Hatch a2d8f6f098 Version bump 2013-01-22 13:02:17 -06:00
Dustin C. Hatch 8e699969e2 Added tag 0.2 for changeset 2d04d03ce334 2013-01-22 13:01:28 -06:00
Dustin C. Hatch 872461d515 Remove dev version tag for 0.2 release 2013-01-22 13:01:16 -06:00
Dustin C. Hatch d068d22e38 Added README 2013-01-22 12:00:56 -06:00
Dustin C. Hatch 345333614c New documentation 2013-01-22 10:47:39 -06:00
Dustin C. Hatch 14c8c28b9a Update docstring for util.read_config 2013-01-21 22:10:24 -06:00
Dustin C. Hatch 243df2be47 Mark the milla.cli module as deprecated 2013-01-20 15:14:25 -06:00
Dustin C. Hatch 708e59125e Bump documentation version 2013-01-20 15:00:45 -06:00
Dustin C. Hatch fc42519f0d Bump setup.py version 2013-01-20 14:45:55 -06:00
Dustin C. Hatch 9da12232d4 Add a `defaults` keyword to `milla.util.read_config` 2013-01-20 14:49:24 -06:00
Dustin C. Hatch 65ebf76b45 Move read_config to milla.util 2013-01-20 14:48:23 -06:00
Dustin C. Hatch 3408919faa Merged branch py3k (closes #2) 2013-01-20 14:53:38 -06:00
Dustin C. Hatch 0064f70160 Update read_config for new API in Python 3.2
--HG--
branch : py3k
2013-01-05 10:38:05 -06:00
Dustin C. Hatch fed7d0fb3d Merge default into py3k
--HG--
branch : py3k
2012-12-19 15:38:36 -06:00
Dustin C. Hatch 4085039997 Added simple inifile-to-dictionary parser 2012-12-19 15:26:19 -06:00
Dustin C. Hatch d635e83431 Automatically create a Traverser instance if Application is given a root object 2012-11-30 22:47:06 -06:00
Dustin C. Hatch f5f7e76dae Added tests for Router's trailing slash handling options 2012-11-30 22:46:28 -06:00
Dustin C. Hatch f14b744ef7 Added tests for Request.static_resource 2012-11-30 22:24:35 -06:00
Dustin C. Hatch 32e96f5807 Fixed more Python 3 import errors
--HG--
branch : py3k
2012-11-30 22:16:08 -06:00
Dustin C. Hatch f8e89d46c6 Merge default into py3k
--HG--
branch : py3k
2012-11-30 22:11:23 -06:00
Dustin C. Hatch c4e9397e8c Replace Request.relative_url with Request.create_url and friends 2012-11-30 22:02:28 -06:00
Dustin C. Hatch 11271ebc31 app: Cleaned up imports and fixed Request.blank docstring 2012-11-30 22:01:25 -06:00