mirror of https://github.com/v2ray/v2ray-core
simplify http header parsing
parent
f108633e2e
commit
31be091a55
|
@ -1,10 +1,8 @@
|
||||||
package conf
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
"v2ray.com/core/common/loader"
|
"v2ray.com/core/common/loader"
|
||||||
"v2ray.com/core/transport/internet/authenticators/http"
|
"v2ray.com/core/transport/internet/authenticators/http"
|
||||||
"v2ray.com/core/transport/internet/authenticators/noop"
|
"v2ray.com/core/transport/internet/authenticators/noop"
|
||||||
|
@ -132,41 +130,27 @@ func (this *HTTPAuthenticatorResponse) Build() (*http.ResponseConfig, error) {
|
||||||
|
|
||||||
type HTTPAuthenticator struct {
|
type HTTPAuthenticator struct {
|
||||||
Request *HTTPAuthenticatorRequest `json:"request"`
|
Request *HTTPAuthenticatorRequest `json:"request"`
|
||||||
Response json.RawMessage `json:"response"`
|
Response *HTTPAuthenticatorResponse `json:"response"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *HTTPAuthenticator) Build() (*loader.TypedSettings, error) {
|
func (this *HTTPAuthenticator) Build() (*loader.TypedSettings, error) {
|
||||||
config := new(http.Config)
|
config := new(http.Config)
|
||||||
if this.Request != nil {
|
if this.Request == nil {
|
||||||
|
return nil, errors.New("HTTP request settings not set.")
|
||||||
|
}
|
||||||
requestConfig, err := this.Request.Build()
|
requestConfig, err := this.Request.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.Request = requestConfig
|
config.Request = requestConfig
|
||||||
}
|
|
||||||
|
|
||||||
if len(this.Response) > 0 {
|
if this.Response != nil {
|
||||||
var text string
|
responseConfig, err := this.Response.Build()
|
||||||
parsed := false
|
|
||||||
if err := json.Unmarshal(this.Response, &text); err == nil {
|
|
||||||
if strings.ToLower(text) != "disabled" {
|
|
||||||
return nil, errors.New("Unknown HTTP header settings: " + text)
|
|
||||||
}
|
|
||||||
parsed = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !parsed {
|
|
||||||
var response HTTPAuthenticatorResponse
|
|
||||||
if err := json.Unmarshal(this.Response, &response); err != nil {
|
|
||||||
return nil, errors.New("Failed to parse HTTP header response.")
|
|
||||||
}
|
|
||||||
responseConfig, err := response.Build()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.Response = responseConfig
|
config.Response = responseConfig
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return loader.NewTypedSettings(config), nil
|
return loader.NewTypedSettings(config), nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue