mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-15 05:03:20 +00:00
33daa0c94b
Testing was conducted only using explicit parameters, and using testsuite. However, when the parameters are not explicitly set in JSON config, it seems that `c.MaxUploadSize` will contain `RandRangeConfig { From: 0, To: 0 }` instead of `nil`, which breaks upload entirely.
99 lines
1.9 KiB
Go
99 lines
1.9 KiB
Go
package splithttp
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
)
|
|
|
|
func (c *Config) GetNormalizedPath(addPath string, addQuery bool) string {
|
|
pathAndQuery := strings.SplitN(c.Path, "?", 2)
|
|
path := pathAndQuery[0]
|
|
query := ""
|
|
if len(pathAndQuery) > 1 && addQuery {
|
|
query = "?" + pathAndQuery[1]
|
|
}
|
|
|
|
if path == "" || path[0] != '/' {
|
|
path = "/" + path
|
|
}
|
|
if path[len(path)-1] != '/' {
|
|
path = path + "/"
|
|
}
|
|
|
|
return path + addPath + query
|
|
}
|
|
|
|
func (c *Config) GetRequestHeader() http.Header {
|
|
header := http.Header{}
|
|
for k, v := range c.Header {
|
|
header.Add(k, v)
|
|
}
|
|
return header
|
|
}
|
|
|
|
func (c *Config) GetNormalizedMaxConcurrentUploads(isServer bool) RandRangeConfig {
|
|
if c.MaxConcurrentUploads == nil || c.MaxConcurrentUploads.To == 0 {
|
|
if isServer {
|
|
return RandRangeConfig{
|
|
From: 200,
|
|
To: 200,
|
|
}
|
|
} else {
|
|
return RandRangeConfig{
|
|
From: 100,
|
|
To: 100,
|
|
}
|
|
}
|
|
}
|
|
|
|
return *c.MaxConcurrentUploads
|
|
}
|
|
|
|
func (c *Config) GetNormalizedMaxUploadSize(isServer bool) RandRangeConfig {
|
|
if c.MaxUploadSize == nil || c.MaxUploadSize.To == 0 {
|
|
if isServer {
|
|
return RandRangeConfig{
|
|
From: 2000000,
|
|
To: 2000000,
|
|
}
|
|
} else {
|
|
return RandRangeConfig{
|
|
From: 1000000,
|
|
To: 1000000,
|
|
}
|
|
}
|
|
}
|
|
|
|
return *c.MaxUploadSize
|
|
}
|
|
|
|
func (c *Config) GetNormalizedMinUploadInterval() RandRangeConfig {
|
|
if c.MinUploadIntervalMs == nil || c.MinUploadIntervalMs.To == 0 {
|
|
return RandRangeConfig{
|
|
From: 30,
|
|
To: 30,
|
|
}
|
|
}
|
|
|
|
return *c.MinUploadIntervalMs
|
|
}
|
|
|
|
func init() {
|
|
common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
|
|
return new(Config)
|
|
}))
|
|
}
|
|
|
|
func (c RandRangeConfig) roll() int32 {
|
|
if c.From == c.To {
|
|
return c.From
|
|
}
|
|
bigInt, _ := rand.Int(rand.Reader, big.NewInt(int64(c.To-c.From)))
|
|
return c.From + int32(bigInt.Int64())
|
|
}
|