add match_info to request
This commit is contained in:
		| @@ -178,6 +178,11 @@ class Request(dict): | |||||||
|     def content_type(self): |     def content_type(self): | ||||||
|         return self.headers.get('Content-Type', DEFAULT_HTTP_CONTENT_TYPE) |         return self.headers.get('Content-Type', DEFAULT_HTTP_CONTENT_TYPE) | ||||||
|  |  | ||||||
|  |     @property | ||||||
|  |     def match_info(self): | ||||||
|  |         """return matched info after resolving route""" | ||||||
|  |         return self.app.router.get(self)[2] | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def path(self): |     def path(self): | ||||||
|         return self._parsed_url.path.decode('utf-8') |         return self._parsed_url.path.decode('utf-8') | ||||||
|   | |||||||
| @@ -211,6 +211,19 @@ def test_content_type(): | |||||||
|     assert response.text == 'application/json' |     assert response.text == 'application/json' | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def test_match_info(): | ||||||
|  |     app = Sanic('test_match_info') | ||||||
|  |  | ||||||
|  |     @app.route('/api/v1/user/<user_id>/') | ||||||
|  |     async def handler(request, user_id): | ||||||
|  |         return json(request.match_info) | ||||||
|  |  | ||||||
|  |     request, response = app.test_client.get('/api/v1/user/sanic_user/') | ||||||
|  |  | ||||||
|  |     assert request.match_info == {"user_id": "sanic_user"} | ||||||
|  |     assert json_loads(response.text) == {"user_id": "sanic_user"} | ||||||
|  |  | ||||||
|  |  | ||||||
| # ------------------------------------------------------------ # | # ------------------------------------------------------------ # | ||||||
| #  POST | #  POST | ||||||
| # ------------------------------------------------------------ # | # ------------------------------------------------------------ # | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Yun Xu
					Yun Xu