From a7bea9009c3a54c223335ad74f40a4364eea3b13 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 31 Dec 2024 14:48:56 +0100 Subject: [PATCH] Update upload handler to use dynamic URL scheme based on request protocol (#20) --- httphandler/uploadHandler.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/httphandler/uploadHandler.go b/httphandler/uploadHandler.go index 9333ac3..ca51ffb 100644 --- a/httphandler/uploadHandler.go +++ b/httphandler/uploadHandler.go @@ -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",