OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 class RequestHeaders(object): | 6 class RequestHeaders(object): |
7 '''A custom dictionary impementation for headers which ignores the case | 7 '''A custom dictionary impementation for headers which ignores the case |
8 of requests, since different HTTP libraries seem to mangle them. | 8 of requests, since different HTTP libraries seem to mangle them. |
9 ''' | 9 ''' |
10 def __init__(self, dict_): | 10 def __init__(self, dict_): |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return Response(content=content, headers=headers, status=200) | 89 return Response(content=content, headers=headers, status=200) |
90 | 90 |
91 @staticmethod | 91 @staticmethod |
92 def Redirect(url, permanent=False): | 92 def Redirect(url, permanent=False): |
93 '''Returns a redirect (301 or 302) response. | 93 '''Returns a redirect (301 or 302) response. |
94 ''' | 94 ''' |
95 status = 301 if permanent else 302 | 95 status = 301 if permanent else 302 |
96 return Response(headers={'Location': url}, status=status) | 96 return Response(headers={'Location': url}, status=status) |
97 | 97 |
98 @staticmethod | 98 @staticmethod |
| 99 def BadRequest(content, headers=None): |
| 100 '''Returns a bad request (400) response. |
| 101 ''' |
| 102 return Response(content=content, headers=headers, status=400) |
| 103 |
| 104 @staticmethod |
99 def NotFound(content, headers=None): | 105 def NotFound(content, headers=None): |
100 '''Returns a not found (404) response. | 106 '''Returns a not found (404) response. |
101 ''' | 107 ''' |
102 return Response(content=content, headers=headers, status=404) | 108 return Response(content=content, headers=headers, status=404) |
103 | 109 |
104 @staticmethod | 110 @staticmethod |
105 def NotModified(content, headers=None): | 111 def NotModified(content, headers=None): |
106 return Response(content=content, headers=headers, status=304) | 112 return Response(content=content, headers=headers, status=304) |
107 | 113 |
108 @staticmethod | 114 @staticmethod |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 return repr(self) | 166 return repr(self) |
161 | 167 |
162 class Servlet(object): | 168 class Servlet(object): |
163 def __init__(self, request): | 169 def __init__(self, request): |
164 self._request = request | 170 self._request = request |
165 | 171 |
166 def Get(self): | 172 def Get(self): |
167 '''Returns a Response. | 173 '''Returns a Response. |
168 ''' | 174 ''' |
169 raise NotImplemented() | 175 raise NotImplemented() |
OLD | NEW |