124 |
124 |
class HttpBadRequest(HttpException):
|
125 |
125 |
"""400 Bad Request
|
126 |
126 |
|
127 |
|
RFC2616, 10.4.1: The request could not be understood by the server due to
|
128 |
|
malformed syntax. The client SHOULD NOT repeat the request without
|
129 |
|
modifications.
|
|
127 |
RFC2616, 10.4.1: The request could not be understood by the server
|
|
128 |
due to malformed syntax. The client SHOULD NOT repeat the request
|
|
129 |
without modifications.
|
130 |
130 |
|
131 |
131 |
"""
|
132 |
132 |
code = 400
|
... | ... | |
135 |
135 |
class HttpUnauthorized(HttpException):
|
136 |
136 |
"""401 Unauthorized
|
137 |
137 |
|
138 |
|
RFC2616, section 10.4.2: The request requires user authentication. The
|
139 |
|
response MUST include a WWW-Authenticate header field (section 14.47)
|
140 |
|
containing a challenge applicable to the requested resource.
|
|
138 |
RFC2616, section 10.4.2: The request requires user
|
|
139 |
authentication. The response MUST include a WWW-Authenticate header
|
|
140 |
field (section 14.47) containing a challenge applicable to the
|
|
141 |
requested resource.
|
141 |
142 |
|
142 |
143 |
"""
|
143 |
144 |
code = 401
|
... | ... | |
146 |
147 |
class HttpForbidden(HttpException):
|
147 |
148 |
"""403 Forbidden
|
148 |
149 |
|
149 |
|
RFC2616, 10.4.4: The server understood the request, but is refusing to
|
150 |
|
fulfill it. Authorization will not help and the request SHOULD NOT be
|
151 |
|
repeated.
|
|
150 |
RFC2616, 10.4.4: The server understood the request, but is refusing
|
|
151 |
to fulfill it. Authorization will not help and the request SHOULD
|
|
152 |
NOT be repeated.
|
152 |
153 |
|
153 |
154 |
"""
|
154 |
155 |
code = 403
|
... | ... | |
157 |
158 |
class HttpNotFound(HttpException):
|
158 |
159 |
"""404 Not Found
|
159 |
160 |
|
160 |
|
RFC2616, 10.4.5: The server has not found anything matching the Request-URI.
|
161 |
|
No indication is given of whether the condition is temporary or permanent.
|
|
161 |
RFC2616, 10.4.5: The server has not found anything matching the
|
|
162 |
Request-URI. No indication is given of whether the condition is
|
|
163 |
temporary or permanent.
|
162 |
164 |
|
163 |
165 |
"""
|
164 |
166 |
code = 404
|
... | ... | |
167 |
169 |
class HttpMethodNotAllowed(HttpException):
|
168 |
170 |
"""405 Method Not Allowed
|
169 |
171 |
|
170 |
|
RFC2616, 10.4.6: The method specified in the Request-Line is not allowed for
|
171 |
|
the resource identified by the Request-URI. The response MUST include an
|
172 |
|
Allow header containing a list of valid methods for the requested resource.
|
|
172 |
RFC2616, 10.4.6: The method specified in the Request-Line is not
|
|
173 |
allowed for the resource identified by the Request-URI. The response
|
|
174 |
MUST include an Allow header containing a list of valid methods for
|
|
175 |
the requested resource.
|
173 |
176 |
|
174 |
177 |
"""
|
175 |
178 |
code = 405
|
... | ... | |
178 |
181 |
class HttpRequestTimeout(HttpException):
|
179 |
182 |
"""408 Request Timeout
|
180 |
183 |
|
181 |
|
RFC2616, 10.4.9: The client did not produce a request within the time that
|
182 |
|
the server was prepared to wait. The client MAY repeat the request without
|
183 |
|
modifications at any later time.
|
|
184 |
RFC2616, 10.4.9: The client did not produce a request within the
|
|
185 |
time that the server was prepared to wait. The client MAY repeat the
|
|
186 |
request without modifications at any later time.
|
184 |
187 |
|
185 |
188 |
"""
|
186 |
189 |
code = 408
|
... | ... | |
189 |
192 |
class HttpConflict(HttpException):
|
190 |
193 |
"""409 Conflict
|
191 |
194 |
|
192 |
|
RFC2616, 10.4.10: The request could not be completed due to a conflict with
|
193 |
|
the current state of the resource. This code is only allowed in situations
|
194 |
|
where it is expected that the user might be able to resolve the conflict and
|
195 |
|
resubmit the request.
|
|
195 |
RFC2616, 10.4.10: The request could not be completed due to a
|
|
196 |
conflict with the current state of the resource. This code is only
|
|
197 |
allowed in situations where it is expected that the user might be
|
|
198 |
able to resolve the conflict and resubmit the request.
|
196 |
199 |
|
197 |
200 |
"""
|
198 |
201 |
code = 409
|
... | ... | |
201 |
204 |
class HttpGone(HttpException):
|
202 |
205 |
"""410 Gone
|
203 |
206 |
|
204 |
|
RFC2616, 10.4.11: The requested resource is no longer available at the server
|
205 |
|
and no forwarding address is known. This condition is expected to be
|
206 |
|
considered permanent.
|
|
207 |
RFC2616, 10.4.11: The requested resource is no longer available at
|
|
208 |
the server and no forwarding address is known. This condition is
|
|
209 |
expected to be considered permanent.
|
207 |
210 |
|
208 |
211 |
"""
|
209 |
212 |
code = 410
|
... | ... | |
212 |
215 |
class HttpLengthRequired(HttpException):
|
213 |
216 |
"""411 Length Required
|
214 |
217 |
|
215 |
|
RFC2616, 10.4.12: The server refuses to accept the request without a defined
|
216 |
|
Content-Length. The client MAY repeat the request if it adds a valid
|
217 |
|
Content-Length header field containing the length of the message-body in the
|
218 |
|
request message.
|
|
218 |
RFC2616, 10.4.12: The server refuses to accept the request without a
|
|
219 |
defined Content-Length. The client MAY repeat the request if it adds
|
|
220 |
a valid Content-Length header field containing the length of the
|
|
221 |
message-body in the request message.
|
219 |
222 |
|
220 |
223 |
"""
|
221 |
224 |
code = 411
|
... | ... | |
224 |
227 |
class HttpPreconditionFailed(HttpException):
|
225 |
228 |
"""412 Precondition Failed
|
226 |
229 |
|
227 |
|
RFC2616, 10.4.13: The precondition given in one or more of the request-header
|
228 |
|
fields evaluated to false when it was tested on the server.
|
|
230 |
RFC2616, 10.4.13: The precondition given in one or more of the
|
|
231 |
request-header fields evaluated to false when it was tested on the
|
|
232 |
server.
|
229 |
233 |
|
230 |
234 |
"""
|
231 |
235 |
code = 412
|
... | ... | |
234 |
238 |
class HttpInternalServerError(HttpException):
|
235 |
239 |
"""500 Internal Server Error
|
236 |
240 |
|
237 |
|
RFC2616, 10.5.1: The server encountered an unexpected condition which
|
238 |
|
prevented it from fulfilling the request.
|
|
241 |
RFC2616, 10.5.1: The server encountered an unexpected condition
|
|
242 |
which prevented it from fulfilling the request.
|
239 |
243 |
|
240 |
244 |
"""
|
241 |
245 |
code = 500
|
... | ... | |
244 |
248 |
class HttpNotImplemented(HttpException):
|
245 |
249 |
"""501 Not Implemented
|
246 |
250 |
|
247 |
|
RFC2616, 10.5.2: The server does not support the functionality required to
|
248 |
|
fulfill the request.
|
|
251 |
RFC2616, 10.5.2: The server does not support the functionality
|
|
252 |
required to fulfill the request.
|
249 |
253 |
|
250 |
254 |
"""
|
251 |
255 |
code = 501
|
... | ... | |
254 |
258 |
class HttpServiceUnavailable(HttpException):
|
255 |
259 |
"""503 Service Unavailable
|
256 |
260 |
|
257 |
|
RFC2616, 10.5.4: The server is currently unable to handle the request due to
|
258 |
|
a temporary overloading or maintenance of the server.
|
|
261 |
RFC2616, 10.5.4: The server is currently unable to handle the
|
|
262 |
request due to a temporary overloading or maintenance of the server.
|
259 |
263 |
|
260 |
264 |
"""
|
261 |
265 |
code = 503
|
... | ... | |
264 |
268 |
class HttpVersionNotSupported(HttpException):
|
265 |
269 |
"""505 HTTP Version Not Supported
|
266 |
270 |
|
267 |
|
RFC2616, 10.5.6: The server does not support, or refuses to support, the HTTP
|
268 |
|
protocol version that was used in the request message.
|
|
271 |
RFC2616, 10.5.6: The server does not support, or refuses to support,
|
|
272 |
the HTTP protocol version that was used in the request message.
|
269 |
273 |
|
270 |
274 |
"""
|
271 |
275 |
code = 505
|
... | ... | |
467 |
471 |
@type sock: socket
|
468 |
472 |
@param sock: Socket to be shut down
|
469 |
473 |
@type close_timeout: float
|
470 |
|
@param close_timeout: How long to wait for the peer to close the connection
|
|
474 |
@param close_timeout: How long to wait for the peer to close
|
|
475 |
the connection
|
471 |
476 |
@type write_timeout: float
|
472 |
477 |
@param write_timeout: Write timeout for shutdown
|
473 |
478 |
@type msgreader: http.HttpMessageReader
|
474 |
|
@param msgreader: Request message reader, used to determine whether peer
|
475 |
|
should close connection
|
|
479 |
@param msgreader: Request message reader, used to determine whether
|
|
480 |
peer should close connection
|
476 |
481 |
@type force: bool
|
477 |
|
@param force: Whether to forcibly close the connection without waiting
|
478 |
|
for peer
|
|
482 |
@param force: Whether to forcibly close the connection without
|
|
483 |
waiting for peer
|
479 |
484 |
|
480 |
485 |
"""
|
481 |
486 |
#print msgreader.peer_will_close, force
|
... | ... | |
529 |
534 |
@type ssl_key_path: string
|
530 |
535 |
@param ssl_key_path: Path to file containing SSL key in PEM format
|
531 |
536 |
@type ssl_cert_path: string
|
532 |
|
@param ssl_cert_path: Path to file containing SSL certificate in PEM format
|
|
537 |
@param ssl_cert_path: Path to file containing SSL certificate
|
|
538 |
in PEM format
|
533 |
539 |
|
534 |
540 |
"""
|
535 |
541 |
self.ssl_key_pem = utils.ReadFile(ssl_key_path)
|
... | ... | |
560 |
566 |
@type ssl_params: HttpSslParams
|
561 |
567 |
@param ssl_params: SSL key and certificate
|
562 |
568 |
@type ssl_verify_peer: bool
|
563 |
|
@param ssl_verify_peer: Whether to require client certificate and compare
|
564 |
|
it with our certificate
|
|
569 |
@param ssl_verify_peer: Whether to require client certificate
|
|
570 |
and compare it with our certificate
|
565 |
571 |
|
566 |
572 |
"""
|
567 |
573 |
self._ssl_params = ssl_params
|
... | ... | |
959 |
965 |
|
960 |
966 |
This function also adjusts internal variables based on header values.
|
961 |
967 |
|
962 |
|
RFC2616, section 4.3: "The presence of a message-body in a request is
|
|
968 |
RFC2616, section 4.3: The presence of a message-body in a request is
|
963 |
969 |
signaled by the inclusion of a Content-Length or Transfer-Encoding header
|
964 |
|
field in the request's message-headers."
|
|
970 |
field in the request's message-headers.
|
965 |
971 |
|
966 |
972 |
"""
|
967 |
973 |
# Parse headers
|