Browse Source

Merge "More details when logging 413 Entity Too Large"

tags/3.38.1^0
Zuul 2 months ago
parent
commit
9bae80ec02

+ 9
- 3
oslo_middleware/sizelimit.py View File

@@ -17,6 +17,8 @@ Request Body limiting middleware.
17 17
 
18 18
 """
19 19
 
20
+import logging
21
+
20 22
 from oslo_config import cfg
21 23
 import webob.dec
22 24
 import webob.exc
@@ -24,6 +26,8 @@ import webob.exc
24 26
 from oslo_middleware._i18n import _
25 27
 from oslo_middleware import base
26 28
 
29
+LOG = logging.getLogger(__name__)
30
+
27 31
 
28 32
 _oldopts = [cfg.DeprecatedOpt('osapi_max_request_body_size',
29 33
                               group='DEFAULT'),
@@ -56,7 +60,7 @@ class LimitingReader(object):
56 60
         for chunk in self.data:
57 61
             self.bytes_read += len(chunk)
58 62
             if self.bytes_read > self.limit:
59
-                msg = _("Request is too large.")
63
+                msg = _("Request is too large. Larger than %s") % self.limit
60 64
                 raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg)
61 65
             else:
62 66
                 yield chunk
@@ -70,7 +74,7 @@ class LimitingReader(object):
70 74
             result = self.data.read(i)
71 75
         self.bytes_read += len(result)
72 76
         if self.bytes_read > self.limit:
73
-            msg = _("Request is too large.")
77
+            msg = _("Request is too large. Larger than %s.") % self.limit
74 78
             raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg)
75 79
         return result
76 80
 
@@ -87,7 +91,9 @@ class RequestBodySizeLimiter(base.ConfigurableMiddleware):
87 91
         max_size = self._conf_get('max_request_body_size')
88 92
         if (req.content_length is not None and
89 93
                 req.content_length > max_size):
90
-            msg = _("Request is too large.")
94
+            msg = _("Request is too large. "
95
+                    "Larger than max_request_body_size (%s).") % max_size
96
+            LOG.info(msg)
91 97
             raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg)
92 98
         if req.content_length is None:
93 99
             limiter = LimitingReader(req.body_file, max_size)

+ 4
- 0
releasenotes/notes/log_max_request_body_size-1835363-6f37946210a100d7.yaml View File

@@ -0,0 +1,4 @@
1
+---
2
+other:
3
+  - |
4
+    Log when max_request_body_size is exceeded.

Loading…
Cancel
Save