mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 06:28:18 +01:00
33 lines
608 B
Go
33 lines
608 B
Go
package utils
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/valyala/fasthttp/fasthttpadaptor"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
func ConvertToStdRequest(c *fiber.Ctx) (*http.Request, error) {
|
|
stdReq := &http.Request{}
|
|
if err := fasthttpadaptor.ConvertRequest(c.Context(), stdReq, true); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return stdReq, nil
|
|
}
|
|
|
|
func CopyBody(req *http.Request) ([]byte, error) {
|
|
body, err := io.ReadAll(req.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := req.Body.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Body = io.NopCloser(bytes.NewBuffer(body))
|
|
return body, nil
|
|
}
|