From 9532b70458b8c7d0568eaedbf6ededb475305240 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 15 Sep 2023 18:48:45 +0300 Subject: [PATCH] feat: Set content length header for comletion and time estiamte on browsers --- main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 94ac41c..20833fc 100644 --- a/main.go +++ b/main.go @@ -294,19 +294,21 @@ func main() { if dataRequest.StatusCode != 200 { log.Println("Failed to get content for URL", userURL) + return } - - w.Header().Set( - "Content-Disposition", - fmt.Sprintf("attachment;filename=%s", filename), - ) - w.WriteHeader(206) - + contentLength := dataRequest.Header.Get("Content-Length") if dataRequest.ContentLength == 0 { log.Println("Empty body from content url") w.WriteHeader(500) return } + + w.Header().Set( + "Content-Disposition", + fmt.Sprintf("attachment;filename=%s;", filename), + ) + w.Header().Set("Content-Length", contentLength) + w.WriteHeader(206) n, err := io.Copy(w, dataRequest.Body) if err != nil {