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" {
|
||||
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"
|
||||
|
@ -3,6 +3,7 @@ Settings:
|
||||
HookScript: APIHOOK
|
||||
# HostMode: 0=IP Address; 1=Hostname
|
||||
HostMode: 1
|
||||
MustPost: false
|
||||
ParamCheck: false
|
||||
LogRequest: false
|
||||
LogResponse: false
|
||||
|
@ -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"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user