feat: add Location header to response
This commit is contained in:
parent
fae72778d9
commit
6ed93d226e
@ -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, "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) {
|
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, "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 {
|
func (app *Application) publicURL(file io.Reader, extension string) string {
|
||||||
|
10
helpers.go
10
helpers.go
@ -119,3 +119,13 @@ func BasicAuth(next http.HandlerFunc, app *Application) http.HandlerFunc {
|
|||||||
http.Error(w, "Unauthorized", http.StatusUnauthorized)
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user