(c *gin.Context, link *model.Link, file model.Obj, proxyRange bool)
| 93 | } |
| 94 | |
| 95 | func proxy(c *gin.Context, link *model.Link, file model.Obj, proxyRange bool) { |
| 96 | defer link.Close() |
| 97 | var err error |
| 98 | if link.URL != "" && setting.GetBool(conf.ForwardDirectLinkParams) { |
| 99 | query := c.Request.URL.Query() |
| 100 | for _, v := range conf.SlicesMap[conf.IgnoreDirectLinkParams] { |
| 101 | query.Del(v) |
| 102 | } |
| 103 | link.URL, err = utils.InjectQuery(link.URL, query) |
| 104 | if err != nil { |
| 105 | common.ErrorPage(c, err, 500) |
| 106 | return |
| 107 | } |
| 108 | } |
| 109 | if proxyRange { |
| 110 | link = common.ProxyRange(c, link, file.GetSize()) |
| 111 | } |
| 112 | Writer := &common.WrittenResponseWriter{ResponseWriter: c.Writer} |
| 113 | err = common.Proxy(Writer, c.Request, link, file) |
| 114 | if err == nil { |
| 115 | return |
| 116 | } |
| 117 | if Writer.IsWritten() { |
| 118 | log.Errorf("%s %s local proxy error: %+v", c.Request.Method, c.Request.URL.Path, err) |
| 119 | } else { |
| 120 | if statusCode, ok := errs.UnwrapOrSelf(err).(net.HttpStatusCodeError); ok { |
| 121 | common.ErrorPage(c, err, int(statusCode), true) |
| 122 | } else { |
| 123 | common.ErrorPage(c, err, 500, true) |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // TODO need optimize |
| 129 | // when can be proxy? |
no test coverage detected