Do not redirect if no originURI is set
This commit is contained in:
parent
477643b58e
commit
66d5aae498
27
sendmail.go
27
sendmail.go
|
@ -297,21 +297,26 @@ 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."
|
||||||
}
|
}
|
||||||
|
|
||||||
originURL, err := url.Parse(contactRequest.OriginURI)
|
if contactRequest.OriginURI != "" {
|
||||||
if err != nil {
|
originURL, err := url.Parse(contactRequest.OriginURI)
|
||||||
log.Printf("error parsing the origin URL %s (%s)", originURL, err.Error())
|
if err != nil {
|
||||||
originURL = &url.URL{} // continue with default (empty) url
|
log.Printf("error parsing the origin URL %s (%s)", originURL, err.Error())
|
||||||
}
|
originURL = &url.URL{} // continue with default (empty) url
|
||||||
|
}
|
||||||
|
|
||||||
q := originURL.Query()
|
q := originURL.Query()
|
||||||
q.Set("status", contactResponse.Status)
|
q.Set("status", contactResponse.Status)
|
||||||
q.Set("message", contactResponse.Message)
|
q.Set("message", contactResponse.Message)
|
||||||
originURL.RawQuery = q.Encode()
|
originURL.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
httpResp.Header().Set("Location", originURL.String())
|
||||||
|
httpResp.WriteHeader(http.StatusSeeOther)
|
||||||
|
} else {
|
||||||
|
httpResp.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
respRawData, _ := json.Marshal(contactResponse)
|
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.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
httpResp.Write(respRawData)
|
httpResp.Write(respRawData)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue