Skip to content

Fix gows #2

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

Merged
merged 5 commits into from
Feb 5, 2022
Merged

Fix gows #2

merged 5 commits into from
Feb 5, 2022

Conversation

mattn
Copy link
Contributor

@mattn mattn commented Feb 5, 2022

  • do not need to close req.Body manually. It will close by server.
  • use atomic.AddInt32 since it may be race condition
  • return error if the file can not be read.

The third change might make gows be slowly but other languages possibly handle exception. So gows have to check the error for the fair.

// add 2 second delay to every 10th request
if (count % 10) == 0 {
println("Adding delay. Count: ", count)
time.Sleep(2 * time.Second)
}
html, _ := ioutil.ReadFile("hello.html") // read html file
w.Header().Add("Connection", "keep-alive")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the header removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net/http set this header automatically if client sent Connection: keep-alive. So you don't need to do.

defer r.Body.Close()
count++
handleConnection(w, count)
handleConnection(w, atomic.AddInt32(&count, 1))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, got too used to Rust these days :P

@deepu105
Copy link
Owner

deepu105 commented Feb 5, 2022

Thanks for this 🙏 I added a comment

@deepu105 deepu105 merged commit 61b6eb7 into deepu105:main Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants