fix possible URI encoding issues
Encode query parameters for the Location URL.
This commit is contained in:
parent
5f9a9ea9a7
commit
f3a62cd876
19
sendmail.go
19
sendmail.go
|
@ -25,6 +25,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -258,14 +259,20 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
|
||||||
contactResponse.Message = "Invalid request, please review your input and try again."
|
contactResponse.Message = "Invalid request, please review your input and try again."
|
||||||
}
|
}
|
||||||
|
|
||||||
refererURL := strings.Split(httpReq.Header["Referer"][0], "?")[0]
|
refererURL, err := url.Parse(httpReq.Header.Get("Referer"))
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("error: %s", err.Error())
|
||||||
|
refererURL = &url.URL{} // continue with default (empty) url
|
||||||
|
}
|
||||||
|
|
||||||
|
q := refererURL.Query()
|
||||||
|
q.Set("status", contactResponse.Status)
|
||||||
|
q.Set("message", contactResponse.Message)
|
||||||
|
refererURL.RawQuery = q.Encode()
|
||||||
|
|
||||||
respRawData, _ := json.Marshal(contactResponse)
|
respRawData, _ := json.Marshal(contactResponse)
|
||||||
|
|
||||||
httpResp.Header().Set("Location",
|
httpResp.Header().Set("Location", refererURL.String())
|
||||||
fmt.Sprintf("%s?status=%s&message=%s",
|
|
||||||
refererURL,
|
|
||||||
contactResponse.Status,
|
|
||||||
contactResponse.Message))
|
|
||||||
httpResp.WriteHeader(http.StatusSeeOther)
|
httpResp.WriteHeader(http.StatusSeeOther)
|
||||||
httpResp.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
httpResp.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
httpResp.Write(respRawData)
|
httpResp.Write(respRawData)
|
||||||
|
|
Loading…
Reference in New Issue