feat: https url return
This commit is contained in:
parent
6dceedf978
commit
456dc6856d
@ -180,7 +180,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())
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseURLHandler(w, app.url, filename)
|
ResponseURLHandler(r, w, app.url, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) {
|
func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -220,7 +220,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())
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseURLHandler(w, app.url, filename)
|
ResponseURLHandler(r, w, app.url, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *Application) publicURL(file io.Reader, extension string, full bool) string {
|
func (app *Application) publicURL(file io.Reader, extension string, full bool) string {
|
||||||
|
10
helpers.go
10
helpers.go
@ -123,12 +123,14 @@ func BasicAuth(next http.HandlerFunc, app *Application) http.HandlerFunc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResponseURLHandler(w http.ResponseWriter, url, filename string) {
|
func ResponseURLHandler(r *http.Request, w http.ResponseWriter, url, filename string) {
|
||||||
pasteURL := fmt.Sprintf("http://%s/%s\n", url, filename)
|
protocol := "http"
|
||||||
|
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
|
||||||
|
protocol = "https"
|
||||||
|
}
|
||||||
|
pasteURL := fmt.Sprintf("%s://%s/%s\n", protocol, url, filename)
|
||||||
|
|
||||||
w.Header().Set("Location", pasteURL)
|
w.Header().Set("Location", pasteURL)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s", pasteURL)
|
fmt.Fprintf(w, "%s", pasteURL)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user