Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support OnBeforeResponse #747

Open
PeterYangs opened this issue Nov 3, 2023 · 1 comment
Open

support OnBeforeResponse #747

PeterYangs opened this issue Nov 3, 2023 · 1 comment

Comments

@PeterYangs
Copy link

PeterYangs commented Nov 3, 2023

package main

import (
	"errors"
	"github.com/go-resty/resty/v2"
)

func main() {

	client := resty.New()
	
	client.OnBeforeResponse(func(client *resty.Client, response *resty.Response) error {

		if response.Size() > 1073741824 {

			return errors.New("file is too big")
		}

		return nil

	}).R().SetOutput("/path/123.zip").Get("http://www.ooxx.com/123.zip")

}

I want to determine the size of the content before parsing the Response, and throw an error if it exceeds my preset size.

@gospider007
Copy link

gospider007 commented Nov 15, 2023

package main

import (
	"errors"
	"github.com/go-resty/resty/v2"
)

func main() {

	client := resty.New()
	
	client.OnBeforeResponse(func(client *resty.Client, response *resty.Response) error {

		if response.Size() > 1073741824 {

			return errors.New("file is too big")
		}

		return nil

	}).R().SetOutput("/path/123.zip").Get("http://www.ooxx.com/123.zip")

}

I want to determine the size of the content before parsing the Response, and throw an error if it exceeds my preset size.

This can help you https://github.com/gospider007/requests/blob/master/test/middleware/requestCallback_test.go

@jeevatkm jeevatkm added this to the v3.0.0 Milestone milestone Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants