mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
feat: support custom HTTP headers in custom HttpEmailProvider and hide unused fields (#3723)
This commit is contained in:
@ -24,14 +24,16 @@ import (
|
||||
)
|
||||
|
||||
type HttpEmailProvider struct {
|
||||
endpoint string
|
||||
method string
|
||||
endpoint string
|
||||
method string
|
||||
httpHeaders map[string]string
|
||||
}
|
||||
|
||||
func NewHttpEmailProvider(endpoint string, method string) *HttpEmailProvider {
|
||||
func NewHttpEmailProvider(endpoint string, method string, httpHeaders map[string]string) *HttpEmailProvider {
|
||||
client := &HttpEmailProvider{
|
||||
endpoint: endpoint,
|
||||
method: method,
|
||||
endpoint: endpoint,
|
||||
method: method,
|
||||
httpHeaders: httpHeaders,
|
||||
}
|
||||
return client
|
||||
}
|
||||
@ -39,7 +41,7 @@ func NewHttpEmailProvider(endpoint string, method string) *HttpEmailProvider {
|
||||
func (c *HttpEmailProvider) Send(fromAddress string, fromName string, toAddress string, subject string, content string) error {
|
||||
var req *http.Request
|
||||
var err error
|
||||
if c.method == "POST" {
|
||||
if c.method == "POST" || c.method == "PUT" || c.method == "DELETE" {
|
||||
formValues := url.Values{}
|
||||
formValues.Set("fromName", fromName)
|
||||
formValues.Set("toAddress", toAddress)
|
||||
@ -67,6 +69,10 @@ func (c *HttpEmailProvider) Send(fromAddress string, fromName string, toAddress
|
||||
return fmt.Errorf("HttpEmailProvider's Send() error, unsupported method: %s", c.method)
|
||||
}
|
||||
|
||||
for k, v := range c.httpHeaders {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
httpClient := proxy.DefaultHttpClient
|
||||
resp, err := httpClient.Do(req)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user