{"id":127973,"date":"2020-06-12T03:19:52","date_gmt":"2020-06-11T19:19:52","guid":{"rendered":"http:\/\/4563.org\/?p=127973"},"modified":"2020-06-12T03:19:52","modified_gmt":"2020-06-11T19:19:52","slug":"golang-body-close-%e7%9a%84%e9%bb%98%e8%ae%a4%e8%a1%8c%e4%b8%ba%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=127973","title":{"rendered":"golang body.close \u7684\u9ed8\u8ba4\u884c\u4e3a\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  golang body.close \u7684\u9ed8\u8ba4\u884c\u4e3a\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vevlins <\/span>  <span><i><\/i> 58<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u524d\u63d0\u662f\u590d\u7528 http \u94fe\u63a5\uff0c\u91c7\u7528 stream \u8bfb\u6cd5\u3002<\/p>\n<p>\u91c7\u7528 stream \u8bfb\u6cd5\u5e76\u4e0d\u8bfb\u5b8c\u8fd9\u4e2a\u94fe\u63a5\u7684 body\uff0c\u6bd4\u5982\u6574\u4e2a\u8bf7\u6c42\u662f 1M\uff0c\u53ea\u8bfb\u4e86 1k\uff0c\u8fd9\u65f6\u5019 close\uff0c\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f<\/p>\n<p>\u662f\u4f1a\u8bfb\u5b8c\u5b8c\u6574\u7684 1M \u518d\u653e\u56de\u5230 http \u590d\u7528\u6c60\u4e2d\u8fd8\u662f\u8bfb tcp \u7f13\u51b2\u533a\u7684\u5927\u5c0f\uff1f\u56e0\u4e3a\u4ece golang net\/http\/transfer.go \u4e2d\u770b\u662f\u8bfb\u4e86 maxPostHandlerReadBytes \u7684\u957f\u5ea6\u3002\u4f46\u662f\u81ea\u5df1\u7406\u89e3\u4e0d\u4e86\uff0c\u7f13\u51b2\u533a\u8bfb\u5b8c\u540e\u670d\u52a1\u7aef\u56e0\u4e3a\u6ed1\u52a8\u7a97\u53e3\u4e0d\u662f\u4f1a\u7ee7\u7eed\u53d1\u9001\u4e4b\u524d\u963b\u585e\u7684\u6570\u636e\u5417\uff0c\u8fd9\u6837\u53c8\u4e0d\u662f\u53ef\u7528\u72b6\u6001\u4e86\u3002<\/p>\n<p>maxPostHandlerReadBytes is the max number of Request.Body bytes not consumed by a handler that the server will read from the client in order to keep a connection alive. If there are more bytes than this then the server to be paranoid instead sends a &#8220;Connection: close&#8221; response.<\/p>\n<p>This number is approximately what a typical machine&#8217;s TCP buffer size is anyway. (if we have the bytes on the machine, we might as well read them)<\/p>\n<p>\u4e0a\u9762\u8fd9\u6bb5\u8bdd\u8be5\u5982\u4f55\u7406\u89e3\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"34151\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : vevlins <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0a\u9762\u4e00\u6bb5\u8bdd\u7684\u542b\u4e49\u662f\u5426\u662f\u5982\u679c\u8bfb\u5b8c\u7f13\u51b2\u533a\u8fd8\u6709\u5185\u5bb9\uff0c\u5c31\u5f03\u7528\u8fd9\u4e2a\u8fde\u63a5\uff0c\u53d1\u9001\u4e00\u4e2a connection:close \u7684\u5305\u544a\u8bc9\u670d\u52a1\u5668\u65ad\u5f00\u94fe\u63a5\u3002 \u8fd9\u4e2a\u201cconnection:close\u201d\u662f\u5ba2\u6237\u7aef\u76f4\u63a5\u53d1\u9001\u4e00\u4e2a fin\uff0c\u7136\u540e\u4ece\u8fde\u63a5\u6c60\u53bb\u6389\u5417\uff1f\u8fd8\u662f\u5bf9\u5e94\u4ec0\u4e48\u64cd\u4f5c\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>golang body.close&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127973"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127973"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127973\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127973"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}