keremoge commented on code in PR #14002:
URL: https://github.com/apache/apisix/pull/14002#discussion_r4181890953


##########
apisix/plugins/signing/request.lua:
##########
@@ -0,0 +1,88 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+
+local ngx = ngx
+
+local _M = {}
+
+
+local function contains(values, expected)
+    for _, value in ipairs(values) do
+        if value == expected then
+            return true
+        end
+    end
+    return false
+end
+
+
+local function normalized_content_type(value)
+    if not value then
+        return ""
+    end
+    local normalized = value:match("^%s*([^;]+)")
+    return normalized and normalized:lower() or ""
+end
+
+
+function _M.rewrite(plugin_name, conf, ctx, sign)
+    if type(conf) ~= "table" then
+        return 500, {message = "internal_error"}
+    end
+
+    conf.request = conf.request or {}
+    conf.request.methods = conf.request.methods or {"POST"}
+    conf.request.content_types = conf.request.content_types or 
{"application/xml"}
+    conf.request.max_body_bytes = conf.request.max_body_bytes or 5242880
+
+    if not contains(conf.request.methods, ngx.req.get_method()) then
+        return
+    end
+
+    local content_type = normalized_content_type(
+        core.request.header(ctx, "Content-Type"))
+    if not contains(conf.request.content_types, content_type) then
+        return 415, {message = "unsupported_media_type"}
+    end
+
+    local body, body_err = core.request.get_body(conf.request.max_body_bytes, 
ctx)
+    if not body then
+        core.log.error(plugin_name, " failed to read request body")
+        return body_err and 413 or 400,
+               {message = body_err and "body_too_large" or "empty_body"}
+    end
+
+    if conf.signature.algorithm == "rsa-sha1" then
+        core.log.warn(plugin_name, " is using legacy SHA-1 cryptography")
+    end

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to