mirror of https://github.com/cloudreve/Cloudreve
fix(s3): avoid perform URL encoding for proxyed path again if possible (#2413)
parent
51fa9f66a5
commit
c13b7365b0
|
@ -2,10 +2,11 @@ package driver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cloudreve/Cloudreve/v4/ent"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cloudreve/Cloudreve/v4/ent"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ApplyProxyIfNeeded(policy *ent.StoragePolicy, srcUrl *url.URL) (*url.URL, error) {
|
func ApplyProxyIfNeeded(policy *ent.StoragePolicy, srcUrl *url.URL) (*url.URL, error) {
|
||||||
|
@ -16,7 +17,12 @@ func ApplyProxyIfNeeded(policy *ent.StoragePolicy, srcUrl *url.URL) (*url.URL, e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse proxy URL: %w", err)
|
return nil, fmt.Errorf("failed to parse proxy URL: %w", err)
|
||||||
}
|
}
|
||||||
proxy.Path = path.Join(proxy.Path, strings.TrimPrefix(srcUrl.Path, "/"))
|
if proxy.Path != "" && proxy.Path != "/" {
|
||||||
|
proxy.Path = path.Join(proxy.Path, strings.TrimPrefix(srcUrl.Path, "/"))
|
||||||
|
} else {
|
||||||
|
proxy.RawPath = srcUrl.RawPath
|
||||||
|
proxy.Path = srcUrl.Path
|
||||||
|
}
|
||||||
q := proxy.Query()
|
q := proxy.Query()
|
||||||
if len(q) == 0 {
|
if len(q) == 0 {
|
||||||
proxy.RawQuery = srcUrl.RawQuery
|
proxy.RawQuery = srcUrl.RawQuery
|
||||||
|
|
Loading…
Reference in New Issue