mirror of
https://github.com/versity/versitygw.git
synced 2026-09-19 14:34:19 +00:00
Fixes #1418 If neither the `Transfer-Encoding` nor the `Content-Length` headers are provided in chunked uploads, **fasthttp** assumes there is no request body and sets the request body reader to `nil`. This leads to a panic in the auth reader when it attempts to read the body. The fix ensures that if the request body reader is `nil`, it is overridden with an `empty reader` to prevent panics.
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
// Copyright 2023 Versity Software
|
|
// This file is licensed 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.
|
|
|
|
package middlewares
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/versity/versitygw/s3api/utils"
|
|
)
|
|
|
|
func wrapBodyReader(ctx *fiber.Ctx, wr func(io.Reader) io.Reader) {
|
|
r, ok := utils.ContextKeyBodyReader.Get(ctx).(io.Reader)
|
|
if !ok {
|
|
r = ctx.Request().BodyStream()
|
|
// Override the body reader with an empty reader to prevent panics
|
|
// in case of unexpected or malformed HTTP requests.
|
|
if r == nil {
|
|
r = bytes.NewBuffer([]byte{})
|
|
}
|
|
}
|
|
|
|
r = wr(r)
|
|
utils.ContextKeyBodyReader.Set(ctx, r)
|
|
}
|