define if accept only POST request by config

This commit is contained in:
r0n1n7an 2024-08-13 09:06:34 +08:00
parent 866c0e3835
commit f17d9d9801
4 changed files with 10 additions and 6 deletions

Binary file not shown.

View File

@ -228,10 +228,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/favicon.ico" {
return
}
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "MethodNotAllowed: %v\r\n", http.StatusMethodNotAllowed)
return
if cfg.Settings.MustPost {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "MethodNotAllowed: %v\r\n", http.StatusMethodNotAllowed)
return
}
}
reqID := uuid.NewV4().String()
@ -351,8 +354,7 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
host := ""
if cfg.Settings.HostMode == 0 {
host = strings.Split(r.Host, ":")[0]
}
if cfg.Settings.HostMode == 1 {
} else {
host, err = os.Hostname()
if err != nil {
host = "hostname"

View File

@ -3,6 +3,7 @@ Settings:
HookScript: APIHOOK
# HostMode: 0=IP Address; 1=Hostname
HostMode: 1
MustPost: false
ParamCheck: false
LogRequest: false
LogResponse: false

View File

@ -9,6 +9,7 @@ type Settings struct {
ListenPort string `yaml:"ListenPort"`
HookScript string `yaml:"HookScript"`
HostMode int `yaml:"HostMode"`
MustPost bool `yaml:"MustPost"`
ParamCheck bool `yaml:"ParamCheck"`
LogRequest bool `yaml:"LogRequest"`
LogResponse bool `yaml:"LogResponse"`