mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
SplitHTTP: More range options, change defaults, enforce maxUploadSize, fix querystring behavior (#3603)
* maxUploadSize and maxConcurrentUploads can now be ranges on the client * maxUploadSize is now enforced on the server * the default of maxUploadSize is 2MB on the server, and 1MB on the client * the default of maxConcurrentUploads is 200 on the server, and 100 on the client * ranges on the server are treated as a single number. if server is configured as `"1-2"`, server will enforce `2` * querystrings in `path` are now handled correctly
This commit is contained in:
parent
4cb2a128db
commit
59f6685774
8 changed files with 223 additions and 82 deletions
|
@ -4,23 +4,28 @@ 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() string {
|
||||
path := c.Path
|
||||
if path == "" {
|
||||
path = "/"
|
||||
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[0] != '/' {
|
||||
|
||||
if path == "" || path[0] != '/' {
|
||||
path = "/" + path
|
||||
}
|
||||
if path[len(path)-1] != '/' {
|
||||
path = path + "/"
|
||||
}
|
||||
return path
|
||||
|
||||
return path + addPath + query
|
||||
}
|
||||
|
||||
func (c *Config) GetRequestHeader() http.Header {
|
||||
|
@ -31,33 +36,51 @@ func (c *Config) GetRequestHeader() http.Header {
|
|||
return header
|
||||
}
|
||||
|
||||
func (c *Config) GetNormalizedMaxConcurrentUploads() int32 {
|
||||
if c.MaxConcurrentUploads == 0 {
|
||||
return 10
|
||||
func (c *Config) GetNormalizedMaxConcurrentUploads(isServer bool) RandRangeConfig {
|
||||
if c.MaxConcurrentUploads == nil {
|
||||
if isServer {
|
||||
return RandRangeConfig{
|
||||
From: 200,
|
||||
To: 200,
|
||||
}
|
||||
} else {
|
||||
return RandRangeConfig{
|
||||
From: 100,
|
||||
To: 100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.MaxConcurrentUploads
|
||||
return *c.MaxConcurrentUploads
|
||||
}
|
||||
|
||||
func (c *Config) GetNormalizedMaxUploadSize() int32 {
|
||||
if c.MaxUploadSize == 0 {
|
||||
return 1000000
|
||||
func (c *Config) GetNormalizedMaxUploadSize(isServer bool) RandRangeConfig {
|
||||
if c.MaxUploadSize == nil {
|
||||
if isServer {
|
||||
return RandRangeConfig{
|
||||
From: 2000000,
|
||||
To: 2000000,
|
||||
}
|
||||
} else {
|
||||
return RandRangeConfig{
|
||||
From: 1000000,
|
||||
To: 1000000,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.MaxUploadSize
|
||||
return *c.MaxUploadSize
|
||||
}
|
||||
|
||||
func (c *Config) GetNormalizedMinUploadInterval() RandRangeConfig {
|
||||
r := c.MinUploadIntervalMs
|
||||
|
||||
if r == nil {
|
||||
r = &RandRangeConfig{
|
||||
if c.MinUploadIntervalMs == nil {
|
||||
return RandRangeConfig{
|
||||
From: 30,
|
||||
To: 30,
|
||||
}
|
||||
}
|
||||
|
||||
return *r
|
||||
return *c.MinUploadIntervalMs
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue