Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
407d03a0
authored
Dec 04, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support gzip
parent
c709ab7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
0 deletions
+28
-0
middleware/gzip.go
+27
-0
router/relay-router.go
+1
-0
No files found.
middleware/gzip.go
0 → 100644
View file @
407d03a0
package
middleware
import
(
"compress/gzip"
"github.com/gin-gonic/gin"
"io"
"net/http"
)
func
GzipDecodeMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
if
c
.
GetHeader
(
"Content-Encoding"
)
==
"gzip"
{
gzipReader
,
err
:=
gzip
.
NewReader
(
c
.
Request
.
Body
)
if
err
!=
nil
{
c
.
AbortWithStatus
(
http
.
StatusBadRequest
)
return
}
defer
gzipReader
.
Close
()
// Replace the request body with the decompressed data
c
.
Request
.
Body
=
io
.
NopCloser
(
gzipReader
)
}
// Continue processing the request
c
.
Next
()
}
}
router/relay-router.go
View file @
407d03a0
...
...
@@ -9,6 +9,7 @@ import (
func
SetRelayRouter
(
router
*
gin
.
Engine
)
{
router
.
Use
(
middleware
.
CORS
())
router
.
Use
(
middleware
.
GzipDecodeMiddleware
())
// https://platform.openai.com/docs/api-reference/introduction
modelsRouter
:=
router
.
Group
(
"/v1/models"
)
modelsRouter
.
Use
(
middleware
.
TokenAuth
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment