@@ -26,11 +26,6 @@ type OpenList struct {
2626}
2727
2828func (d * OpenList ) Config () driver.Config {
29- if d .PassUAToUpsteam {
30- c := config
31- c .LinkCacheType = 2 // add User-Agent to cache key
32- return c
33- }
3429 return config
3530}
3631
@@ -115,19 +110,29 @@ func (d *OpenList) List(ctx context.Context, dir model.Obj, args model.ListArgs)
115110
116111func (d * OpenList ) Link (ctx context.Context , file model.Obj , args model.LinkArgs ) (* model.Link , error ) {
117112 var resp common.Resp [FsGetResp ]
113+ headers := map [string ]string {
114+ "User-Agent" : base .UserAgent ,
115+ }
118116 // if PassUAToUpsteam is true, then pass the user-agent to the upstream
119- userAgent := base .UserAgent
120117 if d .PassUAToUpsteam {
121- userAgent = args .Header .Get ("user-agent" )
122- if userAgent == "" {
123- userAgent = base .UserAgent
118+ userAgent := args .Header .Get ("user-agent" )
119+ if userAgent != "" {
120+ headers ["User-Agent" ] = base .UserAgent
121+ }
122+ }
123+ // if PassIPToUpsteam is true, then pass the ip address to the upstream
124+ if d .PassIPToUpsteam {
125+ ip := args .IP
126+ if ip != "" {
127+ headers ["X-Forwarded-For" ] = ip
128+ headers ["X-Real-Ip" ] = ip
124129 }
125130 }
126131 _ , _ , err := d .request ("/fs/get" , http .MethodPost , func (req * resty.Request ) {
127132 req .SetResult (& resp ).SetBody (FsGetReq {
128133 Path : file .GetPath (),
129134 Password : d .MetaPassword ,
130- }).SetHeader ( "user-agent" , userAgent )
135+ }).SetHeaders ( headers )
131136 })
132137 if err != nil {
133138 return nil , err
@@ -360,8 +365,15 @@ func (d *OpenList) ArchiveDecompress(ctx context.Context, srcObj, dstDir model.O
360365 return err
361366}
362367
363- //func (d *OpenList) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
364- // return nil, errs.NotSupport
365- //}
368+ func (d * OpenList ) ResolveLinkCacheMode (_ string ) driver.LinkCacheMode {
369+ var mode driver.LinkCacheMode
370+ if d .PassIPToUpsteam {
371+ mode |= driver .LinkCacheIP
372+ }
373+ if d .PassUAToUpsteam {
374+ mode |= driver .LinkCacheUA
375+ }
376+ return mode
377+ }
366378
367379var _ driver.Driver = (* OpenList )(nil )
0 commit comments