Dechunk HTTP requests by default (#11)

ProxyManager already has all the Request body's data. There is no never
a need to use chunked transfer encoding to the upstream process.
This commit is contained in:
Benson Wong
2024-11-19 09:40:44 -08:00
parent 5021e0f299
commit 7eec51f3f2
3 changed files with 10 additions and 4 deletions

View File

@@ -178,7 +178,7 @@ func (p *Process) ProxyRequest(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
req.Header = r.Header
req.Header = r.Header.Clone()
resp, err := client.Do(req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"sync"
"time"
@@ -121,6 +122,11 @@ func (pm *ProxyManager) proxyChatRequestHandler(c *gin.Context) {
}
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
// dechunk it as we already have all the body bytes see issue #11
c.Request.Header.Del("transfer-encoding")
c.Request.Header.Add("content-length", strconv.Itoa(len(bodyBytes)))
pm.currentProcess.ProxyRequest(c.Writer, c.Request)
}