feat(api): add request body decoding with Content-Encoding support
- Introduced `ReadRequestBody` helper function to support decoding request bodies based on "Content-Encoding" (e.g., `zstd`). - Replaced `c.GetRawData()` with `ReadRequestBody` across handlers to enable decoding. - Added test case to validate `zstd` decoding for compact responses.
This commit is contained in:
@@ -96,7 +96,7 @@ func (h *OpenAIAPIHandler) OpenAIModels(c *gin.Context) {
|
||||
// Parameters:
|
||||
// - c: The Gin context containing the HTTP request and response
|
||||
func (h *OpenAIAPIHandler) ChatCompletions(c *gin.Context) {
|
||||
rawJSON, err := c.GetRawData()
|
||||
rawJSON, err := handlers.ReadRequestBody(c)
|
||||
// If data retrieval fails, return a 400 Bad Request error.
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, handlers.ErrorResponse{
|
||||
@@ -151,7 +151,7 @@ func shouldTreatAsResponsesFormat(rawJSON []byte) bool {
|
||||
// Parameters:
|
||||
// - c: The Gin context containing the HTTP request and response
|
||||
func (h *OpenAIAPIHandler) Completions(c *gin.Context) {
|
||||
rawJSON, err := c.GetRawData()
|
||||
rawJSON, err := handlers.ReadRequestBody(c)
|
||||
// If data retrieval fails, return a 400 Bad Request error.
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, handlers.ErrorResponse{
|
||||
|
||||
Reference in New Issue
Block a user