Where to put “defer req.Body.Close()”?

前端 未结 5 820
你的背包
你的背包 2021-01-01 15:25

I have net/http handlers that have defer req.Body.Close() in each on web server side.

What is the correct place to put this in? Should I pu

5条回答
  •  [愿得一人]
    2021-01-01 15:50

    A request body does not need to be closed in the handler. From the http.Request documentation

    // The Server will close the request body. The ServeHTTP
    // Handler does not need to.
    

提交回复
热议问题