diff --git a/.version b/.version index 994d91615..61cca7fec 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.2.507 \ No newline at end of file +0.2.508 \ No newline at end of file diff --git a/cmd/templ/generatecmd/proxy/proxy.go b/cmd/templ/generatecmd/proxy/proxy.go index 07998e286..29bce58fd 100644 --- a/cmd/templ/generatecmd/proxy/proxy.go +++ b/cmd/templ/generatecmd/proxy/proxy.go @@ -1,6 +1,7 @@ package proxy import ( + "bytes" "fmt" "io" "log" @@ -89,17 +90,29 @@ type roundTripper struct { } func (rt *roundTripper) RoundTrip(r *http.Request) (*http.Response, error) { - var err error + // Read and buffer the body. + var bodyBytes []byte + if r.Body != nil && r.Body != http.NoBody { + var err error + bodyBytes, err = io.ReadAll(r.Body) + if err != nil { + return nil, err + } + r.Body.Close() + } + // Retry logic. + var resp *http.Response + var err error for retries := 0; retries < rt.maxRetries; retries++ { + // Clone the request and set the body. req := r.Clone(r.Context()) - - req.Body, err = r.GetBody() - if err != nil { - return nil, err + if bodyBytes != nil { + req.Body = io.NopCloser(bytes.NewReader(bodyBytes)) } - resp, err := http.DefaultTransport.RoundTrip(req) + // Execute the request. + resp, err = http.DefaultTransport.RoundTrip(req) if err != nil { time.Sleep(rt.initialDelay * time.Duration(math.Pow(rt.backoffExponent, float64(retries)))) continue