Skip to content

Commit

Permalink
Update upload handler to use dynamic URL scheme based on request prot…
Browse files Browse the repository at this point in the history
…ocol (#20)
  • Loading branch information
dhcgn authored Dec 31, 2024
1 parent fb24b51 commit a7bea90
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions httphandler/uploadHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ func (c Config) handleUpload(w http.ResponseWriter, r *http.Request, uploadKey,
}

func constructAndReturnResponse(w http.ResponseWriter, r *http.Request, downloadKey string, params map[string]string) {
scheme := "http"
if r.TLS != nil {
scheme = "https"
}

urls := make(map[string]string)
for key := range params {
urls[key] = fmt.Sprintf("http://%s/d/%s/plain/%s", r.Host, downloadKey, key)
urls[key] = fmt.Sprintf("%s://%s/d/%s/plain/%s", scheme, r.Host, downloadKey, key)
}

downloadURL := fmt.Sprintf("http://%s/d/%s/json", r.Host, downloadKey)
downloadURL := fmt.Sprintf("%s://%s/d/%s/json", scheme, r.Host, downloadKey)

jsonResponse(w, map[string]interface{}{
"message": "Data uploaded successfully",
Expand Down

0 comments on commit a7bea90

Please sign in to comment.