feat: https url return

This commit is contained in:
jabuxas 2025-02-09 20:15:32 -03:00
parent 6dceedf978
commit 456dc6856d
2 changed files with 8 additions and 6 deletions

View File

@ -180,7 +180,7 @@ func (app *Application) formHandler(w http.ResponseWriter, r *http.Request) {
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) {
@ -220,7 +220,7 @@ func (app *Application) curlHandler(w http.ResponseWriter, r *http.Request) {
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 {

View File

@ -123,12 +123,14 @@ func BasicAuth(next http.HandlerFunc, app *Application) http.HandlerFunc {
})
}
func ResponseURLHandler(w http.ResponseWriter, url, filename string) {
pasteURL := fmt.Sprintf("http://%s/%s\n", url, filename)
func ResponseURLHandler(r *http.Request, w http.ResponseWriter, url, filename string) {
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.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "%s", pasteURL)
}