diff options
author | Drew DeVault <sir@cmpwn.com> | 2020-11-13 12:45:31 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-11-13 12:45:39 -0500 |
commit | fa102822bb61d612a46d67370ed0619f33fdf4a9 (patch) | |
tree | 92056be1230ad174f92ce7b71f3895f668e0cf17 | |
parent | 2611bee1705dcaf541b5efaa3cf61d344cf1bff1 (diff) | |
download | alps-fa102822bb61d612a46d67370ed0619f33fdf4a9.tar.gz alps-fa102822bb61d612a46d67370ed0619f33fdf4a9.zip |
HTML image proxy: handle missing Content-Length
This is less than ideal, but we still won't end up over-reading because
we're using a LimitedReader here.
-rw-r--r-- | plugins/viewhtml/plugin.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/plugins/viewhtml/plugin.go b/plugins/viewhtml/plugin.go index a121d92..08ffc8c 100644 --- a/plugins/viewhtml/plugin.go +++ b/plugins/viewhtml/plugin.go @@ -58,11 +58,13 @@ func init() { } size, err := strconv.Atoi(resp.Header.Get("Content-Length")) - if err != nil || size > proxyMaxSize { - return echo.NewHTTPError(http.StatusBadRequest, "invalid resource length") + if err == nil { + if size > proxyMaxSize { + return echo.NewHTTPError(http.StatusBadRequest, "invalid resource length") + } + ctx.Response().Header().Set("Content-Length", strconv.Itoa(size)) } - ctx.Response().Header().Set("Content-Length", strconv.Itoa(size)) lr := io.LimitedReader{resp.Body, int64(proxyMaxSize)} return ctx.Stream(http.StatusOK, mediaType, &lr) }) |