Merge pull request #11 from Natureshadow/feature-no-redirect

Do not redirect if no requestOrigin is set
This commit is contained in:
Rodrigue Chakode 2022-04-29 12:30:59 +02:00 committed by GitHub
commit ad8e700e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 11 deletions

View File

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