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.
This commit is contained in:
parent
2611bee170
commit
fa102822bb
|
@ -58,11 +58,13 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
size, err := strconv.Atoi(resp.Header.Get("Content-Length"))
|
size, err := strconv.Atoi(resp.Header.Get("Content-Length"))
|
||||||
if err != nil || size > proxyMaxSize {
|
if err == nil {
|
||||||
|
if size > proxyMaxSize {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "invalid resource length")
|
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)}
|
lr := io.LimitedReader{resp.Body, int64(proxyMaxSize)}
|
||||||
return ctx.Stream(http.StatusOK, mediaType, &lr)
|
return ctx.Stream(http.StatusOK, mediaType, &lr)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue