Skip to content

Commit 46eb2c5

Browse files
authoredJul 26, 2023
Merge pull request #7 from metalice/adding-defer-close
Adding defer functions
2 parents ff6ed97 + 588267e commit 46eb2c5

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
 

‎handlers/handlers.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var PROTOCOL string = "https"
1616
var ORIGIN = "http://localhost"
1717

1818
func HealthHandler(c *gin.Context) {
19+
defer c.Request.Body.Close()
1920
c.String(200, "OK")
2021
}
2122

@@ -40,7 +41,7 @@ func RequestHandler(c *gin.Context) {
4041

4142
c.Request.Header.Set("Origin", ORIGIN)
4243
c.Request.Header.Set("Accept-Encoding", "*")
43-
44+
defer c.Request.Body.Close()
4445
if c.IsWebsocket() {
4546
proxy.ServeHTTP(c.Writer, c.Request)
4647
return

‎proxy/proxy.go

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
114114
var writeMutex sync.Mutex // Needed because ticker & copy are writing to frontend in separate goroutines
115115

116116
defer func() {
117+
resp.Body.Close()
117118
backend.Close()
118119
frontend.Close()
119120
}()

0 commit comments

Comments
 (0)
Please sign in to comment.