Commit Graph

253 Commits

Author SHA1 Message Date
Anton Zhyrney
fcae4a9f0a added as_view 2017-01-07 06:30:23 +02:00
Eli Uriegas
baf8254907 Change Ellipsis to None for consistency 2017-01-05 15:29:57 -06:00
Raphael Deem
616e20d467 move backlog to run() 2017-01-04 09:31:06 -08:00
Raphael Deem
e7922c1b54 add configurable backlog #263 2017-01-03 18:36:31 -08:00
Eli Uriegas
16959caa34 Merge pull request #259 from yoloseem/route
Correct Router documentation
2017-01-03 18:47:54 -06:00
Eli Uriegas
0675f388b9 Merge pull request #255 from seemethere/add_more_verbose_debug_error_handling
Add more verbose debug error handling
2017-01-03 15:43:26 -06:00
Eli Uriegas
8a9b1fee14 Merge pull request #265 from youknowone/test-middleware-schedule
Prevent flooding of meaningless traceback in `sanic_endpoint_test`
2017-01-03 14:41:23 -06:00
Jeong YunWon
e6eb697bb2 Use constant PORT rather than literal in test code (#266) 2017-01-03 14:40:13 -06:00
Eli Uriegas
4ccc782e29 Merge pull request #209 from 38elements/protocol
Customizable protocol
2017-01-03 11:52:54 -06:00
Hyunjun Kim
cfdd9f66d1 Correct sanic.router.Router documentation 2017-01-02 14:32:22 +09:00
Hyunjun Kim
035cbf84ae Cache request.json even when it's null or empty
In case of request body is set to `{}`, `[]` or `null`, even it's
already processed, parsed_json won't be used due to its boolean
evaluation.
2017-01-02 14:20:20 +09:00
Jeong YunWon
87c24e5a7c Prevent flooding of meaningless traceback in sanic_endpoint_test
When Sanic has an exception in a request middleware, it fails to
save request object in `results`. In `sanic_endpoint_test`, because
it always requires `results` to have both `request` and `response` objects,
it prints traceback like attached example. It is not a user code and
it doesn't give any information to users, it is better to suppress
to print this kind of error.

To fix it, this patch insert collect hook as first request middleware
to guarantee to successfully run it always.

```
app = <sanic.sanic.Sanic object at 0x1102b5358>, method = 'get', uri = '/ping/', gather_request = True, loop = None
debug = True, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x11286c158>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x11286c378>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            loop=None, debug=False, *request_args,
                            **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            @app.middleware
            def _collect_request(request):
                results.append(request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=42101,
                after_start=_collect_response, loop=loop)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
>               request, response = results
E               ValueError: not enough values to unpack (expected 2, got 1)

../sanic/sanic/utils.py:46: ValueError
```
2017-01-02 13:18:22 +09:00
Eli Uriegas
552ff9d736 Merge pull request #235 from yoloseem/patch-1
Allow Sanic-inherited application
2016-12-31 13:21:44 -06:00
Eli Uriegas
738396c2e2 Merge pull request #236 from seanpar203/token_property
Add token property to request
2016-12-31 13:21:12 -06:00
Eli Uriegas
9f18b5a096 Merge pull request #248 from youknowone/debuggable-typecheck
Handle hooks parameters in more debuggable way
2016-12-31 13:17:06 -06:00
Eli Uriegas
7a8fd6b0df Add more verbose error handling
* Adds logging to error messages in debug mode as pointed out in PR #249,
while also improving the debug message.
2016-12-30 13:48:17 -06:00
Eli Uriegas
f1c2854358 Merge branch 'master' into 178 2016-12-30 12:15:08 -06:00
Eli Uriegas
87559a34f8 Include more explicit loop for headers conversion
Also merges master changes into this PR for this branch
2016-12-30 12:13:16 -06:00
Eli Uriegas
9586351f37 Merge pull request #243 from dutradda/add_remove_route_method
created methods to remove a route from api/router
2016-12-30 09:39:57 -06:00
Diogo
0f6ed642da created methods to remove a route from api/router 2016-12-30 07:36:57 -02:00
38elements
ee8f8c2930 Merge branch 'master' into protocol 2016-12-29 16:44:15 +09:00
38elements
83e9d08853 Add document for custom protocol 2016-12-29 13:11:27 +09:00
Jeong YunWon
15e7d8ab2e Handle hooks parameters in more debuggable way
1. not list() -> callable()
The args of hooking parameters of Sanic have to be callables.
For wrong parameters, errors will be generated from:
```
    listeners += args
```

By checking just list type, the raised error will be associated
with `[args]` instead of `args`, which is not given by users.
With this patch, the raised error will be associated with `args`.
Then users can notice their argument was neither callable nor list
in the easier way.

2. Function -> Functions in document
Regarding the parameter as a list is harmless to the user code.
But unawareness of its type can be list can limit the potent of
the user code.
2016-12-28 18:14:57 +09:00
Raphael Deem
a4f77984b7 stop multiple worker server without sleep loop; issue #73 2016-12-26 14:51:16 -08:00
38elements
ac44900fc4 Add test and example for custom protocol 2016-12-26 23:41:10 +09:00
Sean Parsons
986b0aa106 Added token property to request object. 2016-12-26 06:41:41 -05:00
Hyunjun Kim
01b42fb399 Allow Sanic-inherited application 2016-12-26 20:37:16 +09:00
Eli Uriegas
5402e6d3a6 Merge pull request #212 from r0fls/176
allow overriding logging basicConfig settings
2016-12-25 09:13:51 -08:00
Cadel Watson
52c59e7133 Fix all docstring errors.
When generating documentation with sphinx-apidoc, there are currently
many docstring errors, mostly minor. This commit fixes all errors.
2016-12-25 20:43:45 +11:00
Raphael Deem
be9eca2d63 use try/except 2016-12-24 23:05:03 -08:00
Sean Parsons
d5ad5e46da Update response docstrings to be explicit on whats returned. 2016-12-25 01:24:17 -05:00
Sean Parsons
a486fb99a9 Updated json function docstrings to be more consistent. 2016-12-25 01:06:40 -05:00
Sean Parsons
2b10860c32 Added docstrings to sanic.response.py for issue 41 2016-12-25 01:05:26 -05:00
Sean Parsons
a03f216f42 Added additional docstrings to blueprints.py 2016-12-25 00:47:51 -05:00
Raphael Deem
7d7cbaacf1 header format function 2016-12-24 20:56:13 -08:00
Raphael Deem
00b5a496dd type -> isinstance 2016-12-24 20:56:13 -08:00
Raphael Deem
7e6c92dc52 convert header values to strings 2016-12-24 20:56:13 -08:00
Eli Uriegas
cf7616ebe5 Increment version to 0.1.9 2016-12-24 18:51:16 -08:00
Eli Uriegas
67a50becb0 Merge pull request #215 from cr0hn/patch-1
Improvement: avoid to encoding in each HTTP Response
2016-12-24 18:41:01 -08:00
Eli Uriegas
d7e94473f3 Use a try/except, it's a bit faster
Also reorder some imports and add some comments
2016-12-24 18:37:55 -08:00
Eli Uriegas
275851a755 Merge pull request #188 from webtic/master
Find URL encoded filenames on the fs by decoding them first
2016-12-24 18:14:45 -08:00
Eli Uriegas
16182472fa Remove trailing whitespace 2016-12-24 18:11:46 -08:00
Eli Uriegas
29f3c22fed Rework conditionals to not be inline 2016-12-24 18:11:12 -08:00
Eli Uriegas
a116666d55 Merge pull request #223 from r0fls/115
Raise error if response is malformed.
2016-12-24 17:12:17 -08:00
Raphael Deem
c2622511ce Raise error if response is malformed. Issue #115 2016-12-24 17:09:41 -08:00
cr0hn
cc982c5a61 Update response.py
Type check by isinstance
2016-12-24 15:24:25 +01:00
38elements
2d05243c4a Refactor arguments of run function 2016-12-24 22:49:48 +09:00
38elements
39211f8fbd Refactor arguments of serve function 2016-12-24 11:40:07 +09:00
Raphael Deem
32ea45d403 allow overriding logging.basicConfig 2016-12-23 16:17:34 -08:00
cr0hn
5afae986a0 Apply response Middleware always
Response middleware are useful to apply some post-process information, just before send to the user. For example: Add some HTTP headers (security headers, for example), remove "Server" banner (for security reasons) or cookie management. 

The change is very very simple: although an "request" middleware has produced any response, we'll even apply the response middlewares.
2016-12-23 15:59:04 +01:00
cr0hn
f091d82bad Improvement
improvement: support fo binary data as a input. This do that the response process has more performance because not encoding needed.
2016-12-23 13:12:59 +01:00
38elements
c657c531b4 Customizable protocol 2016-12-23 00:13:38 +09:00
38elements
75fc9f91b9 Change HttpParserError process 2016-12-18 09:25:39 +09:00
Eli Uriegas
435d5585e9 Fix leftover blank line
flake8 build failed here: https://travis-ci.org/channelcat/sanic/builds/183991976
2016-12-14 11:29:09 -06:00
Eli Uriegas
ddfb7f2861 Merge branch 'master' into convert_dict_to_set 2016-12-14 11:26:31 -06:00
Paul Jongsma
2003eceba1 remove trailing space 2016-12-13 10:41:39 +01:00
Eli Uriegas
a3a14cdab2 Merge pull request #170 from jpiasetz/convert_lambda_to_partial
Convert server lambda to partial
2016-12-12 20:40:29 -06:00
Paul Jongsma
9ba2f99ea2 added a comment on why to decode the file_path 2016-12-13 01:10:24 +01:00
Paul Jongsma
0464d31a9c Find URL encoded filenames on the fs by decoding them first 2016-12-10 12:16:37 +01:00
Eli Uriegas
e3453553e1 Merge pull request #183 from 38elements/payload-too-large
Change Payload Too Large process
2016-12-08 10:27:55 -06:00
Raphael Deem
457507d8dc return 400 on invalid json post data 2016-12-07 20:40:31 -08:00
38elements
662e0c9965 Change Payload Too Large process
When Payload Too Large occurs, it uses error handler.
2016-12-04 10:50:32 +09:00
Jack Fischer
c34427690a Merge branch 'master' of git://github.com/channelcat/sanic 2016-12-03 15:08:07 -05:00
Eli Uriegas
d8a974bb4f Merge pull request #175 from Derrreks/master
Improving comments
2016-12-02 20:07:28 -06:00
Eli Uriegas
39f3a63ced Increment version to 0.1.8 2016-11-29 15:59:03 -06:00
Eli Uriegas
89e2084489 Merge pull request #172 from 38elements/timeout
Change request timeout process
2016-11-29 15:56:07 -06:00
Derek Schuster
70c56b7db3 fixing line length 2016-11-28 14:22:07 -05:00
Derek Schuster
209b763302 fix typo 2016-11-28 14:05:47 -05:00
Derek Schuster
190b7a6076 improving comments and examples 2016-11-28 14:00:39 -05:00
Eli Uriegas
cce47a633a Merge pull request #167 from AntonDnepr/class-based-views
Class based views
2016-11-27 21:33:46 -06:00
Jack Fischer
0c215685f2 refactoring cookies 2016-11-27 08:30:46 -05:00
Jack Fischer
d86ac5e3e0 fix for cookie header capitalization bug 2016-11-26 11:20:29 -05:00
38elements
ee89b6ad03 before process 2016-11-26 16:47:16 +09:00
38elements
a5e6d6d2e8 Use default error process 2016-11-26 16:02:44 +09:00
Anton Zhyrney
1eea1f5485 rename&remove redundant code 2016-11-26 08:45:08 +02:00
38elements
0bd61f6a57 Use write_response 2016-11-26 14:14:30 +09:00
38elements
c01cbb3a8c Change Request timeout process
This add a request timeout exception.
It cancels task, when request is timeout.
2016-11-26 13:55:45 +09:00
John Piasetzki
0ca5c4eeff Use explicit import for httptools
Explicit importing the parser and the exception to save a name lookup.
2016-11-25 15:14:44 -05:00
John Piasetzki
47927608b2 Convert connections dict to set
Connections don't need to be a dict since the value is never used
2016-11-25 15:14:19 -05:00
John Piasetzki
13808bf282 Convert server lambda to partial
Partials are faster then lambdas for repeated calls.
2016-11-25 15:13:58 -05:00
Anton Zhyrney
c3c7964e2e pep8 fixes 2016-11-25 09:29:25 +02:00
Anton Zhyrney
9f2d73e2f1 class based views implementation for sanic 2016-11-25 09:10:25 +02:00
Eli Uriegas
fc19f2ea34 Merge pull request #163 from channelcat/request-data-vars
Access Request like a dictionary

Closes #129 #132
2016-11-23 13:51:17 -06:00
Eli Uriegas
93f50b8ef7 Merge pull request #160 from jiajunhuang/log
fix the way using logging.exception
2016-11-21 10:37:10 -06:00
abhishek7
f7f578ed44 Fixed Exception error log on line 157 of server.py 2016-11-20 21:37:01 -05:00
Channel Cat
d02fffb6b8 Fixing import of CIMultiDict 2016-11-19 18:41:40 -08:00
Channel Cat
993627ec44 Merged with master 2016-11-19 18:21:44 -08:00
Channel Cat
3ce6434532 Fix flake8 2016-11-19 18:04:35 -08:00
Channel Cat
a97e554f8f Added shared request data 2016-11-19 17:48:28 -08:00
Raphael Deem
635921adc7 Update headers to use CIMultiDict instead of dict 2016-11-19 16:09:38 -08:00
jiajunhuang
9eb4cecbc1 fix the way using logging.exception 2016-11-19 15:19:38 +08:00
Raphael Deem
f16ea20de5 provide default app name 2016-11-18 17:16:48 -08:00
Eli Uriegas
edb12da154 Fix the flake8 error caused by new flake8 version 2016-11-16 12:55:13 -06:00
Eli Uriegas
b51af7f4bf Merge pull request #147 from webtic/master
Add the client address to the request header
2016-11-10 15:30:04 -06:00
Eli Uriegas
28ce2447ef Update variable name
Give `ra` a more explicit name
2016-11-10 15:28:16 -06:00
Paul Jongsma
8ebc92c236 pass flake8 tests 2016-11-10 13:09:37 +01:00
Paul Jongsma
b92e46df40 fix whitespace 2016-11-10 13:06:27 +01:00
Paul Jongsma
be5588d5d8 Add the client address to the request header 2016-11-10 12:53:00 +01:00
Pahaz Blinov
0d9fb2f927 docs(request): return value docstring 2016-11-09 18:04:15 +05:00
Pahaz Blinov
0e9819fba1 fix(request): parse_multipart_form should return RequestParameters
I have this code:

```
form = FileForm(request.files)
```

and it raise error because the `request.files` is `dict` but `RequestParameters` is expected =/
2016-11-09 00:36:37 +05:00