This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
summer-utils/tables/web/http-route.go
2023-04-16 11:56:17 +01:00

50 lines
1.4 KiB
Go

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