Comments (6)
@Zambiorix update your package, everything should work as expected now 😉
from archive_aws-lambda-go-net.
:-) 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)
- I am aware that even if you have an err on newClient().Do, there are cases you still get a reponse body.
- 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.
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.
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.
@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.
great, thanks!
from archive_aws-lambda-go-net.
Related Issues (9)
- Why init not main? HOT 3
- Cut a release? HOT 2
- Possibly obvious question about concurrency of the server HOT 4
- api badge points to confusing place HOT 2
- Crashes with the latest shim version HOT 7
- http.DetectContentType fails to detect posted JPEG upon lambda HOT 1
- 'Process exited before completing request' HOT 7
- Why listen and serve instead of handling requests in-memory? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from archive_aws-lambda-go-net.