| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 status = 301 if permanent else 302 | 96 status = 301 if permanent else 302 |
| 97 return Response(headers={'Location': url}, status=status) | 97 return Response(headers={'Location': url}, status=status) |
| 98 | 98 |
| 99 @staticmethod | 99 @staticmethod |
| 100 def BadRequest(content, headers=None): | 100 def BadRequest(content, headers=None): |
| 101 '''Returns a bad request (400) response. | 101 '''Returns a bad request (400) response. |
| 102 ''' | 102 ''' |
| 103 return Response(content=content, headers=headers, status=400) | 103 return Response(content=content, headers=headers, status=400) |
| 104 | 104 |
| 105 @staticmethod | 105 @staticmethod |
| 106 def Unauthorized(content, method, realm, headers={}): |
| 107 '''Returns an unauthorized (401) response. |
| 108 ''' |
| 109 new_headers = headers.copy() |
| 110 new_headers.update({ |
| 111 'WWW-Authentication': '%s realm="%s"' % (method, realm)}) |
| 112 return Response(content=content, headers=headers, status=401) |
| 113 |
| 114 @staticmethod |
| 115 def Forbidden(content, headers=None): |
| 116 '''Returns an forbidden (403) response. |
| 117 ''' |
| 118 return Response(content=content, headers=headers, status=403) |
| 119 |
| 120 @staticmethod |
| 106 def NotFound(content, headers=None): | 121 def NotFound(content, headers=None): |
| 107 '''Returns a not found (404) response. | 122 '''Returns a not found (404) response. |
| 108 ''' | 123 ''' |
| 109 return Response(content=content, headers=headers, status=404) | 124 return Response(content=content, headers=headers, status=404) |
| 110 | 125 |
| 111 @staticmethod | 126 @staticmethod |
| 112 def NotModified(content, headers=None): | 127 def NotModified(content, headers=None): |
| 113 return Response(content=content, headers=headers, status=304) | 128 return Response(content=content, headers=headers, status=304) |
| 114 | 129 |
| 115 @staticmethod | 130 @staticmethod |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return repr(self) | 182 return repr(self) |
| 168 | 183 |
| 169 class Servlet(object): | 184 class Servlet(object): |
| 170 def __init__(self, request): | 185 def __init__(self, request): |
| 171 self._request = request | 186 self._request = request |
| 172 | 187 |
| 173 def Get(self): | 188 def Get(self): |
| 174 '''Returns a Response. | 189 '''Returns a Response. |
| 175 ''' | 190 ''' |
| 176 raise NotImplemented() | 191 raise NotImplemented() |
| OLD | NEW |