HTTP 探测改为填写网址,缺本机引擎时立刻失败
HTTP 模式不再单独填端口。完整网址沿用其中的协议、端口和路径;只写主机名或 IP 时按 http 和 80 端口。超时默认改为 5000 毫秒。本机找不到或启动不了 netquality-reflector 时直接说明原因,并建议改用远程节点,不再记成一次全部失败。 Co-authored-by: yanjiu0721 <yanjiu0721@users.noreply.github.com>
This commit is contained in:
1 parent
846e40c023
commit
918ec8f190
20 files changed
+807
-131
No files matched your search
+16
-9
@@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -155,13 +156,13 @@ func (n *Node) auth(next http.HandlerFunc) http.HandlerFunc {
|
||||
}
|
||||
|
||||
type createReq struct {
|
||||
Target string `json:"target"`
|
||||
Port int `json:"port"`
|
||||
Profile string `json:"profile"`
|
||||
IntervalMs int `json:"intervalMs"`
|
||||
TimeoutMs int `json:"timeoutMs"`
|
||||
DurationSec int `json:"durationSec"`
|
||||
PacketSize int `json:"packetSize"`
|
||||
Target string `json:"target"`
|
||||
Port int `json:"port"`
|
||||
Profile string `json:"profile"`
|
||||
IntervalMs int `json:"intervalMs"`
|
||||
TimeoutMs int `json:"timeoutMs"`
|
||||
DurationSec int `json:"durationSec"`
|
||||
PacketSize int `json:"packetSize"`
|
||||
EchoToken string `json:"echoToken"`
|
||||
DNSName string `json:"dnsName"`
|
||||
PayloadHex string `json:"payloadHex"`
|
||||
@@ -224,7 +225,7 @@ func (n *Node) prepare(ctx context.Context, req createReq) (jobSpec, error) {
|
||||
}
|
||||
allow4 := flagOrDefault(req.AllowIPv4, true)
|
||||
allow6 := flagOrDefault(req.AllowIPv6, true)
|
||||
if req.Port < 1 || req.Port > 65535 {
|
||||
if req.Profile != "http" && (req.Port < 1 || req.Port > 65535) {
|
||||
return jobSpec{}, &apiError{http.StatusBadRequest, "bad_port", "端口需要在 1 到 65535 之间"}
|
||||
}
|
||||
interval := time.Duration(req.IntervalMs) * time.Millisecond
|
||||
@@ -279,11 +280,17 @@ func (n *Node) prepare(ctx context.Context, req createReq) (jobSpec, error) {
|
||||
}
|
||||
applyHTTPOptions(&httpIn, req.HTTP)
|
||||
lookupHost := req.Target
|
||||
resolvedPort := req.Port
|
||||
if req.Profile == "http" {
|
||||
page, err := buildHTTPURL(req.Target, req.Port)
|
||||
if err != nil {
|
||||
return jobSpec{}, &apiError{http.StatusBadRequest, "bad_target", err.Error()}
|
||||
}
|
||||
if p, convErr := strconv.Atoi(page.Port()); convErr == nil {
|
||||
resolvedPort = p
|
||||
httpIn.Port = p
|
||||
}
|
||||
httpIn.Target = page.String()
|
||||
if _, err := normalizeHTTPVersion(httpIn.Version); err != nil {
|
||||
return jobSpec{}, &apiError{http.StatusBadRequest, "bad_profile", err.Error()}
|
||||
}
|
||||
@@ -315,7 +322,7 @@ func (n *Node) prepare(ctx context.Context, req createReq) (jobSpec, error) {
|
||||
return jobSpec{}, &apiError{http.StatusBadRequest, "bad_family", "地址族不被允许"}
|
||||
}
|
||||
return jobSpec{
|
||||
Host: req.Target, Port: req.Port, Profile: req.Profile, IP: ips[0],
|
||||
Host: req.Target, Port: resolvedPort, Profile: req.Profile, IP: ips[0],
|
||||
state: &dialState{picker: newEndpointPicker(ips)},
|
||||
Interval: interval, Timeout: timeout, Duration: duration, PacketSize: size,
|
||||
Echo: echo, DNSName: req.DNSName, Payload: payload, Expect: expect,
|
||||
|
||||
Reference in new issue
Block a user