From 580558a32c54823f702fd5feecabd7a87dc59c3d Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 2 Dec 2009 17:36:44 +0100
Subject: [PATCH] http: Add two new exceptions, one constant
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

These will be useful in the future in case we don't enfore JSON encoding
anymore in the http.server module. The HTTP 1.1 RFC recommends error 415
(Unsupported Media Type) to be returned in case the client requests an
unsupported content-type. If the client doesn't send a β€œContent-Type” in
the request, a content-type of β€œapplication/octet-stream” is implied.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/http/__init__.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lib/http/__init__.py b/lib/http/__init__.py
index e1b3ba734..272cff0e9 100644
--- a/lib/http/__init__.py
+++ b/lib/http/__init__.py
@@ -66,6 +66,8 @@ HTTP_AUTHORIZATION = "Authorization"
 HTTP_AUTHENTICATION_INFO = "Authentication-Info"
 HTTP_ALLOW = "Allow"
 
+HTTP_APP_OCTET_STREAM = "application/octet-stream"
+
 _SSL_UNEXPECTED_EOF = "Unexpected EOF"
 
 # Socket operations
@@ -178,6 +180,17 @@ class HttpMethodNotAllowed(HttpException):
   code = 405
 
 
+class HttpNotAcceptable(HttpException):
+  """406 Not Acceptable
+
+  RFC2616, 10.4.7: The resource identified by the request is only capable of
+  generating response entities which have content characteristics not
+  acceptable according to the accept headers sent in the request.
+
+  """
+  code = 406
+
+
 class HttpRequestTimeout(HttpException):
   """408 Request Timeout
 
@@ -235,6 +248,17 @@ class HttpPreconditionFailed(HttpException):
   code = 412
 
 
+class HttpUnsupportedMediaType(HttpException):
+  """415 Unsupported Media Type
+
+  RFC2616, 10.4.16: The server is refusing to service the request because the
+  entity of the request is in a format not supported by the requested resource
+  for the requested method.
+
+  """
+  code = 415
+
+
 class HttpInternalServerError(HttpException):
   """500 Internal Server Error
 
-- 
GitLab