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

前端 未结 5 824
你的背包
你的背包 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:37

    net/http

    Server requests

    Clarified at 2ede818, net/http states that:

    For server requests, the Request Body is always non-nil but will return EOF immediately when no body is present. The Server will close the request body. The ServeHTTP Handler does not need to.

提交回复
热议问题