mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-02 17:09:48 +02:00
IMG-13: separate http.Headers from ImageData (#1475)
* Separate headers from ImageData * processing.Result
This commit is contained in:
@@ -91,7 +91,7 @@ func (s *ImageDataTestSuite) SetupTest() {
|
||||
}
|
||||
|
||||
func (s *ImageDataTestSuite) TestDownloadStatusOK() {
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(imgdata)
|
||||
@@ -158,7 +158,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusPartialContent() {
|
||||
s.Run(tc.name, func() {
|
||||
s.header.Set("Content-Range", tc.contentRange)
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
@@ -178,7 +178,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusNotFound() {
|
||||
s.data = []byte("Not Found")
|
||||
s.header.Set("Content-Type", "text/plain")
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(404, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -190,7 +190,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusForbidden() {
|
||||
s.data = []byte("Forbidden")
|
||||
s.header.Set("Content-Type", "text/plain")
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(404, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -202,7 +202,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusInternalServerError() {
|
||||
s.data = []byte("Internal Server Error")
|
||||
s.header.Set("Content-Type", "text/plain")
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(500, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -216,7 +216,7 @@ func (s *ImageDataTestSuite) TestDownloadUnreachable() {
|
||||
|
||||
serverURL := fmt.Sprintf("http://%s", l.Addr().String())
|
||||
|
||||
imgdata, err := Download(context.Background(), serverURL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), serverURL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(500, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -226,7 +226,7 @@ func (s *ImageDataTestSuite) TestDownloadUnreachable() {
|
||||
func (s *ImageDataTestSuite) TestDownloadInvalidImage() {
|
||||
s.data = []byte("invalid")
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(422, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -236,7 +236,7 @@ func (s *ImageDataTestSuite) TestDownloadInvalidImage() {
|
||||
func (s *ImageDataTestSuite) TestDownloadSourceAddressNotAllowed() {
|
||||
config.AllowLoopbackSourceAddresses = false
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(404, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -246,7 +246,7 @@ func (s *ImageDataTestSuite) TestDownloadSourceAddressNotAllowed() {
|
||||
func (s *ImageDataTestSuite) TestDownloadImageTooLarge() {
|
||||
config.MaxSrcResolution = 1
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(422, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -256,7 +256,7 @@ func (s *ImageDataTestSuite) TestDownloadImageTooLarge() {
|
||||
func (s *ImageDataTestSuite) TestDownloadImageFileTooLarge() {
|
||||
config.MaxSrcFileSize = 1
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().Error(err)
|
||||
s.Require().Equal(422, ierrors.Wrap(err, 0).StatusCode())
|
||||
@@ -275,7 +275,7 @@ func (s *ImageDataTestSuite) TestDownloadGzip() {
|
||||
s.data = buf.Bytes()
|
||||
s.header.Set("Content-Encoding", "gzip")
|
||||
|
||||
imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
imgdata, _, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(imgdata)
|
||||
|
Reference in New Issue
Block a user