Skip to content

Commit

Permalink
🐛 fix 189 upload while filename contains &
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Feb 12, 2022
1 parent 5dca777 commit 387e8af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
7 changes: 6 additions & 1 deletion drivers/189/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ func (driver Cloud189) Link(args base.Args, account *model.Account) (*base.Link,
if err != nil {
return nil, err
}
link := base.Link{}
link := base.Link{
Headers: []base.Header{
{Name: "User-Agent", Value: base.UserAgent},
{Name: "Authorization", Value: ""},
},
}
if res.StatusCode() == 302 {
link.Url = res.Header().Get("location")
} else {
Expand Down
2 changes: 1 addition & 1 deletion drivers/189/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func EncodeParam(v url.Values) string {
}
buf.WriteString(k)
buf.WriteByte('=')
buf.WriteString(v)
buf.WriteString(strings.ReplaceAll(v, "&", "%26"))
}
}
return buf.String()
Expand Down
6 changes: 3 additions & 3 deletions drivers/base/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ func GetDrivers() map[string][]Item {
var NoRedirectClient *resty.Client
var RestyClient = resty.New()
var HttpClient = &http.Client{}
var UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"

func init() {
NoRedirectClient = resty.New().SetRedirectPolicy(
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}),
)
userAgent := "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
NoRedirectClient.SetHeader("user-agent", userAgent)
RestyClient.SetHeader("user-agent", userAgent)
NoRedirectClient.SetHeader("user-agent", UserAgent)
RestyClient.SetHeader("user-agent", UserAgent)
RestyClient.SetRetryCount(3)
}
9 changes: 9 additions & 0 deletions server/controllers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -117,12 +118,14 @@ func Proxy(c *gin.Context) {
common.ErrorResp(c, err, 500)
return
}
log.Debugf("%+v", r.Header)
for h, val := range r.Header {
req.Header[h] = val
}
for _, header := range link.Headers {
req.Header.Set(header.Name, header.Value)
}
log.Debugf("%+v", req.Header)
res, err := HttpClient.Do(req)
if err != nil {
common.ErrorResp(c, err, 500)
Expand All @@ -133,6 +136,12 @@ func Proxy(c *gin.Context) {
}()
log.Debugf("proxy status: %d", res.StatusCode)
w.WriteHeader(res.StatusCode)
if res.StatusCode >= 400 {
all, _ := ioutil.ReadAll(res.Body)
log.Debugln(string(all))
common.ErrorStrResp(c, string(all), 500)
return
}
for h, v := range res.Header {
w.Header()[h] = v
}
Expand Down

0 comments on commit 387e8af

Please sign in to comment.