feat: Set content length header for comletion and time estiamte on
browsers
This commit is contained in:
parent
aef6deb8d6
commit
9532b70458
16
main.go
16
main.go
@ -294,20 +294,22 @@ func main() {
|
|||||||
|
|
||||||
if dataRequest.StatusCode != 200 {
|
if dataRequest.StatusCode != 200 {
|
||||||
log.Println("Failed to get content for URL", userURL)
|
log.Println("Failed to get content for URL", userURL)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
contentLength := dataRequest.Header.Get("Content-Length")
|
||||||
w.Header().Set(
|
|
||||||
"Content-Disposition",
|
|
||||||
fmt.Sprintf("attachment;filename=%s", filename),
|
|
||||||
)
|
|
||||||
w.WriteHeader(206)
|
|
||||||
|
|
||||||
if dataRequest.ContentLength == 0 {
|
if dataRequest.ContentLength == 0 {
|
||||||
log.Println("Empty body from content url")
|
log.Println("Empty body from content url")
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
return
|
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)
|
n, err := io.Copy(w, dataRequest.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user