Do not redirect if no originURI is set

This commit is contained in:
Dominik George 2022-04-28 23:30:56 +02:00
parent 477643b58e
commit 66d5aae498
No known key found for this signature in database
GPG Key ID: 0AE554E5460E1BDD
1 changed files with 16 additions and 11 deletions

View File

@ -297,6 +297,7 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
contactResponse.Message = "Invalid request, please review your input and try again."
}
if contactRequest.OriginURI != "" {
originURL, err := url.Parse(contactRequest.OriginURI)
if err != nil {
log.Printf("error parsing the origin URL %s (%s)", originURL, err.Error())
@ -308,10 +309,14 @@ func SendMail(httpResp http.ResponseWriter, httpReq *http.Request) {
q.Set("message", contactResponse.Message)
originURL.RawQuery = q.Encode()
respRawData, _ := json.Marshal(contactResponse)
httpResp.Header().Set("Location", originURL.String())
httpResp.WriteHeader(http.StatusSeeOther)
} else {
httpResp.WriteHeader(http.StatusOK)
}
respRawData, _ := json.Marshal(contactResponse)
httpResp.Header().Set("Content-Type", "application/json; charset=UTF-8")
httpResp.Write(respRawData)
}