mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 21:00:52 +08:00
- Introduced unit tests for request logging middleware to enhance coverage. - Added WebSocket-based Codex executor to support Responses API upgrade. - Updated middleware logic to selectively capture request bodies for memory efficiency. - Enhanced Codex configuration handling with new WebSocket attributes.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestExtractRequestBodyPrefersOverride(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
recorder := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(recorder)
|
|
|
|
wrapper := &ResponseWriterWrapper{
|
|
requestInfo: &RequestInfo{Body: []byte("original-body")},
|
|
}
|
|
|
|
body := wrapper.extractRequestBody(c)
|
|
if string(body) != "original-body" {
|
|
t.Fatalf("request body = %q, want %q", string(body), "original-body")
|
|
}
|
|
|
|
c.Set(requestBodyOverrideContextKey, []byte("override-body"))
|
|
body = wrapper.extractRequestBody(c)
|
|
if string(body) != "override-body" {
|
|
t.Fatalf("request body = %q, want %q", string(body), "override-body")
|
|
}
|
|
}
|
|
|
|
func TestExtractRequestBodySupportsStringOverride(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
recorder := httptest.NewRecorder()
|
|
c, _ := gin.CreateTestContext(recorder)
|
|
|
|
wrapper := &ResponseWriterWrapper{}
|
|
c.Set(requestBodyOverrideContextKey, "override-as-string")
|
|
|
|
body := wrapper.extractRequestBody(c)
|
|
if string(body) != "override-as-string" {
|
|
t.Fatalf("request body = %q, want %q", string(body), "override-as-string")
|
|
}
|
|
}
|