Giter Site home page Giter Site logo

Comments (6)

lion3ls avatar lion3ls commented on May 19, 2024

@Zambiorix update your package, everything should work as expected now 😉

from archive_aws-lambda-go-net.

Zambiorix avatar Zambiorix commented on May 19, 2024

:-) great, I'll test it immediately!

Another thing, I believe there is a still a bug in the code:

You should always close a response body if a response is present.
Now you have 2 returns leaving the body open (and the socket unavailable for reuse)

  1. I am aware that even if you have an err on newClient().Do, there are cases you still get a reponse body.
  2. you should immediately close the body after a ioutil.ReadAll(res.Body)

res, err := newClient().Do(req)
if err != nil {
	log.Println(err)
	return
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
	log.Println(err)
	return
}
res.Body.Close()


from archive_aws-lambda-go-net.

Zambiorix avatar Zambiorix commented on May 19, 2024

It's working :-)

I use redirects to test if cookies are allowed by client, and it now works as expected

Thanks!

from archive_aws-lambda-go-net.

Zambiorix avatar Zambiorix commented on May 19, 2024

I would solve the response body closure like this


res, err := newClient().Do(req)
if res != nil {
	defer res.Body.Close()
}
if err != nil {
	log.Println(err)
	return
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
	log.Println(err)
	return
}


from archive_aws-lambda-go-net.

lion3ls avatar lion3ls commented on May 19, 2024

@Zambiorix you're right in the fact that the body should be deferred closed before ReadAll but for the Do function, the general idiom is to defer after checking for errors. See also the commit message. And thank you very much for having reported this problem.

from archive_aws-lambda-go-net.

Zambiorix avatar Zambiorix commented on May 19, 2024

great, thanks!

from archive_aws-lambda-go-net.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.