From 0c8ff3ea049035bda3ca8203f677ea382eeb0e8b Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 24 Jun 2016 12:05:14 +1000 Subject: [PATCH] Fixup download handler --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 48c0710..c70f545 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "crypto/sha1" "database/sql" "encoding/base64" @@ -13,6 +14,7 @@ import ( "io/ioutil" "log" "net/http" + "time" "github.com/dchest/uniuri" "github.com/ewhal/pygments" @@ -259,9 +261,7 @@ func downloadHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) paste := vars["pasteId"] s := getPaste(paste, "") - w.Header().Set("Content-Disposition", "attachment; filename="+paste) - w.Header().Set("Content-Type", r.Header.Get("Content-Type")) - io.Copy(w, s) + http.ServeContent(w, r, paste, time.Now(), bytes.NewReader([]byte(s))) } func rawHandler(w http.ResponseWriter, r *http.Request) {