diff --git a/handlers.go b/handlers.go index 5d24997..d674385 100644 --- a/handlers.go +++ b/handlers.go @@ -172,7 +172,7 @@ func (app *Application) formHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Error parsing file: %s", err.Error()) } - fmt.Fprintf(w, "%s", fmt.Sprintf("http://%s/%s\n", app.url, filename)) + ResponseURLHandler(w, app.url, filename) } func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) { @@ -209,7 +209,7 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Error parsing file: %s", err.Error()) } - fmt.Fprintf(w, "%s", fmt.Sprintf("http://%s/%s\n", app.url, filename)) + ResponseURLHandler(w, app.url, filename) } func (app *Application) publicURL(file io.Reader, extension string) string { diff --git a/helpers.go b/helpers.go index a799e62..b4f2c40 100644 --- a/helpers.go +++ b/helpers.go @@ -119,3 +119,13 @@ func BasicAuth(next http.HandlerFunc, app *Application) http.HandlerFunc { http.Error(w, "Unauthorized", http.StatusUnauthorized) }) } + +func ResponseURLHandler(w http.ResponseWriter, url, filename string) { + pasteURL := fmt.Sprintf("http://%s/%s\n", url, filename) + + w.Header().Set("Location", pasteURL) + + w.WriteHeader(http.StatusCreated) + + fmt.Fprintf(w, "%s", pasteURL) +}