mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-08 13:29:56 +00:00
feat: masquerade string mode
This commit is contained in:
parent
4ebc765f43
commit
197e913dce
@ -181,10 +181,17 @@ type serverConfigMasqueradeProxy struct {
|
|||||||
RewriteHost bool `mapstructure:"rewriteHost"`
|
RewriteHost bool `mapstructure:"rewriteHost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type serverConfigMasqueradeString struct {
|
||||||
|
Content string `mapstructure:"content"`
|
||||||
|
Headers map[string]string `mapstructure:"headers"`
|
||||||
|
StatusCode int `mapstructure:"statusCode"`
|
||||||
|
}
|
||||||
|
|
||||||
type serverConfigMasquerade struct {
|
type serverConfigMasquerade struct {
|
||||||
Type string `mapstructure:"type"`
|
Type string `mapstructure:"type"`
|
||||||
File serverConfigMasqueradeFile `mapstructure:"file"`
|
File serverConfigMasqueradeFile `mapstructure:"file"`
|
||||||
Proxy serverConfigMasqueradeProxy `mapstructure:"proxy"`
|
Proxy serverConfigMasqueradeProxy `mapstructure:"proxy"`
|
||||||
|
String serverConfigMasqueradeString `mapstructure:"string"`
|
||||||
ListenHTTP string `mapstructure:"listenHTTP"`
|
ListenHTTP string `mapstructure:"listenHTTP"`
|
||||||
ListenHTTPS string `mapstructure:"listenHTTPS"`
|
ListenHTTPS string `mapstructure:"listenHTTPS"`
|
||||||
ForceHTTPS bool `mapstructure:"forceHTTPS"`
|
ForceHTTPS bool `mapstructure:"forceHTTPS"`
|
||||||
@ -613,6 +620,25 @@ func (c *serverConfig) fillMasqHandler(hyConfig *server.Config) error {
|
|||||||
w.WriteHeader(http.StatusBadGateway)
|
w.WriteHeader(http.StatusBadGateway)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
case "string":
|
||||||
|
if c.Masquerade.String.Content == "" {
|
||||||
|
return configError{Field: "masquerade.string.content", Err: errors.New("empty string content")}
|
||||||
|
}
|
||||||
|
if c.Masquerade.String.StatusCode != 0 &&
|
||||||
|
(c.Masquerade.String.StatusCode < 200 || c.Masquerade.String.StatusCode > 599) {
|
||||||
|
return configError{Field: "masquerade.string.statusCode", Err: errors.New("invalid status code (must be 200-599)")}
|
||||||
|
}
|
||||||
|
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
for k, v := range c.Masquerade.String.Headers {
|
||||||
|
w.Header().Set(k, v)
|
||||||
|
}
|
||||||
|
if c.Masquerade.String.StatusCode != 0 {
|
||||||
|
w.WriteHeader(c.Masquerade.String.StatusCode)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusOK) // Use 200 OK by default
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(c.Masquerade.String.Content))
|
||||||
|
})
|
||||||
default:
|
default:
|
||||||
return configError{Field: "masquerade.type", Err: errors.New("unsupported masquerade type")}
|
return configError{Field: "masquerade.type", Err: errors.New("unsupported masquerade type")}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,14 @@ func TestServerConfig(t *testing.T) {
|
|||||||
URL: "https://some.site.net",
|
URL: "https://some.site.net",
|
||||||
RewriteHost: true,
|
RewriteHost: true,
|
||||||
},
|
},
|
||||||
|
String: serverConfigMasqueradeString{
|
||||||
|
Content: "aint nothin here",
|
||||||
|
Headers: map[string]string{
|
||||||
|
"content-type": "text/plain",
|
||||||
|
"custom-haha": "lol",
|
||||||
|
},
|
||||||
|
StatusCode: 418,
|
||||||
|
},
|
||||||
ListenHTTP: ":80",
|
ListenHTTP: ":80",
|
||||||
ListenHTTPS: ":443",
|
ListenHTTPS: ":443",
|
||||||
ForceHTTPS: true,
|
ForceHTTPS: true,
|
||||||
|
@ -102,6 +102,12 @@ masquerade:
|
|||||||
proxy:
|
proxy:
|
||||||
url: https://some.site.net
|
url: https://some.site.net
|
||||||
rewriteHost: true
|
rewriteHost: true
|
||||||
|
string:
|
||||||
|
content: aint nothin here
|
||||||
|
headers:
|
||||||
|
content-type: text/plain
|
||||||
|
custom-haha: lol
|
||||||
|
statusCode: 418
|
||||||
listenHTTP: :80
|
listenHTTP: :80
|
||||||
listenHTTPS: :443
|
listenHTTPS: :443
|
||||||
forceHTTPS: true
|
forceHTTPS: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user