50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package web
|
|
|
|
import (
|
|
"code.mrmelon54.com/melon/summer-utils/utils"
|
|
"net/http"
|
|
)
|
|
|
|
type HttpService struct {
|
|
Id uint64 `json:"id" xorm:"pk autoincr"`
|
|
Host string `json:"host"`
|
|
Dst string `json:"dst"`
|
|
AbsPath *bool `json:"abs_path,omitempty"`
|
|
SecureMode *bool `json:"secure_mode,omitempty"`
|
|
IgnoreCert *bool `json:"ignore_cert,omitempty"`
|
|
ForwardHost *bool `json:"forward_host,omitempty"`
|
|
Enabled *bool `json:"enabled"`
|
|
LiveHeaders []HttpServiceHeader `json:"-" xorm:"-"`
|
|
}
|
|
|
|
func (h HttpService) GetId() uint64 { return h.Id }
|
|
|
|
func (h HttpService) SetEnabled(v bool) HttpService {
|
|
h.Enabled = utils.PBool(v)
|
|
return h
|
|
}
|
|
|
|
func (h HttpService) ClearForNew() HttpService {
|
|
h.Id = 0
|
|
return h
|
|
}
|
|
|
|
func (h HttpService) Target() string { return h.Dst }
|
|
func (h HttpService) IsAbsPath() bool { return utils.SBool(h.AbsPath) }
|
|
func (h HttpService) IsSecureMode() bool { return utils.SBool(h.SecureMode) }
|
|
func (h HttpService) IsIgnoreCert() bool { return utils.SBool(h.IgnoreCert) }
|
|
func (h HttpService) IsForwardHost() bool { return utils.SBool(h.ForwardHost) }
|
|
|
|
func (h HttpService) UpdateHeaders(header http.Header) {
|
|
if h.LiveHeaders == nil {
|
|
return
|
|
}
|
|
for _, i := range h.LiveHeaders {
|
|
if a := i.Value; a != nil && *a != "" {
|
|
header.Set(i.Key, *a)
|
|
} else {
|
|
header.Del(i.Key)
|
|
}
|
|
}
|
|
}
|