1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-18 01:46:06 -04:00
v2fly/transport/internet/authenticators/http/config.go

97 lines
1.7 KiB
Go
Raw Normal View History

2016-10-31 17:26:46 -04:00
package http
import (
2016-11-06 07:38:32 -05:00
"strings"
2016-10-31 17:26:46 -04:00
"v2ray.com/core/common/dice"
)
2016-11-02 17:26:21 -04:00
func (this *Version) GetValue() string {
if this == nil {
return "1.1"
}
return this.Value
}
func (this *Method) GetValue() string {
if this == nil {
return "GET"
}
return this.Value
}
func (this *Status) GetCode() string {
if this == nil {
return "200"
}
return this.Code
}
func (this *Status) GetReason() string {
if this == nil {
return "OK"
}
return this.Reason
}
2016-10-31 17:26:46 -04:00
func pickString(arr []string) string {
n := len(arr)
2016-11-06 08:04:44 -05:00
switch n {
case 0:
2016-10-31 17:26:46 -04:00
return ""
2016-11-06 08:04:44 -05:00
case 1:
return arr[0]
default:
return arr[dice.Roll(n)]
2016-10-31 17:26:46 -04:00
}
}
func (this *RequestConfig) PickUri() string {
return pickString(this.Uri)
}
func (this *RequestConfig) PickHeaders() []string {
n := len(this.Header)
if n == 0 {
return nil
}
headers := make([]string, n)
for idx, headerConfig := range this.Header {
headerName := headerConfig.Name
headerValue := pickString(headerConfig.Value)
headers[idx] = headerName + ": " + headerValue
}
return headers
}
2016-11-02 17:26:21 -04:00
func (this *RequestConfig) GetFullVersion() string {
return "HTTP/" + this.Version.GetValue()
2016-10-31 17:26:46 -04:00
}
2016-11-06 07:38:32 -05:00
func (this *ResponseConfig) HasHeader(header string) bool {
cHeader := strings.ToLower(header)
for _, tHeader := range this.Header {
if strings.ToLower(tHeader.Name) == cHeader {
return true
}
}
return false
}
2016-10-31 17:26:46 -04:00
func (this *ResponseConfig) PickHeaders() []string {
n := len(this.Header)
if n == 0 {
return nil
}
headers := make([]string, n)
for idx, headerConfig := range this.Header {
headerName := headerConfig.Name
headerValue := pickString(headerConfig.Value)
headers[idx] = headerName + ": " + headerValue
}
return headers
}
2016-11-02 17:26:21 -04:00
func (this *ResponseConfig) GetFullVersion() string {
return "HTTP/" + this.Version.GetValue()
2016-10-31 17:26:46 -04:00
}