define if accept only POST request by config
This commit is contained in:
parent
866c0e3835
commit
f17d9d9801
BIN
APIServer.exe
BIN
APIServer.exe
Binary file not shown.
14
APIServer.go
14
APIServer.go
@ -228,10 +228,13 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.RequestURI == "/favicon.ico" {
|
if r.RequestURI == "/favicon.ico" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
if cfg.Settings.MustPost {
|
||||||
fmt.Fprintf(w, "MethodNotAllowed: %v\r\n", http.StatusMethodNotAllowed)
|
if r.Method != http.MethodPost {
|
||||||
return
|
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
fmt.Fprintf(w, "MethodNotAllowed: %v\r\n", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reqID := uuid.NewV4().String()
|
reqID := uuid.NewV4().String()
|
||||||
@ -351,8 +354,7 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
host := ""
|
host := ""
|
||||||
if cfg.Settings.HostMode == 0 {
|
if cfg.Settings.HostMode == 0 {
|
||||||
host = strings.Split(r.Host, ":")[0]
|
host = strings.Split(r.Host, ":")[0]
|
||||||
}
|
} else {
|
||||||
if cfg.Settings.HostMode == 1 {
|
|
||||||
host, err = os.Hostname()
|
host, err = os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
host = "hostname"
|
host = "hostname"
|
||||||
|
@ -3,6 +3,7 @@ Settings:
|
|||||||
HookScript: APIHOOK
|
HookScript: APIHOOK
|
||||||
# HostMode: 0=IP Address; 1=Hostname
|
# HostMode: 0=IP Address; 1=Hostname
|
||||||
HostMode: 1
|
HostMode: 1
|
||||||
|
MustPost: false
|
||||||
ParamCheck: false
|
ParamCheck: false
|
||||||
LogRequest: false
|
LogRequest: false
|
||||||
LogResponse: false
|
LogResponse: false
|
||||||
|
@ -9,6 +9,7 @@ type Settings struct {
|
|||||||
ListenPort string `yaml:"ListenPort"`
|
ListenPort string `yaml:"ListenPort"`
|
||||||
HookScript string `yaml:"HookScript"`
|
HookScript string `yaml:"HookScript"`
|
||||||
HostMode int `yaml:"HostMode"`
|
HostMode int `yaml:"HostMode"`
|
||||||
|
MustPost bool `yaml:"MustPost"`
|
||||||
ParamCheck bool `yaml:"ParamCheck"`
|
ParamCheck bool `yaml:"ParamCheck"`
|
||||||
LogRequest bool `yaml:"LogRequest"`
|
LogRequest bool `yaml:"LogRequest"`
|
||||||
LogResponse bool `yaml:"LogResponse"`
|
LogResponse bool `yaml:"LogResponse"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user