{"id":60893,"date":"2026-01-16T15:25:42","date_gmt":"2026-01-16T07:25:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/60893.html"},"modified":"2026-01-16T15:25:42","modified_gmt":"2026-01-16T07:25:42","slug":"http-%e7%8a%b6%e6%80%81%e7%a0%81%ef%bc%9a%e5%ae%a2%e6%88%b7%e7%ab%af%e4%b8%8e%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e9%80%9a%e4%bf%a1%e8%af%ad%e8%a8%80-%e7%ac%ac%e4%b8%80%e9%83%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/60893.html","title":{"rendered":"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba"},"content":{"rendered":"<h3><\/h3>\n<h3>\u7b2c1\u7ae0&#xff1a;HTTP\u534f\u8bae\u4e0e\u72b6\u6001\u7801\u6982\u8ff0<\/h3>\n<h4>1.1 HTTP\u534f\u8bae\u7684\u57fa\u672c\u6a21\u578b<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1746\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072537-6969e7f1b79a3.png\" width=\"958\" \/><\/h4>\n<h5>HTTP\u534f\u8bae\u7684\u6f14\u8fdb\u5386\u7a0b<\/h5>\n<p>HTTP&#xff08;HyperText Transfer Protocol&#xff09;\u534f\u8bae\u81ea1990\u5e74\u8bde\u751f\u4ee5\u6765&#xff0c;\u5df2\u7ecf\u7ecf\u5386\u4e86\u591a\u4e2a\u7248\u672c\u7684\u6f14\u8fdb\u3002\u5176\u57fa\u672c\u6a21\u578b\u59cb\u7ec8\u4fdd\u6301\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784&#xff0c;\u4f46\u5b9e\u73b0\u7ec6\u8282\u548c\u6027\u80fd\u7279\u6027\u6709\u4e86\u663e\u8457\u6539\u8fdb\u3002<\/p>\n<p>HTTP\u4e8b\u52a1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;<\/p>\n<h5>HTTP\u6d88\u606f\u7ed3\u6784\u8be6\u89e3<\/h5>\n<p>HTTP\u6d88\u606f\u7531\u8d77\u59cb\u884c\u3001\u5934\u90e8\u5b57\u6bb5\u548c\u6d88\u606f\u4f53\u4e09\u90e8\u5206\u7ec4\u6210\u3002\u5bf9\u4e8e\u72b6\u6001\u7801&#xff0c;\u5b83\u4f4d\u4e8e\u54cd\u5e94\u6d88\u606f\u7684\u8d77\u59cb\u884c\u4e2d\u3002<\/p>\n<p>\u8bf7\u6c42\u6d88\u606f\u683c\u5f0f&#xff1a;<\/p>\n<p>http<\/p>\n<p>GET \/index.html HTTP\/1.1          \u2190 \u8bf7\u6c42\u884c<br \/>\nHost: www.example.com             \u2190 \u8bf7\u6c42\u5934\u90e8\u5f00\u59cb<br \/>\nUser-Agent: Mozilla\/5.0<br \/>\nAccept: text\/html,application\/xhtml&#043;xml<br \/>\nAccept-Language: en-US,en;q&#061;0.5<br \/>\nAccept-Encoding: gzip, deflate<br \/>\nConnection: keep-alive            \u2190 \u8bf7\u6c42\u5934\u90e8\u7ed3\u675f<br \/>\n                                   \u2190 \u7a7a\u884c\u5206\u9694<br \/>\n                                   \u2190 \u8bf7\u6c42\u4f53&#xff08;GET\u65e0\u8bf7\u6c42\u4f53&#xff09;<\/p>\n<p>\u54cd\u5e94\u6d88\u606f\u683c\u5f0f&#xff1a;<\/p>\n<p>http<\/p>\n<p>HTTP\/1.1 200 OK                   \u2190 \u72b6\u6001\u884c&#xff08;\u5305\u542b\u72b6\u6001\u7801&#xff09;<br \/>\nDate: Mon, 23 Jan 2023 10:30:45 GMT<br \/>\nServer: Apache\/2.4.41<br \/>\nLast-Modified: Mon, 16 Jan 2023 14:28:00 GMT<br \/>\nContent-Type: text\/html; charset&#061;utf-8<br \/>\nContent-Length: 1234              \u2190 \u54cd\u5e94\u5934\u90e8\u7ed3\u675f<br \/>\n                                   \u2190 \u7a7a\u884c\u5206\u9694<br \/>\n&lt;!DOCTYPE html&gt;                   \u2190 \u54cd\u5e94\u4f53\u5f00\u59cb<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;&lt;title&gt;Example&lt;\/title&gt;&lt;\/head&gt;<br \/>\n&lt;body&gt;&#8230;&lt;\/body&gt;<br \/>\n&lt;\/html&gt;                           \u2190 \u54cd\u5e94\u4f53\u7ed3\u675f<\/p>\n<h4>1.2 \u72b6\u6001\u7801\u7684\u5b9a\u4e49\u4e0e\u4f5c\u7528<\/h4>\n<h5>\u72b6\u6001\u7801\u7684\u6838\u5fc3\u4ef7\u503c<\/h5>\n<p>\u72b6\u6001\u7801\u4e0d\u4ec5\u4ec5\u662f\u7b80\u5355\u7684\u6570\u5b57&#xff0c;\u5b83\u627f\u8f7d\u7740\u4e30\u5bcc\u7684\u8bed\u4e49\u4fe1\u606f&#xff0c;\u662f\u5b9e\u73b0\u53ef\u9760Web\u901a\u4fe1\u7684\u57fa\u77f3\u3002<\/p>\n<p>1. \u901a\u4fe1\u72b6\u6001\u6307\u793a\u5668<\/p>\n<ul>\n<li>\n<p>\u5373\u65f6\u53cd\u9988&#xff1a;\u5ba2\u6237\u7aef\u5728\u6536\u5230\u54cd\u5e94\u540e\u80fd\u7acb\u5373\u77e5\u9053\u8bf7\u6c42\u5904\u7406\u7ed3\u679c<\/p>\n<\/li>\n<li>\n<p>\u51b3\u7b56\u4f9d\u636e&#xff1a;\u5ba2\u6237\u7aef\u6839\u636e\u72b6\u6001\u7801\u51b3\u5b9a\u4e0b\u4e00\u6b65\u64cd\u4f5c&#xff08;\u91cd\u8bd5\u3001\u91cd\u5b9a\u5411\u3001\u663e\u793a\u9519\u8bef\u7b49&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u534f\u8bae\u534f\u8c03&#xff1a;\u534f\u8c03\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u4ea4\u4e92\u6d41\u7a0b<\/p>\n<\/li>\n<\/ul>\n<p>2. \u9519\u8bef\u8bca\u65ad\u4e0e\u5206\u7c7b\u7cfb\u7edf<\/p>\n<ul>\n<li>\n<p>\u95ee\u9898\u5b9a\u4f4d&#xff1a;\u5feb\u901f\u8bc6\u522b\u95ee\u9898\u662f\u5ba2\u6237\u7aef\u8fd8\u662f\u670d\u52a1\u5668\u7aef<\/p>\n<\/li>\n<li>\n<p>\u5206\u7c7b\u5904\u7406&#xff1a;\u5c06\u9519\u8bef\u5206\u4e3a\u8bed\u6cd5\u3001\u6743\u9650\u3001\u8d44\u6e90\u3001\u670d\u52a1\u5668\u7b49\u7c7b\u522b<\/p>\n<\/li>\n<li>\n<p>\u8c03\u8bd5\u8f85\u52a9&#xff1a;\u4e3a\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\u660e\u786e\u7684\u9519\u8bef\u7ebf\u7d22<\/p>\n<\/li>\n<\/ul>\n<p>3. \u6d41\u7a0b\u63a7\u5236\u673a\u5236<\/p>\n<ul>\n<li>\n<p>\u91cd\u5b9a\u5411\u63a7\u5236&#xff1a;301\/302\/307\/308\u6307\u5bfc\u5ba2\u6237\u7aef\u8bbf\u95ee\u65b0\u4f4d\u7f6e<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u7b56\u7565&#xff1a;304\/200\u7b49\u72b6\u6001\u7801\u4e0e\u7f13\u5b58\u5934\u90e8\u914d\u5408\u63a7\u5236\u7f13\u5b58\u884c\u4e3a<\/p>\n<\/li>\n<li>\n<p>\u8eab\u4efd\u9a8c\u8bc1\u6d41\u7a0b&#xff1a;401\u89e6\u53d1\u8ba4\u8bc1&#xff0c;403\u62d2\u7edd\u8bbf\u95ee<\/p>\n<\/li>\n<\/ul>\n<p>4. \u7cfb\u7edf\u76d1\u63a7\u6307\u6807<\/p>\n<ul>\n<li>\n<p>\u5065\u5eb7\u68c0\u67e5&#xff1a;\u72b6\u6001\u7801\u5206\u5e03\u53cd\u6620\u7cfb\u7edf\u5065\u5eb7\u72b6\u51b5<\/p>\n<\/li>\n<li>\n<p>\u6027\u80fd\u76d1\u63a7&#xff1a;4xx\/5xx\u6bd4\u4f8b\u6307\u793a\u7cfb\u7edf\u53ef\u9760\u6027<\/p>\n<\/li>\n<li>\n<p>\u5b89\u5168\u76d1\u63a7&#xff1a;\u5f02\u5e38\u72b6\u6001\u7801\u6a21\u5f0f\u53ef\u80fd\u6307\u793a\u653b\u51fb\u884c\u4e3a<\/p>\n<\/li>\n<\/ul>\n<h5>\u72b6\u6001\u7801\u7684\u5c42\u6b21\u5316\u8bed\u4e49<\/h5>\n<p>\u72b6\u6001\u7801\u7684\u8bbe\u8ba1\u91c7\u7528\u5c42\u6b21\u5316\u8bed\u4e49\u6a21\u578b&#xff1a;<\/p>\n<p>text<\/p>\n<p>\u72b6\u6001\u7801\u8bed\u4e49\u5c42\u6b21<br \/>\n\u251c\u2500\u2500 \u7c7b\u522b\u5c42&#xff08;\u7b2c\u4e00\u4f4d\u6570\u5b57&#xff09;<br \/>\n\u2502   \u251c\u2500\u2500 1xx&#xff1a;\u4fe1\u606f\u6027 &#8211; \u534f\u8bae\u7ea7\u5904\u7406\u72b6\u6001<br \/>\n\u2502   \u251c\u2500\u2500 2xx&#xff1a;\u6210\u529f &#8211; \u4e1a\u52a1\u64cd\u4f5c\u5b8c\u6210<br \/>\n\u2502   \u251c\u2500\u2500 3xx&#xff1a;\u91cd\u5b9a\u5411 &#8211; \u8d44\u6e90\u4f4d\u7f6e\u53d8\u66f4<br \/>\n\u2502   \u251c\u2500\u2500 4xx&#xff1a;\u5ba2\u6237\u7aef\u9519\u8bef &#8211; \u8bf7\u6c42\u6709\u95ee\u9898<br \/>\n\u2502   \u2514\u2500\u2500 5xx&#xff1a;\u670d\u52a1\u5668\u9519\u8bef &#8211; \u5904\u7406\u5931\u8d25<br \/>\n\u2502<br \/>\n\u251c\u2500\u2500 \u5b50\u7c7b\u5c42&#xff08;\u7b2c\u4e8c\u4f4d\u6570\u5b57&#xff09;<br \/>\n\u2502   \u251c\u2500\u2500 x0x&#xff1a;\u901a\u7528\u7c7b\u522b<br \/>\n\u2502   \u251c\u2500\u2500 x1x&#xff1a;\u5b9e\u9a8c\u6027\/\u6269\u5c55<br \/>\n\u2502   \u251c\u2500\u2500 x2x&#xff1a;\u6210\u529f\u7279\u5b9a\u573a\u666f<br \/>\n\u2502   \u251c\u2500\u2500 x3x&#xff1a;\u7f13\u5b58\u76f8\u5173<br \/>\n\u2502   \u251c\u2500\u2500 x4x&#xff1a;\u8bed\u6cd5\/\u683c\u5f0f\u9519\u8bef<br \/>\n\u2502   \u251c\u2500\u2500 x5x&#xff1a;\u670d\u52a1\u5668\u914d\u7f6e\u9519\u8bef<br \/>\n\u2502   \u2514\u2500\u2500 x6x-x9x&#xff1a;\u9884\u7559\u6269\u5c55<br \/>\n\u2502<br \/>\n\u2514\u2500\u2500 \u5177\u4f53\u7801\u5c42&#xff08;\u7b2c\u4e09\u4f4d\u6570\u5b57&#xff09;<br \/>\n    \u2514\u2500\u2500 0-9&#xff1a;\u7279\u5b9a\u573a\u666f\u7ec6\u5316<\/p>\n<h4>1.3 \u72b6\u6001\u7801\u7684\u683c\u5f0f\u89c4\u8303<\/h4>\n<h5>RFC\u6807\u51c6\u5b9a\u4e49<\/h5>\n<p>\u6839\u636eRFC 7231\u7b2c6\u8282&#xff0c;\u72b6\u6001\u7801\u7684\u6b63\u5f0f\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>abnf<\/p>\n<p>status-code &#061; 3DIGIT<br \/>\nreason-phrase &#061; *( HTAB \/ SP \/ VCHAR \/ obs-text )<br \/>\nstatus-line &#061; HTTP-version SP status-code SP reason-phrase CRLF<\/p>\n<p>\u72b6\u6001\u7801\u6570\u503c\u8303\u56f4\u7ea6\u675f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7b2c\u4e00\u4f4d\u6570\u5b57&#xff1a;1-5&#xff0c;\u5b9a\u4e49\u54cd\u5e94\u7c7b\u522b<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u4f4d\u6570\u5b57&#xff1a;0-9&#xff0c;\u5b9a\u4e49\u5b50\u7c7b\u522b&#xff08;\u90e8\u5206\u6709\u7279\u5b9a\u542b\u4e49&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e09\u4f4d\u6570\u5b57&#xff1a;0-9&#xff0c;\u5177\u4f53\u72b6\u6001\u6807\u8bc6<\/p>\n<\/li>\n<\/ul>\n<p>\u72b6\u6001\u7801\u4fdd\u7559\u8303\u56f4&#xff1a;<\/p>\n<ul>\n<li>\n<p>0xx&#xff1a;\u672a\u4f7f\u7528&#xff0c;\u4fdd\u7559<\/p>\n<\/li>\n<li>\n<p>1xx&#xff1a;\u4fe1\u606f\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>2xx&#xff1a;\u6210\u529f\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>3xx&#xff1a;\u91cd\u5b9a\u5411<\/p>\n<\/li>\n<li>\n<p>4xx&#xff1a;\u5ba2\u6237\u7aef\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>5xx&#xff1a;\u670d\u52a1\u5668\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>6xx-9xx&#xff1a;\u672a\u5206\u914d&#xff0c;\u4fdd\u7559\u4f9b\u5c06\u6765\u4f7f\u7528<\/p>\n<\/li>\n<\/ul>\n<h5>\u72b6\u6001\u884c\u8be6\u7ec6\u89e3\u6790<\/h5>\n<p>\u6807\u51c6\u683c\u5f0f&#xff1a;<\/p>\n<p>text<\/p>\n<p>HTTP-Version Status-Code Reason-Phrase<\/p>\n<p>\u793a\u4f8b\u5206\u6790&#xff1a;<\/p>\n<p>http<\/p>\n<p>HTTP\/1.1 404 Not Found<\/p>\n<p>\u5404\u7ec4\u6210\u90e8\u5206\u8981\u6c42&#xff1a;<\/p>\n<li>\n<p>HTTP\u7248\u672c&#xff08;HTTP-Version&#xff09;<\/p>\n<ul>\n<li>\n<p>\u683c\u5f0f&#xff1a;HTTP\/\u4e3b\u7248\u672c\u53f7.\u6b21\u7248\u672c\u53f7<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;HTTP\/1.0, HTTP\/1.1, HTTP\/2, HTTP\/3<\/p>\n<\/li>\n<li>\n<p>\u4f5c\u7528&#xff1a;\u6307\u793a\u534f\u8bae\u7248\u672c&#xff0c;\u5f71\u54cd\u5ba2\u6237\u7aef\u89e3\u6790\u65b9\u5f0f<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u72b6\u6001\u7801&#xff08;Status-Code&#xff09;<\/p>\n<ul>\n<li>\n<p>\u4e09\u4f4d\u5341\u8fdb\u5236\u6570\u5b57<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u4e09\u4f4d&#xff0c;\u4e0d\u8db3\u88650&#xff08;\u5982004\u65e0\u6548&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u5e94\u80fd\u5904\u7406\u672a\u77e5\u72b6\u6001\u7801&#xff08;\u6309\u7b2c\u4e00\u4f4d\u6570\u5b57\u7c7b\u522b\u5904\u7406&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u539f\u56e0\u77ed\u8bed&#xff08;Reason-Phrase&#xff09;<\/p>\n<ul>\n<li>\n<p>\u53ef\u8bfb\u6587\u672c\u63cf\u8ff0<\/p>\n<\/li>\n<li>\n<p>\u4ec5\u7528\u4e8e\u4eba\u7c7b\u9605\u8bfb&#xff0c;\u7a0b\u5e8f\u4e0d\u5e94\u89e3\u6790\u5176\u5185\u5bb9<\/p>\n<\/li>\n<li>\n<p>\u53ef\u81ea\u5b9a\u4e49&#xff0c;\u4f46\u5efa\u8bae\u4f7f\u7528\u6807\u51c6\u77ed\u8bed<\/p>\n<\/li>\n<li>\n<p>\u957f\u5ea6\u5efa\u8bae\u4e0d\u8d85\u8fc750\u5b57\u7b26<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<h5>\u72b6\u6001\u7801\u7684\u6269\u5c55\u6027\u8bbe\u8ba1<\/h5>\n<p>HTTP\u72b6\u6001\u7801\u8bbe\u8ba1\u5177\u6709\u826f\u597d\u6269\u5c55\u6027&#xff1a;<\/p>\n<p>\u5ba2\u6237\u7aef\u5904\u7406\u672a\u77e5\u72b6\u6001\u7801\u7684\u89c4\u5219&#xff1a;<\/p>\n<p>javascript<\/p>\n<p>function handleStatusCode(code) {<br \/>\n    const category &#061; Math.floor(code \/ 100);<\/p>\n<p>    switch(category) {<br \/>\n        case 1:<br \/>\n            \/\/ \u4fe1\u606f\u54cd\u5e94 &#8211; \u901a\u5e38\u5ffd\u7565\u6216\u8bb0\u5f55<br \/>\n            console.log(&#096;Informational: ${code}&#096;);<br \/>\n            break;<br \/>\n        case 2:<br \/>\n            \/\/ \u6210\u529f &#8211; \u5904\u7406\u54cd\u5e94\u4f53<br \/>\n            console.log(&#096;Success: ${code}&#096;);<br \/>\n            processResponseBody();<br \/>\n            break;<br \/>\n        case 3:<br \/>\n            \/\/ \u91cd\u5b9a\u5411 &#8211; \u68c0\u67e5Location\u5934\u90e8<br \/>\n            console.log(&#096;Redirection: ${code}&#096;);<br \/>\n            handleRedirection();<br \/>\n            break;<br \/>\n        case 4:<br \/>\n            \/\/ \u5ba2\u6237\u7aef\u9519\u8bef &#8211; \u7528\u6237\u6216\u5e94\u7528\u9700\u8981\u4fee\u6b63<br \/>\n            console.log(&#096;Client Error: ${code}&#096;);<br \/>\n            showUserError();<br \/>\n            break;<br \/>\n        case 5:<br \/>\n            \/\/ \u670d\u52a1\u5668\u9519\u8bef &#8211; \u53ef\u91cd\u8bd5\u6216\u62a5\u544a<br \/>\n            console.log(&#096;Server Error: ${code}&#096;);<br \/>\n            handleServerError();<br \/>\n            break;<br \/>\n        default:<br \/>\n            \/\/ \u672a\u77e5\u7c7b\u522b &#8211; \u6309\u9519\u8bef\u5904\u7406<br \/>\n            console.log(&#096;Unknown status: ${code}&#096;);<br \/>\n            treatAsError();<br \/>\n    }<br \/>\n}<\/p>\n<p>\u670d\u52a1\u5668\u751f\u6210\u72b6\u6001\u7801\u7684\u6700\u4f73\u5b9e\u8df5&#xff1a;<\/p>\n<p>python<\/p>\n<p>from http import HTTPStatus<\/p>\n<p>class HTTPResponse:<br \/>\n    def __init__(self, status_code, body&#061;None, headers&#061;None):<br \/>\n        # \u4f7f\u7528\u6807\u51c6\u5e93\u7684\u72b6\u6001\u7801\u679a\u4e3e<br \/>\n        try:<br \/>\n            self.status &#061; HTTPStatus(status_code)<br \/>\n            self.status_code &#061; status_code<br \/>\n            self.reason &#061; self.status.phrase  # \u6807\u51c6\u539f\u56e0\u77ed\u8bed<br \/>\n        except ValueError:<br \/>\n            # \u672a\u77e5\u72b6\u6001\u7801 &#8211; \u4f7f\u7528\u901a\u7528\u63cf\u8ff0<br \/>\n            self.status_code &#061; status_code<br \/>\n            category &#061; status_code \/\/ 100<br \/>\n            reasons &#061; {<br \/>\n                1: &#034;Informational&#034;,<br \/>\n                2: &#034;Success&#034;,<br \/>\n                3: &#034;Redirection&#034;,<br \/>\n                4: &#034;Client Error&#034;,<br \/>\n                5: &#034;Server Error&#034;<br \/>\n            }<br \/>\n            self.reason &#061; reasons.get(category, &#034;Unknown Status&#034;)<\/p>\n<p>        self.body &#061; body or b&#034;&#034;<br \/>\n        self.headers &#061; headers or {}<\/p>\n<p>    def to_bytes(self):<br \/>\n        # \u6784\u5efa\u54cd\u5e94\u884c<br \/>\n        status_line &#061; f&#034;HTTP\/1.1 {self.status_code} {self.reason}\\\\r\\\\n&#034;<\/p>\n<p>        # \u6784\u5efa\u5934\u90e8<br \/>\n        headers &#061; &#034;&#034;<br \/>\n        for key, value in self.headers.items():<br \/>\n            headers &#043;&#061; f&#034;{key}: {value}\\\\r\\\\n&#034;<\/p>\n<p>        # \u6dfb\u52a0\u5fc5\u8981\u7684\u5934\u90e8<br \/>\n        if &#034;Content-Length&#034; not in self.headers:<br \/>\n            headers &#043;&#061; f&#034;Content-Length: {len(self.body)}\\\\r\\\\n&#034;<\/p>\n<p>        # \u7ec4\u5408\u54cd\u5e94<br \/>\n        return (status_line &#043; headers &#043; &#034;\\\\r\\\\n&#034;).encode() &#043; self.body<\/p>\n<h5>\u72b6\u6001\u7801\u4e0eHTTP\u7248\u672c\u517c\u5bb9\u6027<\/h5>\n<p>\u4e0d\u540cHTTP\u7248\u672c\u5bf9\u72b6\u6001\u7801\u7684\u652f\u6301\u6709\u7ec6\u5fae\u5dee\u5f02&#xff1a;<\/p>\n<table>\n<tr>HTTP\u7248\u672c\u72b6\u6001\u7801\u7279\u6027\u6ce8\u610f\u4e8b\u9879<\/tr>\n<tbody>\n<tr>\n<td>HTTP\/1.0<\/td>\n<td>\u57fa\u784016\u4e2a\u72b6\u6001\u7801<\/td>\n<td>\u65e0100 Continue&#xff0c;\u65e0\u5206\u5757\u4f20\u8f93<\/td>\n<\/tr>\n<tr>\n<td>HTTP\/1.1<\/td>\n<td>\u5b8c\u6574\u72b6\u6001\u7801\u96c6<\/td>\n<td>\u652f\u6301100 Continue&#xff0c;\u5206\u5757\u4f20\u8f93<\/td>\n<\/tr>\n<tr>\n<td>HTTP\/2<\/td>\n<td>\u8bed\u4e49\u4e0d\u53d8&#xff0c;\u4e8c\u8fdb\u5236\u5e27<\/td>\n<td>\u72b6\u6001\u7801\u5728HEADERS\u5e27\u4e2d\u4f20\u8f93<\/td>\n<\/tr>\n<tr>\n<td>HTTP\/3<\/td>\n<td>\u8bed\u4e49\u4e0d\u53d8&#xff0c;QUIC\u534f\u8bae<\/td>\n<td>\u72b6\u6001\u7801\u5728HTTP\/3\u5e27\u4e2d\u4f20\u8f93<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>HTTP\/2\u4e2d\u7684\u72b6\u6001\u7801\u4f20\u8f93&#xff1a;<\/p>\n<p>text<\/p>\n<p>HTTP\/2\u5e27\u7ed3\u6784&#xff1a;<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n| Length (24) | Type (8) | Flags (8) | R (1) |<br \/>\n| Stream Identifier (31)                        |<br \/>\n| Frame Payload (0&#8230;)                         |<br \/>\n&#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<\/p>\n<p>HEADERS\u5e27\u8f7d\u8377\u5305\u542b&#xff1a;<br \/>\n&#8211; \u538b\u7f29\u7684\u5934\u90e8\u5757\u7247\u6bb5<br \/>\n&#8211; \u5305\u542b:status\u4f2a\u5934\u90e8\u5b57\u6bb5<br \/>\n&#8211; \u793a\u4f8b: :status: 200<\/p>\n<h5>\u72b6\u6001\u7801\u7684\u56fd\u9645\u5316\u8003\u8651<\/h5>\n<p>\u867d\u7136\u72b6\u6001\u7801\u672c\u8eab\u662f\u6570\u5b57&#xff0c;\u4f46\u539f\u56e0\u77ed\u8bed\u53ef\u80fd\u9700\u8981\u56fd\u9645\u5316\u3002RFC\u6807\u51c6\u5efa\u8bae&#xff1a;<\/p>\n<li>\n<p>\u539f\u56e0\u77ed\u8bed\u4f7f\u7528US-ASCII\u5b57\u7b26\u96c6<\/p>\n<\/li>\n<li>\n<p>\u975eASCII\u5b57\u7b26\u4f7f\u7528\u7f16\u7801\u8f6c\u6362<\/p>\n<\/li>\n<li>\n<p>\u539f\u56e0\u77ed\u8bed\u4e3b\u8981\u7528\u4e8e\u8c03\u8bd5&#xff0c;\u4e0d\u5e94\u4f9d\u8d56\u5176\u5177\u4f53\u5185\u5bb9<\/p>\n<\/li>\n<p>\u591a\u8bed\u8a00\u73af\u5883\u4e0b\u7684\u72b6\u6001\u7801\u5904\u7406&#xff1a;<\/p>\n<p>java<\/p>\n<p>public class LocalizedStatus {<br \/>\n    private static final Map&lt;Integer, Map&lt;Locale, String&gt;&gt; REASON_PHRASES &#061; new HashMap&lt;&gt;();<\/p>\n<p>    static {<br \/>\n        \/\/ \u82f1\u8bed&#xff08;\u9ed8\u8ba4&#xff09;<br \/>\n        Map&lt;Locale, String&gt; en &#061; new HashMap&lt;&gt;();<br \/>\n        en.put(Locale.ENGLISH, &#034;OK&#034;);<br \/>\n        en.put(Locale.FRENCH, &#034;OK&#034;);<br \/>\n        REASON_PHRASES.put(200, en);<\/p>\n<p>        \/\/ \u4e2d\u6587<br \/>\n        Map&lt;Locale, String&gt; zh &#061; new HashMap&lt;&gt;();<br \/>\n        zh.put(Locale.SIMPLIFIED_CHINESE, &#034;\u6210\u529f&#034;);<br \/>\n        zh.put(Locale.TRADITIONAL_CHINESE, &#034;\u6210\u529f&#034;);<br \/>\n        REASON_PHRASES.put(200, zh);<br \/>\n    }<\/p>\n<p>    public static String getReasonPhrase(int statusCode, Locale locale) {<br \/>\n        Map&lt;Locale, String&gt; phrases &#061; REASON_PHRASES.get(statusCode);<br \/>\n        if (phrases !&#061; null) {<br \/>\n            String phrase &#061; phrases.get(locale);<br \/>\n            if (phrase !&#061; null) {<br \/>\n                return phrase;<br \/>\n            }<br \/>\n        }<br \/>\n        \/\/ \u56de\u9000\u5230HTTPStatus\u7684\u6807\u51c6\u77ed\u8bed<br \/>\n        return HttpStatus.valueOf(statusCode).getReasonPhrase();<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u7b2c2\u7ae0&#xff1a;\u72b6\u6001\u7801\u5206\u7c7b\u4f53\u7cfb\u8be6\u89e3<\/h3>\n<h4>2.1 \u4e94\u7c7b\u72b6\u6001\u7801\u7684\u8bed\u4e49\u533a\u522b<\/h4>\n<h5>1xx&#xff1a;\u4fe1\u606f\u6027\u72b6\u6001\u7801&#xff08;Informational&#xff09;<\/h5>\n<p>1xx\u72b6\u6001\u7801\u8868\u793a\u8bf7\u6c42\u5df2\u88ab\u63a5\u6536&#xff0c;\u9700\u8981\u7ee7\u7eed\u5904\u7406\u3002\u8fd9\u7c7b\u72b6\u6001\u7801\u662f\u4e34\u65f6\u7684&#xff0c;\u5ba2\u6237\u7aef\u5e94\u8be5\u7b49\u5f85\u670d\u52a1\u5668\u7684\u6700\u7ec8\u54cd\u5e94\u3002<\/p>\n<p>\u6838\u5fc3\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e34\u65f6\u54cd\u5e94&#xff0c;\u4e0d\u4ee3\u8868\u6700\u7ec8\u7ed3\u679c<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u7531HTTP\/1.1\u6216\u66f4\u9ad8\u7248\u672c\u670d\u52a1\u5668\u53d1\u9001<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u4e0d\u5e94\u5355\u72ec\u53d1\u90011xx\u54cd\u5e94\u7684ACK<\/p>\n<\/li>\n<li>\n<p>1xx\u54cd\u5e94\u4e0d\u80fd\u5305\u542b\u6d88\u606f\u4f53<\/p>\n<\/li>\n<\/ul>\n<p>\u5e38\u89c11xx\u72b6\u6001\u7801&#xff1a;<\/p>\n<ul>\n<li>\n<p>100 Continue&#xff1a;\u5ba2\u6237\u7aef\u5e94\u7ee7\u7eed\u53d1\u9001\u8bf7\u6c42\u4f53<\/p>\n<\/li>\n<li>\n<p>101 Switching Protocols&#xff1a;\u670d\u52a1\u5668\u540c\u610f\u5207\u6362\u534f\u8bae<\/p>\n<\/li>\n<li>\n<p>102 Processing\u00a0(WebDAV)&#xff1a;\u8bf7\u6c42\u6b63\u5728\u5904\u7406\u4f46\u672a\u5b8c\u6210<\/p>\n<\/li>\n<li>\n<p>103 Early Hints&#xff1a;\u9884\u52a0\u8f7d\u63d0\u793a<\/p>\n<\/li>\n<\/ul>\n<p>\u6280\u672f\u5b9e\u73b0\u793a\u4f8b&#xff1a;<\/p>\n<p>nginx<\/p>\n<p># Nginx\u914d\u7f6e100 Continue\u652f\u6301<br \/>\nlocation \/upload {<br \/>\n    # \u542f\u7528100 Continue\u54cd\u5e94<br \/>\n    client_max_body_size 100M;<\/p>\n<p>    # \u5bf9\u5927\u6587\u4ef6\u4e0a\u4f20\u7279\u522b\u6709\u7528<br \/>\n    if ($request_method &#061; POST) {<br \/>\n        # \u68c0\u67e5Expect\u5934\u90e8<br \/>\n        if ($http_expect &#061; &#034;100-continue&#034;) {<br \/>\n            return 100;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    # \u5b9e\u9645\u5904\u7406\u903b\u8f91<br \/>\n    proxy_pass http:\/\/backend;<br \/>\n}<\/p>\n<h5>2xx&#xff1a;\u6210\u529f\u72b6\u6001\u7801&#xff08;Success&#xff09;<\/h5>\n<p>2xx\u72b6\u6001\u7801\u8868\u793a\u8bf7\u6c42\u5df2\u88ab\u6210\u529f\u63a5\u6536\u3001\u7406\u89e3\u3001\u63a5\u53d7\u548c\u5904\u7406\u3002<\/p>\n<p>\u6838\u5fc3\u7279\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bf7\u6c42\u6210\u529f\u5b8c\u6210<\/p>\n<\/li>\n<li>\n<p>\u54cd\u5e94\u53ef\u80fd\u5305\u542b\u6d88\u606f\u4f53&#xff08;204\/205\u9664\u5916&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6210\u529f\u8bed\u4e49\u56e0\u65b9\u6cd5\u548c\u72b6\u6001\u7801\u800c\u5f02<\/p>\n<\/li>\n<\/ul>\n<p>\u6210\u529f\u72b6\u6001\u7801\u7684\u8bed\u4e49\u77e9\u9635&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\\\\\u72b6\u6001\u7801200 OK201 Created204 No Content<\/tr>\n<tbody>\n<tr>\n<td>GET<\/td>\n<td>\u8fd4\u56de\u8d44\u6e90<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>POST<\/td>\n<td>\u64cd\u4f5c\u7ed3\u679c<\/td>\n<td>\u521b\u5efa\u65b0\u8d44\u6e90<\/td>\n<td>\u65e0\u5185\u5bb9\u8fd4\u56de<\/td>\n<\/tr>\n<tr>\n<td>PUT<\/td>\n<td>\u66f4\u65b0\u6210\u529f<\/td>\n<td>\u521b\u5efa\u65b0\u8d44\u6e90<\/td>\n<td>\u66f4\u65b0\u6210\u529f\u65e0\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>DELETE<\/td>\n<td>\u5220\u9664\u6210\u529f<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u5220\u9664\u6210\u529f\u65e0\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>PATCH<\/td>\n<td>\u66f4\u65b0\u6210\u529f<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u66f4\u65b0\u6210\u529f\u65e0\u5185\u5bb9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>3xx&#xff1a;\u91cd\u5b9a\u5411\u72b6\u6001\u7801&#xff08;Redirection&#xff09;<\/h5>\n<p>3xx\u72b6\u6001\u7801\u8868\u793a\u9700\u8981\u5ba2\u6237\u7aef\u91c7\u53d6\u8fdb\u4e00\u6b65\u64cd\u4f5c\u624d\u80fd\u5b8c\u6210\u8bf7\u6c42\u3002<\/p>\n<p>\u91cd\u5b9a\u5411\u7c7b\u578b\u5206\u7c7b&#xff1a;<\/p>\n<li>\n<p>\u6c38\u4e45\u91cd\u5b9a\u5411<\/p>\n<ul>\n<li>\n<p>301 Moved Permanently<\/p>\n<\/li>\n<li>\n<p>308 Permanent Redirect<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u65f6\u95f4\u957f&#xff0c;\u6d4f\u89c8\u5668\u4f1a\u66f4\u65b0\u4e66\u7b7e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e34\u65f6\u91cd\u5b9a\u5411<\/p>\n<ul>\n<li>\n<p>302 Found<\/p>\n<\/li>\n<li>\n<p>303 See Other<\/p>\n<\/li>\n<li>\n<p>307 Temporary Redirect<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u65f6\u95f4\u77ed\u6216\u4e0d\u7f13\u5b58<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7279\u6b8a\u91cd\u5b9a\u5411<\/p>\n<ul>\n<li>\n<p>304 Not Modified&#xff08;\u7f13\u5b58\u9a8c\u8bc1&#xff09;<\/p>\n<\/li>\n<li>\n<p>300 Multiple Choices&#xff08;\u591a\u9009\u9879&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u91cd\u5b9a\u5411\u5904\u7406\u6d41\u7a0b\u56fe&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"1760\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072538-6969e7f2a37a2.png\" width=\"1064\" \/><\/p>\n<h5>4xx&#xff1a;\u5ba2\u6237\u7aef\u9519\u8bef\u72b6\u6001\u7801&#xff08;Client Error&#xff09;<\/h5>\n<p>4xx\u72b6\u6001\u7801\u8868\u793a\u5ba2\u6237\u7aef\u4f3c\u4e4e\u53d1\u751f\u4e86\u9519\u8bef&#xff0c;\u670d\u52a1\u5668\u65e0\u6cd5\u6216\u4e0d\u613f\u610f\u5904\u7406\u8bf7\u6c42\u3002<\/p>\n<p>\u9519\u8bef\u8d23\u4efb\u5212\u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5ba2\u6237\u7aef\u8d1f\u8d23\u4fee\u6b63\u9519\u8bef<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u660e\u786e\u6307\u793a\u95ee\u9898\u6240\u5728<\/p>\n<\/li>\n<li>\n<p>\u8bf7\u6c42\u53ef\u80fd\u90e8\u5206\u5904\u7406&#xff0c;\u53ef\u80fd\u6709\u526f\u4f5c\u7528<\/p>\n<\/li>\n<\/ul>\n<p>\u5ba2\u6237\u7aef\u9519\u8bef\u5206\u7c7b&#xff1a;<\/p>\n<table>\n<tr>\u9519\u8bef\u7c7b\u522b\u5178\u578b\u72b6\u6001\u7801\u5ba2\u6237\u7aef\u5e94\u91c7\u53d6\u63aa\u65bd<\/tr>\n<tbody>\n<tr>\n<td>\u8bed\u6cd5\u9519\u8bef<\/td>\n<td>400 Bad Request<\/td>\n<td>\u68c0\u67e5\u8bf7\u6c42\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>\u8ba4\u8bc1\u9519\u8bef<\/td>\n<td>401 Unauthorized<\/td>\n<td>\u63d0\u4f9b\u6709\u6548\u51ed\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>\u6743\u9650\u9519\u8bef<\/td>\n<td>403 Forbidden<\/td>\n<td>\u68c0\u67e5\u8bbf\u95ee\u6743\u9650<\/td>\n<\/tr>\n<tr>\n<td>\u8d44\u6e90\u9519\u8bef<\/td>\n<td>404 Not Found<\/td>\n<td>\u68c0\u67e5\u8d44\u6e90\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td>\u65b9\u6cd5\u9519\u8bef<\/td>\n<td>405 Method Not Allowed<\/td>\n<td>\u4f7f\u7528\u5141\u8bb8\u7684\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>\u51b2\u7a81\u9519\u8bef<\/td>\n<td>409 Conflict<\/td>\n<td>\u89e3\u51b3\u8d44\u6e90\u51b2\u7a81<\/td>\n<\/tr>\n<tr>\n<td>\u683c\u5f0f\u9519\u8bef<\/td>\n<td>415 Unsupported Media Type<\/td>\n<td>\u4f7f\u7528\u652f\u6301\u7684\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>\u901f\u7387\u9650\u5236<\/td>\n<td>429 Too Many Requests<\/td>\n<td>\u964d\u4f4e\u8bf7\u6c42\u9891\u7387<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>5xx&#xff1a;\u670d\u52a1\u5668\u9519\u8bef\u72b6\u6001\u7801&#xff08;Server Error&#xff09;<\/h5>\n<p>5xx\u72b6\u6001\u7801\u8868\u793a\u670d\u52a1\u5668\u5728\u5904\u7406\u8bf7\u6c42\u65f6\u53d1\u751f\u9519\u8bef\u6216\u65e0\u6cd5\u5b8c\u6210\u8bf7\u6c42\u3002<\/p>\n<p>\u670d\u52a1\u5668\u9519\u8bef\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bf7\u6c42\u672c\u8eab\u53ef\u80fd\u662f\u6709\u6548\u7684<\/p>\n<\/li>\n<li>\n<p>\u9519\u8bef\u8d23\u4efb\u5728\u670d\u52a1\u5668\u7aef<\/p>\n<\/li>\n<li>\n<p>\u5ba2\u6237\u7aef\u53ef\u7a0d\u540e\u91cd\u8bd5&#xff08;\u5e42\u7b49\u8bf7\u6c42&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>\u670d\u52a1\u5668\u9519\u8bef\u5904\u7406\u7b56\u7565&#xff1a;<\/p>\n<p>python<\/p>\n<p>class ServerErrorHandler:<br \/>\n    def __init__(self):<br \/>\n        self.error_counts &#061; {}<br \/>\n        self.circuit_breaker &#061; CircuitBreaker()<\/p>\n<p>    def handle_5xx_error(self, url, status_code):<br \/>\n        # \u8bb0\u5f55\u9519\u8bef<br \/>\n        self._log_error(url, status_code)<\/p>\n<p>        # \u68c0\u67e5\u662f\u5426\u9700\u8981\u7194\u65ad<br \/>\n        if self.circuit_breaker.should_open(url):<br \/>\n            return self._fallback_response(url)<\/p>\n<p>        # \u5b9e\u73b0\u91cd\u8bd5\u903b\u8f91<br \/>\n        if self._should_retry(status_code):<br \/>\n            return self._retry_request(url)<\/p>\n<p>        # \u663e\u793a\u7528\u6237\u53cb\u597d\u9519\u8bef<br \/>\n        return self._user_friendly_error(status_code)<\/p>\n<p>    def _should_retry(self, status_code):<br \/>\n        &#034;&#034;&#034;\u786e\u5b9a\u662f\u5426\u5e94\u91cd\u8bd5\u76845xx\u72b6\u6001\u7801&#034;&#034;&#034;<br \/>\n        retriable_codes &#061; {<br \/>\n            500: True,  # \u5185\u90e8\u9519\u8bef&#xff0c;\u53ef\u80fd\u4e34\u65f6<br \/>\n            502: True,  # \u7f51\u5173\u9519\u8bef&#xff0c;\u4e0a\u6e38\u95ee\u9898<br \/>\n            503: True,  # \u670d\u52a1\u4e0d\u53ef\u7528&#xff0c;\u8fc7\u8f7d<br \/>\n            504: True,  # \u7f51\u5173\u8d85\u65f6<br \/>\n            507: False, # \u5b58\u50a8\u7a7a\u95f4\u4e0d\u8db3&#xff0c;\u4e0d\u5e94\u91cd\u8bd5<br \/>\n            508: False  # \u68c0\u6d4b\u5230\u5faa\u73af&#xff0c;\u4e0d\u5e94\u91cd\u8bd5<br \/>\n        }<br \/>\n        return retriable_codes.get(status_code, False)<\/p>\n<h4 style=\"background-color:transparent\">2.2 \u72b6\u6001\u7801\u7684\u53ef\u7f13\u5b58\u6027\u89c4\u5219<\/h4>\n<h5>HTTP\u7f13\u5b58\u57fa\u7840<\/h5>\n<p>HTTP\u7f13\u5b58\u673a\u5236\u901a\u8fc7\u72b6\u6001\u7801\u548c\u7f13\u5b58\u63a7\u5236\u5934\u90e8\u534f\u540c\u5de5\u4f5c&#xff0c;\u51b3\u5b9a\u54cd\u5e94\u662f\u5426\u4ee5\u53ca\u5982\u4f55\u7f13\u5b58\u3002<\/p>\n<p>\u7f13\u5b58\u51b3\u7b56\u6d41\u7a0b&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"540\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072539-6969e7f39dd02.png\" width=\"3084\" \/><\/p>\n<h5>\u72b6\u6001\u7801\u7f13\u5b58\u5206\u7c7b<\/h5>\n<p>\u6839\u636eRFC 7231&#xff0c;\u72b6\u6001\u7801\u7684\u9ed8\u8ba4\u7f13\u5b58\u884c\u4e3a\u5982\u4e0b&#xff1a;<\/p>\n<p>\u9ed8\u8ba4\u53ef\u7f13\u5b58\u7684\u54cd\u5e94&#xff1a;<\/p>\n<p>http<\/p>\n<p># \u793a\u4f8b1&#xff1a;200 OK &#8211; \u9ed8\u8ba4\u53ef\u7f13\u5b58<br \/>\nHTTP\/1.1 200 OK<br \/>\nDate: Mon, 23 Jan 2023 10:30:45 GMT<br \/>\nContent-Type: text\/html<br \/>\nContent-Length: 1234<br \/>\nCache-Control: max-age&#061;3600  # \u660e\u786e\u7f13\u5b581\u5c0f\u65f6<\/p>\n<p>&lt;!DOCTYPE html&gt;&#8230;&lt;\/html&gt;<\/p>\n<p>\u9ed8\u8ba4\u4e0d\u53ef\u7f13\u5b58\u7684\u54cd\u5e94&#xff1a;<\/p>\n<p>http<\/p>\n<p># \u793a\u4f8b2&#xff1a;500 Internal Server Error &#8211; \u9ed8\u8ba4\u4e0d\u7f13\u5b58<br \/>\nHTTP\/1.1 500 Internal Server Error<br \/>\nDate: Mon, 23 Jan 2023 10:30:45 GMT<br \/>\nContent-Type: application\/json<br \/>\nContent-Length: 45<\/p>\n<p>{&#034;error&#034;: &#034;Internal server error&#034;}<\/p>\n<h5>\u8be6\u7ec6\u7f13\u5b58\u89c4\u5219\u8868<\/h5>\n<table>\n<tr>\u72b6\u6001\u7801\u9ed8\u8ba4\u53ef\u7f13\u5b58\u53ef\u88ab\u8986\u76d6\u5178\u578b\u7f13\u5b58\u65f6\u95f4\u7f13\u5b58\u9a8c\u8bc1\u8981\u6c42<\/tr>\n<tbody>\n<tr>\n<td>200 OK<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<td>\u7531Cache-Control\u51b3\u5b9a<\/td>\n<td>\u9700\u8981\u9a8c\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>201 Created<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>204 No Content<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<td>\u77ed\u65f6\u95f4&#xff08;\u59825\u79d2&#xff09;<\/td>\n<td>\u4e0d\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td>206 Partial Content<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<td>\u4e0e\u5b8c\u6574\u8d44\u6e90\u76f8\u540c<\/td>\n<td>\u9700\u8981\u9a8c\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>301 Moved Permanently<\/td>\n<td>\u662f<\/td>\n<td>\u5426<\/td>\n<td>\u6c38\u4e45&#xff08;\u901a\u5e381\u5e74&#xff09;<\/td>\n<td>\u4e0d\u9700\u8981<\/td>\n<\/tr>\n<tr>\n<td>302 Found<\/td>\n<td>\u901a\u5e38\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u63a8\u8350\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>304 Not Modified<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>307 Temporary Redirect<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>400 Bad Request<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>401 Unauthorized<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>403 Forbidden<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<td>\u77ed\u65f6\u95f4&#xff08;\u598210\u5206\u949f&#xff09;<\/td>\n<td>\u9700\u8981\u9a8c\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>404 Not Found<\/td>\n<td>\u662f<\/td>\n<td>\u662f<\/td>\n<td>\u77ed\u65f6\u95f4&#xff08;\u598210\u5206\u949f&#xff09;<\/td>\n<td>\u9700\u8981\u9a8c\u8bc1<\/td>\n<\/tr>\n<tr>\n<td>500 Internal Server Error<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u4e0d\u7f13\u5b58<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>502 Bad Gateway<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u77ed\u65f6\u95f4&#xff08;\u598230\u79d2&#xff09;<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>503 Service Unavailable<\/td>\n<td>\u5426<\/td>\n<td>\u662f<\/td>\n<td>\u77ed\u65f6\u95f4&#xff08;\u598230\u79d2&#xff09;<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u7f13\u5b58\u9a8c\u8bc1\u673a\u5236<\/h5>\n<p>\u7f13\u5b58\u9a8c\u8bc1\u662f\u786e\u4fdd\u7f13\u5b58\u5185\u5bb9\u65b0\u9c9c\u5ea6\u7684\u5173\u952e\u673a\u5236&#xff0c;\u4e3b\u8981\u6d89\u53ca\u4ee5\u4e0b\u72b6\u6001\u7801&#xff1a;<\/p>\n<p>http<\/p>\n<p># \u5ba2\u6237\u7aef\u53d1\u8d77\u7f13\u5b58\u9a8c\u8bc1\u8bf7\u6c42<br \/>\nGET \/resource HTTP\/1.1<br \/>\nHost: example.com<br \/>\nIf-None-Match: &#034;abc123&#034;    # \u5b9e\u4f53\u6807\u7b7e\u9a8c\u8bc1<br \/>\nIf-Modified-Since: Mon, 16 Jan 2023 14:28:00 GMT  # \u65f6\u95f4\u9a8c\u8bc1<\/p>\n<p># \u670d\u52a1\u5668\u54cd\u5e94<br \/>\nHTTP\/1.1 304 Not Modified  # \u7f13\u5b58\u6709\u6548&#xff0c;\u4f7f\u7528\u7f13\u5b58<br \/>\nETag: &#034;abc123&#034;<br \/>\nDate: Mon, 23 Jan 2023 10:30:45 GMT<br \/>\n# \u65e0\u6d88\u606f\u4f53<\/p>\n<p>\u7f13\u5b58\u9a8c\u8bc1\u72b6\u6001\u7801\u5904\u7406&#xff1a;<\/p>\n<p>javascript<\/p>\n<p>class CacheValidator {<br \/>\n    async validateCache(request, cachedResponse) {<br \/>\n        \/\/ \u6784\u5efa\u9a8c\u8bc1\u8bf7\u6c42<br \/>\n        const validationRequest &#061; new Request(request.url, {<br \/>\n            headers: this._buildValidationHeaders(cachedResponse)<br \/>\n        });<\/p>\n<p>        try {<br \/>\n            const validationResponse &#061; await fetch(validationRequest);<\/p>\n<p>            switch (validationResponse.status) {<br \/>\n                case 200: \/\/ \u8d44\u6e90\u5df2\u4fee\u6539&#xff0c;\u8fd4\u56de\u65b0\u5185\u5bb9<br \/>\n                    return {<br \/>\n                        fresh: false,<br \/>\n                        response: validationResponse<br \/>\n                    };<\/p>\n<p>                case 304: \/\/ \u7f13\u5b58\u6709\u6548<br \/>\n                    return {<br \/>\n                        fresh: true,<br \/>\n                        response: this._updateCachedResponse(<br \/>\n                            cachedResponse,<br \/>\n                            validationResponse.headers<br \/>\n                        )<br \/>\n                    };<\/p>\n<p>                case 404: \/\/ \u8d44\u6e90\u4e0d\u5b58\u5728&#xff0c;\u6e05\u9664\u7f13\u5b58<br \/>\n                case 410: \/\/ \u8d44\u6e90\u6c38\u4e45\u6d88\u5931<br \/>\n                    this.cache.delete(request);<br \/>\n                    return {<br \/>\n                        fresh: false,<br \/>\n                        response: validationResponse<br \/>\n                    };<\/p>\n<p>                default: \/\/ \u5176\u4ed6\u72b6\u6001\u7801&#xff0c;\u8c28\u614e\u5904\u7406<br \/>\n                    console.warn(&#096;Unexpected status: ${validationResponse.status}&#096;);<br \/>\n                    return {<br \/>\n                        fresh: false,<br \/>\n                        response: validationResponse<br \/>\n                    };<br \/>\n            }<br \/>\n        } catch (error) {<br \/>\n            \/\/ \u7f51\u7edc\u9519\u8bef&#xff0c;\u4f7f\u7528\u7f13\u5b58&#xff08;\u5982\u679c\u672a\u8fc7\u671f&#xff09;<br \/>\n            if (this._isCacheFresh(cachedResponse)) {<br \/>\n                return { fresh: true, response: cachedResponse };<br \/>\n            }<br \/>\n            throw error;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    _buildValidationHeaders(cachedResponse) {<br \/>\n        const headers &#061; {};<\/p>\n<p>        \/\/ \u6dfb\u52a0ETag\u9a8c\u8bc1<br \/>\n        const etag &#061; cachedResponse.headers.get(&#039;ETag&#039;);<br \/>\n        if (etag) {<br \/>\n            headers[&#039;If-None-Match&#039;] &#061; etag;<br \/>\n        }<\/p>\n<p>        \/\/ \u6dfb\u52a0Last-Modified\u9a8c\u8bc1<br \/>\n        const lastModified &#061; cachedResponse.headers.get(&#039;Last-Modified&#039;);<br \/>\n        if (lastModified) {<br \/>\n            headers[&#039;If-Modified-Since&#039;] &#061; lastModified;<br \/>\n        }<\/p>\n<p>        return headers;<br \/>\n    }<br \/>\n}<\/p>\n<h5>\u7f13\u5b58\u5931\u6548\u7b56\u7565<\/h5>\n<p>\u4e0d\u540c\u72b6\u6001\u7801\u89e6\u53d1\u7684\u7f13\u5b58\u5931\u6548\u884c\u4e3a\u4e0d\u540c&#xff1a;<\/p>\n<p>python<\/p>\n<p>class CacheInvalidator:<br \/>\n    &#034;&#034;&#034;\u5904\u7406\u4e0d\u540c\u72b6\u6001\u7801\u7684\u7f13\u5b58\u5931\u6548\u903b\u8f91&#034;&#034;&#034;<\/p>\n<p>    def handle_response(self, request, response):<br \/>\n        status &#061; response.status_code<\/p>\n<p>        # \u6839\u636e\u72b6\u6001\u7801\u51b3\u5b9a\u7f13\u5b58\u884c\u4e3a<br \/>\n        cache_strategy &#061; self._get_cache_strategy(status, response.headers)<\/p>\n<p>        if cache_strategy &#061;&#061; &#039;no_store&#039;:<br \/>\n            self.cache.delete(request.url)<\/p>\n<p>        elif cache_strategy &#061;&#061; &#039;invalidate&#039;:<br \/>\n            # \u4f7f\u76f8\u5173\u7f13\u5b58\u5931\u6548<br \/>\n            self._invalidate_related(request.url)<\/p>\n<p>        elif cache_strategy &#061;&#061; &#039;update&#039;:<br \/>\n            # \u66f4\u65b0\u7f13\u5b58\u5185\u5bb9<br \/>\n            self.cache.set(request.url, response)<\/p>\n<p>        return cache_strategy<\/p>\n<p>    def _get_cache_strategy(self, status, headers):<br \/>\n        &#034;&#034;&#034;\u6839\u636e\u72b6\u6001\u7801\u548c\u5934\u90e8\u786e\u5b9a\u7f13\u5b58\u7b56\u7565&#034;&#034;&#034;<\/p>\n<p>        # \u5f3a\u5236\u4e0d\u7f13\u5b58<br \/>\n        if headers.get(&#039;Cache-Control&#039;, &#039;&#039;).find(&#039;no-store&#039;) !&#061; -1:<br \/>\n            return &#039;no_store&#039;<\/p>\n<p>        # \u72b6\u6001\u7801\u7279\u5b9a\u7b56\u7565<br \/>\n        if status &#061;&#061; 200:<br \/>\n            return &#039;update&#039;<br \/>\n        elif status &#061;&#061; 301:  # \u6c38\u4e45\u91cd\u5b9a\u5411<br \/>\n            return &#039;invalidate&#039;<br \/>\n        elif status &#061;&#061; 404:<br \/>\n            # 404\u53ef\u4ee5\u7f13\u5b58&#xff0c;\u4f46\u65f6\u95f4\u8f83\u77ed<br \/>\n            return &#039;update&#039;<br \/>\n        elif status &gt;&#061; 500:<br \/>\n            # \u670d\u52a1\u5668\u9519\u8bef\u901a\u5e38\u4e0d\u7f13\u5b58<br \/>\n            return &#039;no_store&#039;<br \/>\n        else:<br \/>\n            return &#039;no_store&#039;<\/p>\n<h4>2.3 \u72b6\u6001\u7801\u7684\u5b89\u5168\u6027\u5c5e\u6027<\/h4>\n<h5>\u5b89\u5168\u65b9\u6cd5\u4e0e\u975e\u5b89\u5168\u65b9\u6cd5<\/h5>\n<p>HTTP\u65b9\u6cd5\u6839\u636e\u5176\u662f\u5426\u6539\u53d8\u670d\u52a1\u5668\u72b6\u6001\u5206\u4e3a\u5b89\u5168\u65b9\u6cd5\u548c\u975e\u5b89\u5168\u65b9\u6cd5&#xff1a;<\/p>\n<p>\u5b89\u5168\u65b9\u6cd5&#xff08;Safe Methods&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>GET &#8211; \u83b7\u53d6\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>HEAD &#8211; \u83b7\u53d6\u5934\u90e8<\/p>\n<\/li>\n<li>\n<p>OPTIONS &#8211; \u67e5\u8be2\u9009\u9879<\/p>\n<\/li>\n<li>\n<p>TRACE &#8211; \u56de\u663e\u8bf7\u6c42<\/p>\n<\/li>\n<\/ul>\n<p>\u975e\u5b89\u5168\u65b9\u6cd5&#xff08;Unsafe Methods&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>POST &#8211; \u521b\u5efa\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>PUT &#8211; \u66f4\u65b0\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>DELETE &#8211; \u5220\u9664\u8d44\u6e90<\/p>\n<\/li>\n<li>\n<p>PATCH &#8211; \u90e8\u5206\u66f4\u65b0<\/p>\n<\/li>\n<\/ul>\n<h5>\u72b6\u6001\u7801\u4e0e\u5e42\u7b49\u6027<\/h5>\n<p>\u5e42\u7b49\u6027\u662f\u6307\u540c\u4e00\u64cd\u4f5c\u6267\u884c\u4e00\u6b21\u6216\u591a\u6b21\u4ea7\u751f\u7684\u6548\u679c\u76f8\u540c&#xff1a;<\/p>\n<p>\u5e42\u7b49\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\n<p>GET\u3001HEAD\u3001OPTIONS\u3001TRACE\u3001PUT\u3001DELETE<\/p>\n<\/li>\n<\/ul>\n<p>\u975e\u5e42\u7b49\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>\n<p>POST\u3001PATCH<\/p>\n<\/li>\n<\/ul>\n<p>\u72b6\u6001\u7801\u5bf9\u5e42\u7b49\u6027\u7684\u5f71\u54cd&#xff1a;<\/p>\n<p>javascript<\/p>\n<p>class IdempotencyChecker {<br \/>\n    isRequestIdempotent(method, statusCode) {<br \/>\n        \/\/ \u57fa\u4e8e\u65b9\u6cd5\u5224\u65ad<br \/>\n        const idempotentMethods &#061; [&#039;GET&#039;, &#039;HEAD&#039;, &#039;OPTIONS&#039;, &#039;TRACE&#039;, &#039;PUT&#039;, &#039;DELETE&#039;];<br \/>\n        const isMethodIdempotent &#061; idempotentMethods.includes(method);<\/p>\n<p>        \/\/ \u57fa\u4e8e\u72b6\u6001\u7801\u5224\u65ad<br \/>\n        const category &#061; Math.floor(statusCode \/ 100);<\/p>\n<p>        if (category &#061;&#061;&#061; 4 || category &#061;&#061;&#061; 5) {<br \/>\n            \/\/ 4xx\u62165xx\u54cd\u5e94&#xff0c;\u9700\u8981\u68c0\u67e5\u662f\u5426\u4ea7\u751f\u526f\u4f5c\u7528<br \/>\n            return this._checkForSideEffects(method, statusCode);<br \/>\n        }<\/p>\n<p>        return isMethodIdempotent;<br \/>\n    }<\/p>\n<p>    _checkForSideEffects(method, statusCode) {<br \/>\n        \/\/ \u7279\u5b9a\u72b6\u6001\u7801\u53ef\u80fd\u8868\u793a\u90e8\u5206\u6210\u529f<br \/>\n        const partialSuccessCodes &#061; [202, 206];<\/p>\n<p>        if (partialSuccessCodes.includes(statusCode)) {<br \/>\n            \/\/ 202 Accepted: \u8bf7\u6c42\u5df2\u63a5\u53d7\u4f46\u672a\u5904\u7406\u5b8c\u6210<br \/>\n            \/\/ 206 Partial Content: \u90e8\u5206\u5185\u5bb9\u5df2\u5904\u7406<br \/>\n            return false; \/\/ \u53ef\u80fd\u975e\u5e42\u7b49<br \/>\n        }<\/p>\n<p>        \/\/ \u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u9519\u8bef\u54cd\u5e94\u4e0d\u6539\u53d8\u72b6\u6001<br \/>\n        return true;<br \/>\n    }<br \/>\n}<\/p>\n<h5>\u5b89\u5168\u72b6\u6001\u7801\u5b9e\u8df5<\/h5>\n<p>\u5b89\u5168\u72b6\u6001\u7801\u7684\u4f7f\u7528\u6a21\u5f0f&#xff1a;<\/p>\n<li>\n<p>GET &#043; 200 OK&#xff1a;\u5b89\u5168\u8bfb\u53d6\u64cd\u4f5c<\/p>\n<p>http<\/p>\n<p>GET \/api\/users\/123 HTTP\/1.1<\/p>\n<p>HTTP\/1.1 200 OK<br \/>\n{&#034;id&#034;: 123, &#034;name&#034;: &#034;John&#034;}\n<\/li>\n<li>\n<p>PUT &#043; 200 OK\/204 No Content&#xff1a;\u5e42\u7b49\u66f4\u65b0\u64cd\u4f5c<\/p>\n<p>http<\/p>\n<p>PUT \/api\/users\/123 HTTP\/1.1<br \/>\n{&#034;name&#034;: &#034;Jane&#034;}<\/p>\n<p>HTTP\/1.1 200 OK<br \/>\n{&#034;id&#034;: 123, &#034;name&#034;: &#034;Jane&#034;}\n<\/li>\n<li>\n<p>DELETE &#043; 200 OK\/204 No Content&#xff1a;\u5e42\u7b49\u5220\u9664\u64cd\u4f5c<\/p>\n<p>http<\/p>\n<p>DELETE \/api\/users\/123 HTTP\/1.1<\/p>\n<p>HTTP\/1.1 204 No Content\n<\/li>\n<p>\u4e0d\u5b89\u5168\u64cd\u4f5c\u7684\u54cd\u5e94\u5904\u7406&#xff1a;<\/p>\n<p>python<\/p>\n<p>from flask import Flask, request, jsonify<br \/>\nimport uuid<\/p>\n<p>app &#061; Flask(__name__)<\/p>\n<p>class IdempotencyManager:<br \/>\n    def __init__(self):<br \/>\n        self.processed_requests &#061; {}<\/p>\n<p>    def generate_key(self, request):<br \/>\n        &#034;&#034;&#034;\u4e3a\u8bf7\u6c42\u751f\u6210\u5e42\u7b49\u952e&#034;&#034;&#034;<br \/>\n        # \u7ed3\u5408\u5ba2\u6237\u7aefID\u548c\u8bf7\u6c42\u7279\u5f81<br \/>\n        client_id &#061; request.headers.get(&#039;X-Client-ID&#039;)<br \/>\n        request_hash &#061; hash(frozenset(request.get_json().items()))<br \/>\n        return f&#034;{client_id}:{request_hash}&#034;<\/p>\n<p>    def check_and_store(self, idempotency_key):<br \/>\n        &#034;&#034;&#034;\u68c0\u67e5\u5e76\u8bb0\u5f55\u5e42\u7b49\u952e&#034;&#034;&#034;<br \/>\n        if idempotency_key in self.processed_requests:<br \/>\n            # \u8fd4\u56de\u4e4b\u524d\u7684\u7ed3\u679c<br \/>\n            return self.processed_requests[idempotency_key]<br \/>\n        return None<\/p>\n<p>    def store_result(self, idempotency_key, result):<br \/>\n        &#034;&#034;&#034;\u5b58\u50a8\u5904\u7406\u7ed3\u679c&#034;&#034;&#034;<br \/>\n        self.processed_requests[idempotency_key] &#061; result<br \/>\n        # \u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4&#xff08;\u598224\u5c0f\u65f6&#xff09;<br \/>\n        # &#8230;<\/p>\n<p>idempotency_mgr &#061; IdempotencyManager()<\/p>\n<p>&#064;app.route(&#039;\/api\/orders&#039;, methods&#061;[&#039;POST&#039;])<br \/>\ndef create_order():<br \/>\n    # \u68c0\u67e5\u5e42\u7b49\u952e<br \/>\n    idempotency_key &#061; request.headers.get(&#039;Idempotency-Key&#039;)<br \/>\n    if idempotency_key:<br \/>\n        previous_result &#061; idempotency_mgr.check_and_store(idempotency_key)<br \/>\n        if previous_result:<br \/>\n            # \u8fd4\u56de\u4e4b\u524d\u7684\u7ed3\u679c<br \/>\n            return jsonify(previous_result), 200<\/p>\n<p>    # \u5904\u7406\u8ba2\u5355\u521b\u5efa<br \/>\n    order_data &#061; request.get_json()<br \/>\n    # &#8230; \u4e1a\u52a1\u903b\u8f91 &#8230;<\/p>\n<p>    result &#061; {&#034;order_id&#034;: 456, &#034;status&#034;: &#034;created&#034;}<\/p>\n<p>    # \u5b58\u50a8\u7ed3\u679c&#xff08;\u5982\u679c\u662f\u5e42\u7b49\u8bf7\u6c42&#xff09;<br \/>\n    if idempotency_key:<br \/>\n        idempotency_mgr.store_result(idempotency_key, result)<\/p>\n<p>    return jsonify(result), 201<\/p>\n<h5>\u72b6\u6001\u7801\u4e0e\u8de8\u7ad9\u8bf7\u6c42\u4f2a\u9020&#xff08;CSRF&#xff09;\u9632\u62a4<\/h5>\n<p>\u67d0\u4e9b\u72b6\u6001\u7801\u548c\u65b9\u6cd5\u7684\u7ec4\u5408\u53ef\u80fd\u589e\u52a0CSRF\u98ce\u9669&#xff1a;<\/p>\n<p>javascript<\/p>\n<p>\/\/ \u5b89\u5168\u7684\u72b6\u6001\u7801-\u65b9\u6cd5\u7ec4\u5408<br \/>\nconst safeCombinations &#061; [<br \/>\n    { method: &#039;GET&#039;, status: 200 },   \/\/ \u5b89\u5168\u8bfb\u53d6<br \/>\n    { method: &#039;HEAD&#039;, status: 200 },  \/\/ \u5b89\u5168\u5934\u90e8<br \/>\n    { method: &#039;OPTIONS&#039;, status: 200 }, \/\/ \u5b89\u5168\u9009\u9879<br \/>\n];<\/p>\n<p>\/\/ \u9700\u8981CSRF\u9632\u62a4\u7684\u7ec4\u5408<br \/>\nconst csrfProtectedCombinations &#061; [<br \/>\n    { method: &#039;POST&#039;, status: 201 },  \/\/ \u521b\u5efa\u8d44\u6e90<br \/>\n    { method: &#039;PUT&#039;, status: 200 },   \/\/ \u66f4\u65b0\u8d44\u6e90<br \/>\n    { method: &#039;DELETE&#039;, status: 204 }, \/\/ \u5220\u9664\u8d44\u6e90<br \/>\n    { method: &#039;PATCH&#039;, status: 200 }, \/\/ \u90e8\u5206\u66f4\u65b0<br \/>\n];<\/p>\n<p>\/\/ CSRF\u9632\u62a4\u4e2d\u95f4\u4ef6<br \/>\napp.use((req, res, next) &#061;&gt; {<br \/>\n    const combination &#061; { method: req.method, status: null };<\/p>\n<p>    \/\/ \u68c0\u67e5\u662f\u5426\u9700\u8981CSRF\u9632\u62a4<br \/>\n    const needsProtection &#061; csrfProtectedCombinations.some(<br \/>\n        c &#061;&gt; c.method &#061;&#061;&#061; combination.method<br \/>\n    );<\/p>\n<p>    if (needsProtection) {<br \/>\n        \/\/ \u9a8c\u8bc1CSRF\u4ee4\u724c<br \/>\n        const csrfToken &#061; req.headers[&#039;x-csrf-token&#039;] || req.body._csrf;<br \/>\n        if (!isValidCsrfToken(csrfToken)) {<br \/>\n            return res.status(403).json({<br \/>\n                error: &#039;CSRF token validation failed&#039;<br \/>\n            });<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u6355\u83b7\u54cd\u5e94\u72b6\u6001\u7801<br \/>\n    const originalSend &#061; res.send;<br \/>\n    res.send &#061; function(body) {<br \/>\n        combination.status &#061; res.statusCode;<br \/>\n        logSecurityEvent(combination, req);<br \/>\n        originalSend.call(this, body);<br \/>\n    };<\/p>\n<p>    next();<br \/>\n});<\/p>\n<h5>\u72b6\u6001\u7801\u7684\u4fe1\u606f\u6cc4\u9732\u98ce\u9669<\/h5>\n<p>\u67d0\u4e9b\u72b6\u6001\u7801\u53ef\u80fd\u6cc4\u9732\u7cfb\u7edf\u4fe1\u606f&#xff0c;\u9700\u8981\u8c28\u614e\u5904\u7406&#xff1a;<\/p>\n<p>nginx<\/p>\n<p># Nginx\u914d\u7f6e&#xff1a;\u9690\u85cf\u654f\u611f\u4fe1\u606f<br \/>\nserver {<br \/>\n    # \u81ea\u5b9a\u4e49\u9519\u8bef\u9875\u9762&#xff0c;\u907f\u514d\u6cc4\u9732\u7ec6\u8282<br \/>\n    error_page 400 \/error\/400.html;<br \/>\n    error_page 401 \/error\/401.html;<br \/>\n    error_page 403 \/error\/403.html;<br \/>\n    error_page 404 \/error\/404.html;<br \/>\n    error_page 500 \/error\/500.html;<br \/>\n    error_page 502 \/error\/502.html;<br \/>\n    error_page 503 \/error\/503.html;<\/p>\n<p>    # \u9690\u85cf\u670d\u52a1\u5668\u7248\u672c\u4fe1\u606f<br \/>\n    server_tokens off;<\/p>\n<p>    # \u9650\u5236\u9519\u8bef\u4fe1\u606f\u7684\u8be6\u7ec6\u7a0b\u5ea6<br \/>\n    location &#061; \/error\/500.html {<br \/>\n        internal;<br \/>\n        return 500 &#034;Internal Server Error&#034;;<br \/>\n    }<br \/>\n}<\/p>\n<p>python<\/p>\n<p># Flask\u5e94\u7528&#xff1a;\u5b89\u5168\u9519\u8bef\u5904\u7406<br \/>\nfrom flask import Flask, jsonify<br \/>\nimport traceback<\/p>\n<p>app &#061; Flask(__name__)<\/p>\n<p># \u751f\u4ea7\u73af\u5883\u914d\u7f6e<br \/>\nclass ProductionConfig:<br \/>\n    DEBUG &#061; False<br \/>\n    PROPAGATE_EXCEPTIONS &#061; False<\/p>\n<p>app.config.from_object(ProductionConfig)<\/p>\n<p>&#064;app.errorhandler(404)<br \/>\ndef not_found(error):<br \/>\n    # \u751f\u4ea7\u73af\u5883&#xff1a;\u8fd4\u56de\u901a\u7528\u9519\u8bef<br \/>\n    return jsonify({<br \/>\n        &#034;error&#034;: &#034;Resource not found&#034;,<br \/>\n        &#034;code&#034;: 404<br \/>\n    }), 404<\/p>\n<p>&#064;app.errorhandler(500)<br \/>\ndef internal_error(error):<br \/>\n    # \u8bb0\u5f55\u8be6\u7ec6\u9519\u8bef\u65e5\u5fd7<br \/>\n    app.logger.error(f&#034;Internal error: {traceback.format_exc()}&#034;)<\/p>\n<p>    # \u8fd4\u56de\u901a\u7528\u9519\u8bef\u4fe1\u606f<br \/>\n    return jsonify({<br \/>\n        &#034;error&#034;: &#034;Internal server error&#034;,<br \/>\n        &#034;code&#034;: 500<br \/>\n    }), 500<\/p>\n<p># \u5f00\u53d1\u73af\u5883\u7279\u6b8a\u5904\u7406<br \/>\nif app.debug:<br \/>\n    &#064;app.errorhandler(500)<br \/>\n    def debug_internal_error(error):<br \/>\n        # \u5f00\u53d1\u73af\u5883&#xff1a;\u8fd4\u56de\u8be6\u7ec6\u9519\u8bef<br \/>\n        return jsonify({<br \/>\n            &#034;error&#034;: str(error),<br \/>\n            &#034;traceback&#034;: traceback.format_exc().splitlines(),<br \/>\n            &#034;code&#034;: 500<br \/>\n        }), 500<\/p>\n<h3>\u7b2c3\u7ae0&#xff1a;\u72b6\u6001\u7801\u7684\u8bbe\u8ba1\u54f2\u5b66\u4e0e\u5386\u53f2\u6f14\u53d8<\/h3>\n<h4>3.1 \u72b6\u6001\u7801\u7684\u8bbe\u8ba1\u539f\u5219<\/h4>\n<h5>\u6b63\u4ea4\u6027\u539f\u5219&#xff08;Orthogonality&#xff09;<\/h5>\n<p>\u6b63\u4ea4\u6027\u8bbe\u8ba1\u786e\u4fdd\u6bcf\u4e2a\u72b6\u6001\u7801\u6709\u660e\u786e\u3001\u552f\u4e00\u7684\u8bed\u4e49&#xff0c;\u907f\u514d\u6b67\u4e49&#xff1a;<\/p>\n<p>\u6b63\u4ea4\u6027\u77e9\u9635\u793a\u4f8b&#xff1a;<\/p>\n<table>\n<tr>\u5173\u6ce8\u70b9\\\\\u72b6\u6001\u7801200 OK201 Created204 No Content<\/tr>\n<tbody>\n<tr>\n<td>\u8d44\u6e90\u72b6\u6001<\/td>\n<td>\u5b58\u5728\u5e76\u8fd4\u56de<\/td>\n<td>\u65b0\u521b\u5efa<\/td>\n<td>\u5b58\u5728\u4f46\u65e0\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>\u54cd\u5e94\u4f53<\/td>\n<td>\u5fc5\u987b\u6709<\/td>\n<td>\u5e94\u8be5\u6709<\/td>\n<td>\u5fc5\u987b\u65e0<\/td>\n<\/tr>\n<tr>\n<td>Location<\/td>\n<td>\u53ef\u9009<\/td>\n<td>\u5e94\u8be5\u5305\u542b<\/td>\n<td>\u4e0d\u9002\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u7f13\u5b58\u6027<\/td>\n<td>\u9ed8\u8ba4\u53ef\u7f13\u5b58<\/td>\n<td>\u9ed8\u8ba4\u4e0d\u7f13\u5b58<\/td>\n<td>\u53ef\u7f13\u5b58<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u53ef\u6269\u5c55\u6027\u539f\u5219<\/h5>\n<p>\u72b6\u6001\u7801\u8bbe\u8ba1\u9884\u7559\u4e86\u6269\u5c55\u7a7a\u95f4&#xff1a;<\/p>\n<p>abnf<\/p>\n<p>; RFC\u5b9a\u4e49\u7684\u72b6\u6001\u7801\u6269\u5c55\u6a21\u5f0f<br \/>\nstatus-code &#061; 3DIGIT<br \/>\n; \u7b2c\u4e00\u4f4d&#xff1a;1-5&#xff08;\u5df2\u5b9a\u4e49&#xff09;&#xff0c;6-9&#xff08;\u4fdd\u7559&#xff09;<br \/>\n; \u7b2c\u4e8c\u4f4d&#xff1a;0-9&#xff08;\u90e8\u5206\u6709\u7279\u5b9a\u542b\u4e49&#xff09;<br \/>\n; \u7b2c\u4e09\u4f4d&#xff1a;0-9&#xff08;\u81ea\u7531\u4f7f\u7528&#xff09;<\/p>\n<p>; \u6269\u5c55\u72b6\u6001\u7801\u793a\u4f8b&#xff08;\u975e\u6807\u51c6\u4f46\u5e38\u7528&#xff09;<br \/>\n; 5xx\u7cfb\u5217\u6269\u5c55<br \/>\n; 520: Web Server Returned an Unknown Error (Cloudflare)<br \/>\n; 521: Web Server Is Down (Cloudflare)<br \/>\n; 529: Site is overloaded (Qualys)<\/p>\n<h5>\u517c\u5bb9\u6027\u539f\u5219<\/h5>\n<p>\u72b6\u6001\u7801\u8bbe\u8ba1\u4fdd\u6301\u5411\u540e\u517c\u5bb9&#xff1a;<\/p>\n<p>python<\/p>\n<p>class StatusCodeHandler:<br \/>\n    &#034;&#034;&#034;\u5904\u7406\u65b0\u65e7\u72b6\u6001\u7801\u517c\u5bb9\u6027&#034;&#034;&#034;<\/p>\n<p>    def handle_response(self, response):<br \/>\n        status_code &#061; response.status_code<\/p>\n<p>        # \u5904\u7406\u5df2\u77e5\u72b6\u6001\u7801<br \/>\n        if status_code in self.known_codes:<br \/>\n            return self.known_codes[status_code](response)<\/p>\n<p>        # \u5904\u7406\u672a\u77e5\u72b6\u6001\u7801&#xff08;\u6309\u7c7b\u522b\u5904\u7406&#xff09;<br \/>\n        category &#061; status_code \/\/ 100<\/p>\n<p>        compatibility_map &#061; {<br \/>\n            1: self._handle_informational,<br \/>\n            2: self._handle_success,<br \/>\n            3: self._handle_redirection,<br \/>\n            4: self._handle_client_error,<br \/>\n            5: self._handle_server_error,<br \/>\n        }<\/p>\n<p>        handler &#061; compatibility_map.get(category, self._handle_unknown)<br \/>\n        return handler(response, status_code)<\/p>\n<p>    def _handle_unknown(self, response, code):<br \/>\n        &#034;&#034;&#034;\u5904\u7406\u672a\u77e5\u72b6\u6001\u7801\u7684\u517c\u5bb9\u7b56\u7565&#034;&#034;&#034;<br \/>\n        # \u8bb0\u5f55\u65e5\u5fd7<br \/>\n        logger.warning(f&#034;Unknown status code: {code}&#034;)<\/p>\n<p>        # \u6309\u7c7b\u522b\u63d0\u4f9b\u57fa\u672c\u5904\u7406<br \/>\n        category &#061; code \/\/ 100<\/p>\n<p>        if category &#061;&#061; 2:<br \/>\n            # \u672a\u77e5\u6210\u529f\u72b6\u6001\u7801&#xff0c;\u5f53\u4f5c200\u5904\u7406<br \/>\n            return self._extract_success_data(response)<br \/>\n        elif category &#061;&#061; 4:<br \/>\n            # \u672a\u77e5\u5ba2\u6237\u7aef\u9519\u8bef&#xff0c;\u5f53\u4f5c400\u5904\u7406<br \/>\n            raise ClientError(f&#034;Client error: {code}&#034;)<br \/>\n        elif category &#061;&#061; 5:<br \/>\n            # \u672a\u77e5\u670d\u52a1\u5668\u9519\u8bef&#xff0c;\u5f53\u4f5c500\u5904\u7406<br \/>\n            raise ServerError(f&#034;Server error: {code}&#034;)<br \/>\n        else:<br \/>\n            # \u5176\u4ed6\u7c7b\u522b&#xff0c;\u4f7f\u7528\u901a\u7528\u5904\u7406<br \/>\n            return self._generic_handle(response)<\/p>\n<h4>3.2 HTTP\u7248\u672c\u4e0e\u72b6\u6001\u7801\u6f14\u8fdb<\/h4>\n<h5>HTTP\/0.9 \u5230 HTTP\/1.0 \u7684\u7a81\u7834<\/h5>\n<p>HTTP\/0.9 (1991) \u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4ec5\u652f\u6301GET\u65b9\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u65e0\u5934\u90e8\u3001\u65e0\u72b6\u6001\u7801<\/p>\n<\/li>\n<li>\n<p>\u54cd\u5e94\u4ec5\u5305\u542bHTML\u6587\u6863<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u5728\u54cd\u5e94\u540e\u7acb\u5373\u5173\u95ed<\/p>\n<\/li>\n<\/ul>\n<p>\u793a\u4f8bHTTP\/0.9\u4e8b\u52a1&#xff1a;<\/p>\n<p>text<\/p>\n<p>\u5ba2\u6237\u7aef\u8bf7\u6c42: GET \/index.html<br \/>\n\u670d\u52a1\u5668\u54cd\u5e94: &lt;html&gt;&#8230;&lt;\/html&gt;<\/p>\n<p>HTTP\/1.0 (RFC 1945, 1996) \u521b\u65b0&#xff1a;<\/p>\n<li>\n<p>\u5f15\u5165\u72b6\u6001\u7801&#xff08;16\u4e2a&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6dfb\u52a0HTTP\u5934\u90e8<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u591a\u79cd\u5185\u5bb9\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u7f13\u5b58\u63a7\u5236<\/p>\n<\/li>\n<p>HTTP\/1.0\u72b6\u6001\u7801\u96c6&#xff1a;<\/p>\n<p>python<\/p>\n<p>HTTP_1_0_STATUS_CODES &#061; {<br \/>\n    200: &#034;OK&#034;,<br \/>\n    201: &#034;Created&#034;,<br \/>\n    202: &#034;Accepted&#034;,<br \/>\n    204: &#034;No Content&#034;,<br \/>\n    301: &#034;Moved Permanently&#034;,<br \/>\n    302: &#034;Moved Temporarily&#034;,  # \u540e\u6539\u4e3a302 Found<br \/>\n    304: &#034;Not Modified&#034;,<br \/>\n    400: &#034;Bad Request&#034;,<br \/>\n    401: &#034;Unauthorized&#034;,<br \/>\n    403: &#034;Forbidden&#034;,<br \/>\n    404: &#034;Not Found&#034;,<br \/>\n    500: &#034;Internal Server Error&#034;,<br \/>\n    501: &#034;Not Implemented&#034;,<br \/>\n    502: &#034;Bad Gateway&#034;,<br \/>\n    503: &#034;Service Unavailable&#034;<br \/>\n}<\/p>\n<h5>HTTP\/1.1 \u7684\u5b8c\u5584\u4e0e\u6807\u51c6\u5316<\/h5>\n<p>HTTP\/1.1 (RFC 2616, 1999) \u4e3b\u8981\u6539\u8fdb&#xff1a;<\/p>\n<li>\n<p>\u6301\u4e45\u8fde\u63a5&#xff1a;\u9ed8\u8ba4Keep-Alive<\/p>\n<\/li>\n<li>\n<p>\u5206\u5757\u4f20\u8f93&#xff1a;\u652f\u6301\u6d41\u5f0f\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>\u5185\u5bb9\u534f\u5546&#xff1a;\u66f4\u4e30\u5bcc\u7684Accept\u5934\u90e8<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u589e\u5f3a&#xff1a;\u66f4\u590d\u6742\u7684\u7f13\u5b58\u63a7\u5236<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u7801\u6269\u5c55&#xff1a;\u65b0\u589e20&#043;\u72b6\u6001\u7801<\/p>\n<\/li>\n<p>HTTP\/1.1\u65b0\u589e\u91cd\u8981\u72b6\u6001\u7801&#xff1a;<\/p>\n<p>python<\/p>\n<p>HTTP_1_1_NEW_STATUS_CODES &#061; {<br \/>\n    # \u6210\u529f\u7c7b<br \/>\n    206: &#034;Partial Content&#034;,<\/p>\n<p>    # \u91cd\u5b9a\u5411\u7c7b<br \/>\n    300: &#034;Multiple Choices&#034;,<br \/>\n    303: &#034;See Other&#034;,<br \/>\n    305: &#034;Use Proxy&#034;,<br \/>\n    306: &#034;(Unused)&#034;,<br \/>\n    307: &#034;Temporary Redirect&#034;,<\/p>\n<p>    # \u5ba2\u6237\u7aef\u9519\u8bef\u7c7b<br \/>\n    405: &#034;Method Not Allowed&#034;,<br \/>\n    406: &#034;Not Acceptable&#034;,<br \/>\n    407: &#034;Proxy Authentication Required&#034;,<br \/>\n    408: &#034;Request Timeout&#034;,<br \/>\n    409: &#034;Conflict&#034;,<br \/>\n    410: &#034;Gone&#034;,<br \/>\n    411: &#034;Length Required&#034;,<br \/>\n    412: &#034;Precondition Failed&#034;,<br \/>\n    413: &#034;Request Entity Too Large&#034;,<br \/>\n    414: &#034;Request-URI Too Long&#034;,<br \/>\n    415: &#034;Unsupported Media Type&#034;,<br \/>\n    416: &#034;Requested Range Not Satisfiable&#034;,<br \/>\n    417: &#034;Expectation Failed&#034;,<\/p>\n<p>    # \u670d\u52a1\u5668\u9519\u8bef\u7c7b<br \/>\n    505: &#034;HTTP Version Not Supported&#034;<br \/>\n}<\/p>\n<h5>HTTP\/2 \u548c HTTP\/3 \u7684\u6f14\u8fdb<\/h5>\n<p>HTTP\/2 (RFC 7540, 2015) \u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e8c\u8fdb\u5236\u5206\u5e27<\/p>\n<\/li>\n<li>\n<p>\u591a\u8def\u590d\u7528<\/p>\n<\/li>\n<li>\n<p>\u5934\u90e8\u538b\u7f29<\/p>\n<\/li>\n<li>\n<p>\u670d\u52a1\u5668\u63a8\u9001<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u7801\u8bed\u4e49\u4e0d\u53d8<\/p>\n<\/li>\n<\/ul>\n<p>HTTP\/3 (RFC 9114, 2022) \u521b\u65b0&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u57fa\u4e8eQUIC\u534f\u8bae&#xff08;UDP&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u6539\u8fdb\u7684TLS\u96c6\u6210<\/p>\n<\/li>\n<li>\n<p>\u89e3\u51b3\u961f\u5934\u963b\u585e<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u7801\u8bed\u4e49\u4fdd\u6301\u4e0d\u53d8<\/p>\n<\/li>\n<\/ul>\n<p>\u534f\u8bae\u6f14\u8fdb\u4e2d\u7684\u72b6\u6001\u7801\u517c\u5bb9\u6027&#xff1a;<\/p>\n<p>javascript<\/p>\n<p>class ProtocolAdapter {<br \/>\n    \/**<br \/>\n     * \u8de8HTTP\u7248\u672c\u7684\u72b6\u6001\u7801\u5904\u7406\u9002\u914d\u5668<br \/>\n     *\/<br \/>\n    adaptStatusCode(statusCode, httpVersion) {<br \/>\n        \/\/ \u57fa\u7840\u72b6\u6001\u7801\u5728\u6240\u6709\u7248\u672c\u4e2d\u8bed\u4e49\u4e00\u81f4<br \/>\n        const baseCodes &#061; [200, 301, 302, 304, 400, 401, 403, 404, 500, 503];<\/p>\n<p>        if (baseCodes.includes(statusCode)) {<br \/>\n            return { code: statusCode, compatible: true };<br \/>\n        }<\/p>\n<p>        \/\/ \u7248\u672c\u7279\u5b9a\u72b6\u6001\u7801\u68c0\u67e5<br \/>\n        switch (httpVersion) {<br \/>\n            case &#039;1.0&#039;:<br \/>\n                return this._checkHttp10Compatibility(statusCode);<br \/>\n            case &#039;1.1&#039;:<br \/>\n                return this._checkHttp11Compatibility(statusCode);<br \/>\n            case &#039;2&#039;:<br \/>\n            case &#039;3&#039;:<br \/>\n                return { code: statusCode, compatible: true }; \/\/ \u5168\u90e8\u517c\u5bb9<br \/>\n            default:<br \/>\n                return { code: statusCode, compatible: false };<br \/>\n        }<br \/>\n    }<\/p>\n<p>    _checkHttp10Compatibility(code) {<br \/>\n        \/\/ HTTP\/1.0\u53ea\u652f\u630116\u4e2a\u72b6\u6001\u7801<br \/>\n        const http10Codes &#061; [<br \/>\n            200, 201, 202, 204, 301, 302, 304,<br \/>\n            400, 401, 403, 404, 500, 501, 502, 503<br \/>\n        ];<\/p>\n<p>        if (http10Codes.includes(code)) {<br \/>\n            return { code, compatible: true };<br \/>\n        }<\/p>\n<p>        \/\/ \u5bf9\u4e8e\u4e0d\u652f\u6301\u7684\u72b6\u6001\u7801&#xff0c;\u964d\u7ea7\u5904\u7406<br \/>\n        const category &#061; Math.floor(code \/ 100);<br \/>\n        const fallbackCode &#061; this._getFallbackCode(category);<\/p>\n<p>        return {<br \/>\n            code: fallbackCode,<br \/>\n            compatible: false,<br \/>\n            originalCode: code,<br \/>\n            warning: &#096;HTTP\/1.0 does not support status ${code}, using ${fallbackCode}&#096;<br \/>\n        };<br \/>\n    }<br \/>\n}<\/p>\n<h4 style=\"background-color:transparent\">3.3 \u91cd\u8981RFC\u6587\u6863\u4e2d\u7684\u72b6\u6001\u7801\u6269\u5c55<\/h4>\n<h5>RFC\u6587\u6863\u6f14\u8fdb\u65f6\u95f4\u7ebf<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"684\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072540-6969e7f4ccd58.png\" width=\"3084\" \/><\/h5>\n<h5>\u5173\u952eRFC\u8be6\u7ec6\u89e3\u6790<\/h5>\n<p>RFC 6585 (2012) &#8211; Additional HTTP Status Codes<\/p>\n<p>\u65b0\u589e4\u4e2a\u72b6\u6001\u7801\u89e3\u51b3\u73b0\u4ee3Web\u5e94\u7528\u4e2d\u7684\u7279\u5b9a\u95ee\u9898&#xff1a;<\/p>\n<p>python<\/p>\n<p># RFC 6585 \u65b0\u589e\u72b6\u6001\u7801<br \/>\nRFC_6585_STATUS_CODES &#061; {<br \/>\n    428: {<br \/>\n        &#034;phrase&#034;: &#034;Precondition Required&#034;,<br \/>\n        &#034;description&#034;: &#034;\u8981\u6c42\u5148\u51b3\u6761\u4ef6&#034;,<br \/>\n        &#034;use_case&#034;: &#034;\u8981\u6c42\u8bf7\u6c42\u5305\u542b\u6761\u4ef6\u5934\u90e8\u5982If-Match&#034;,<br \/>\n        &#034;example&#034;: &#034;&#034;&#034;<br \/>\n        HTTP\/1.1 428 Precondition Required<br \/>\n        Content-Type: application\/problem&#043;json<\/p>\n<p>        {<br \/>\n          &#034;type&#034;: &#034;https:\/\/example.com\/errors\/precondition-required&#034;,<br \/>\n          &#034;title&#034;: &#034;Precondition Required&#034;,<br \/>\n          &#034;detail&#034;: &#034;This request requires a precondition header&#034;,<br \/>\n          &#034;instance&#034;: &#034;\/articles\/123&#034;<br \/>\n        }<br \/>\n        &#034;&#034;&#034;<br \/>\n    },<\/p>\n<p>    429: {<br \/>\n        &#034;phrase&#034;: &#034;Too Many Requests&#034;,<br \/>\n        &#034;description&#034;: &#034;\u8bf7\u6c42\u8fc7\u591a&#034;,<br \/>\n        &#034;use_case&#034;: &#034;\u5ba2\u6237\u7aef\u53d1\u9001\u4e86\u8fc7\u591a\u8bf7\u6c42&#xff0c;\u901f\u7387\u9650\u5236&#034;,<br \/>\n        &#034;headers&#034;: {<br \/>\n            &#034;Retry-After&#034;: &#034;\u7b49\u5f85\u91cd\u8bd5\u7684\u79d2\u6570\u6216HTTP\u65e5\u671f&#034;<br \/>\n        },<br \/>\n        &#034;example&#034;: &#034;&#034;&#034;<br \/>\n        HTTP\/1.1 429 Too Many Requests<br \/>\n        Retry-After: 3600<br \/>\n        X-RateLimit-Limit: 1000<br \/>\n        X-RateLimit-Remaining: 0<br \/>\n        X-RateLimit-Reset: 1674460800<br \/>\n        &#034;&#034;&#034;<br \/>\n    },<\/p>\n<p>    431: {<br \/>\n        &#034;phrase&#034;: &#034;Request Header Fields Too Large&#034;,<br \/>\n        &#034;description&#034;: &#034;\u8bf7\u6c42\u5934\u90e8\u5b57\u6bb5\u8fc7\u5927&#034;,<br \/>\n        &#034;use_case&#034;: &#034;\u8bf7\u6c42\u5934\u90e8\u8d85\u8fc7\u670d\u52a1\u5668\u9650\u5236&#034;,<br \/>\n        &#034;example&#034;: &#034;&#034;&#034;<br \/>\n        HTTP\/1.1 431 Request Header Fields Too Large<br \/>\n        Content-Type: text\/plain<\/p>\n<p>        Request header fields too large<br \/>\n        &#034;&#034;&#034;<br \/>\n    },<\/p>\n<p>    511: {<br \/>\n        &#034;phrase&#034;: &#034;Network Authentication Required&#034;,<br \/>\n        &#034;description&#034;: &#034;\u9700\u8981\u7f51\u7edc\u8ba4\u8bc1&#034;,<br \/>\n        &#034;use_case&#034;: &#034;\u5ba2\u6237\u7aef\u9700\u8981\u8ba4\u8bc1\u624d\u80fd\u8bbf\u95ee\u7f51\u7edc&#034;,<br \/>\n        &#034;headers&#034;: {<br \/>\n            &#034;X-Captive-Portal&#034;: &#034;portal.example.com&#034;<br \/>\n        },<br \/>\n        &#034;example&#034;: &#034;&#034;&#034;<br \/>\n        HTTP\/1.1 511 Network Authentication Required<br \/>\n        Content-Type: text\/html<\/p>\n<p>        &lt;html&gt;<br \/>\n          &lt;body&gt;<br \/>\n            &lt;h1&gt;Network Authentication Required&lt;\/h1&gt;<br \/>\n            &lt;p&gt;You need to &lt;a href&#061;&#034;https:\/\/portal.example.com\/login&#034;&gt;login&lt;\/a&gt;&lt;\/p&gt;<br \/>\n          &lt;\/body&gt;<br \/>\n        &lt;\/html&gt;<br \/>\n        &#034;&#034;&#034;<br \/>\n    }<br \/>\n}<\/p>\n<p>RFC 7725 (2016) &#8211; HTTP\u72b6\u6001\u7801451<\/p>\n<p>451\u72b6\u6001\u7801\u7528\u4e8e\u8868\u793a\u56e0\u6cd5\u5f8b\u539f\u56e0\u65e0\u6cd5\u8bbf\u95ee\u7684\u8d44\u6e90&#xff1a;<\/p>\n<p>python<\/p>\n<p>class Status451Handler:<br \/>\n    &#034;&#034;&#034;\u5904\u7406451\u72b6\u6001\u7801\u7684\u7279\u6b8a\u903b\u8f91&#034;&#034;&#034;<\/p>\n<p>    def handle_451_response(self, response):<br \/>\n        &#034;&#034;&#034;<br \/>\n        \u5904\u7406451 Unavailable For Legal Reasons\u54cd\u5e94<\/p>\n<p>        RFC\u8981\u6c42&#xff1a;<br \/>\n        1. \u5e94\u8be5\u5305\u542b\u89e3\u91ca\u6027\u4fe1\u606f<br \/>\n        2. \u53ef\u5305\u542b\u963b\u6b62\u673a\u6784\u7684\u6807\u8bc6<br \/>\n        3. \u53ef\u5305\u542b\u76f8\u5173\u6cd5\u5f8b\u5f15\u7528<br \/>\n        &#034;&#034;&#034;<\/p>\n<p>        data &#061; {<br \/>\n            &#034;status&#034;: 451,<br \/>\n            &#034;title&#034;: &#034;Unavailable For Legal Reasons&#034;,<br \/>\n            &#034;detail&#034;: response.headers.get(&#034;X-Censorship-Reason&#034;, &#034;&#034;),<br \/>\n            &#034;blocking_agency&#034;: response.headers.get(&#034;X-Blocking-Agency&#034;),<br \/>\n            &#034;legal_reference&#034;: response.headers.get(&#034;X-Legal-Reference&#034;),<br \/>\n            &#034;appeal_procedure&#034;: response.headers.get(&#034;X-Appeal-Procedure&#034;),<br \/>\n            &#034;country&#034;: response.headers.get(&#034;X-Censorship-Country&#034;)<br \/>\n        }<\/p>\n<p>        # \u8bb0\u5f55\u5ba1\u67e5\u4e8b\u4ef6<br \/>\n        self.log_censorship_event(data)<\/p>\n<p>        # \u5411\u7528\u6237\u5c55\u793a\u9002\u5f53\u4fe1\u606f<br \/>\n        return self.render_451_template(data)<\/p>\n<p>    def render_451_template(self, data):<br \/>\n        &#034;&#034;&#034;\u6e32\u67d3451\u9519\u8bef\u9875\u9762&#034;&#034;&#034;<br \/>\n        template &#061; &#034;&#034;&#034;<br \/>\n        &lt;!DOCTYPE html&gt;<br \/>\n        &lt;html&gt;<br \/>\n        &lt;head&gt;<br \/>\n            &lt;title&gt;451 Unavailable For Legal Reasons&lt;\/title&gt;<br \/>\n            &lt;style&gt;<br \/>\n                body { font-family: sans-serif; margin: 40px; }<br \/>\n                .container { max-width: 800px; margin: 0 auto; }<br \/>\n                .legal-notice {<br \/>\n                    background: #fff3cd;<br \/>\n                    border: 1px solid #ffeaa7;<br \/>\n                    padding: 20px;<br \/>\n                    margin: 20px 0;<br \/>\n                }<br \/>\n            &lt;\/style&gt;<br \/>\n        &lt;\/head&gt;<br \/>\n        &lt;body&gt;<br \/>\n            &lt;div class&#061;&#034;container&#034;&gt;<br \/>\n                &lt;h1&gt;451 Unavailable For Legal Reasons&lt;\/h1&gt;<br \/>\n                &lt;p&gt;The requested resource is not available due to legal restrictions.&lt;\/p&gt;<\/p>\n<p>                &lt;div class&#061;&#034;legal-notice&#034;&gt;<br \/>\n                    &lt;h2&gt;Legal Notice&lt;\/h2&gt;<br \/>\n                    {% if detail %}&lt;p&gt;&lt;strong&gt;Reason:&lt;\/strong&gt; {{ detail }}&lt;\/p&gt;{% endif %}<br \/>\n                    {% if blocking_agency %}&lt;p&gt;&lt;strong&gt;Blocking Agency:&lt;\/strong&gt; {{ blocking_agency }}&lt;\/p&gt;{% endif %}<br \/>\n                    {% if legal_reference %}&lt;p&gt;&lt;strong&gt;Legal Reference:&lt;\/strong&gt; {{ legal_reference }}&lt;\/p&gt;{% endif %}<br \/>\n                    {% if country %}&lt;p&gt;&lt;strong&gt;Jurisdiction:&lt;\/strong&gt; {{ country }}&lt;\/p&gt;{% endif %}<br \/>\n                &lt;\/div&gt;<\/p>\n<p>                {% if appeal_procedure %}<br \/>\n                &lt;p&gt;For more information on appeal procedures: {{ appeal_procedure }}&lt;\/p&gt;<br \/>\n                {% endif %}<br \/>\n            &lt;\/div&gt;<br \/>\n        &lt;\/body&gt;<br \/>\n        &lt;\/html&gt;<br \/>\n        &#034;&#034;&#034;<\/p>\n<p>        return render_template(template, **data)<\/p>\n<h4>3.4 \u72b6\u6001\u7801\u7684\u5b9e\u9645\u5206\u5e03\u7edf\u8ba1<\/h4>\n<h5>\u5168\u7403\u72b6\u6001\u7801\u5206\u5e03\u5206\u6790<\/h5>\n<p>\u57fa\u4e8e\u5168\u7403CDN\u548cWeb\u670d\u52a1\u5668\u7edf\u8ba1\u6570\u636e&#xff1a;<\/p>\n<p>python<\/p>\n<p>class StatusCodeStatistics:<br \/>\n    &#034;&#034;&#034;\u72b6\u6001\u7801\u7edf\u8ba1\u5206\u6790&#034;&#034;&#034;<\/p>\n<p>    def __init__(self):<br \/>\n        self.distribution &#061; {<br \/>\n            # \u6210\u529f\u7c7b (\u7ea670-80%)<br \/>\n            200: 65.5,  # \u6210\u529f<br \/>\n            201: 0.8,   # \u521b\u5efa\u6210\u529f<br \/>\n            204: 1.2,   # \u65e0\u5185\u5bb9<br \/>\n            206: 0.5,   # \u90e8\u5206\u5185\u5bb9<\/p>\n<p>            # \u91cd\u5b9a\u5411\u7c7b (\u7ea610-15%)<br \/>\n            301: 1.5,   # \u6c38\u4e45\u91cd\u5b9a\u5411<br \/>\n            302: 2.1,   # \u4e34\u65f6\u91cd\u5b9a\u5411<br \/>\n            304: 9.8,   # \u7f13\u5b58\u6709\u6548<br \/>\n            307: 0.3,   # \u4e34\u65f6\u4fdd\u6301\u65b9\u6cd5\u91cd\u5b9a\u5411<br \/>\n            308: 0.1,   # \u6c38\u4e45\u4fdd\u6301\u65b9\u6cd5\u91cd\u5b9a\u5411<\/p>\n<p>            # \u5ba2\u6237\u7aef\u9519\u8bef (\u7ea68-12%)<br \/>\n            400: 1.2,   # \u9519\u8bef\u8bf7\u6c42<br \/>\n            401: 0.8,   # \u672a\u6388\u6743<br \/>\n            403: 2.5,   # \u7981\u6b62\u8bbf\u95ee<br \/>\n            404: 6.3,   # \u672a\u627e\u5230<br \/>\n            405: 0.1,   # \u65b9\u6cd5\u4e0d\u5141\u8bb8<br \/>\n            408: 0.2,   # \u8bf7\u6c42\u8d85\u65f6<br \/>\n            409: 0.05,  # \u51b2\u7a81<br \/>\n            410: 0.08,  # \u5df2\u5220\u9664<br \/>\n            413: 0.03,  # \u8d1f\u8f7d\u8fc7\u5927<br \/>\n            414: 0.01,  # URI\u8fc7\u957f<br \/>\n            415: 0.02,  # \u4e0d\u652f\u6301\u7684\u5a92\u4f53\u7c7b\u578b<br \/>\n            429: 0.15,  # \u8bf7\u6c42\u8fc7\u591a<br \/>\n            451: 0.001, # \u6cd5\u5f8b\u539f\u56e0\u4e0d\u53ef\u7528<\/p>\n<p>            # \u670d\u52a1\u5668\u9519\u8bef (\u7ea62-5%)<br \/>\n            500: 1.8,   # \u5185\u90e8\u670d\u52a1\u5668\u9519\u8bef<br \/>\n            502: 0.3,   # \u9519\u8bef\u7f51\u5173<br \/>\n            503: 0.4,   # \u670d\u52a1\u4e0d\u53ef\u7528<br \/>\n            504: 0.2,   # \u7f51\u5173\u8d85\u65f6<br \/>\n            520: 0.05,  # Cloudflare\u672a\u77e5\u9519\u8bef<br \/>\n            521: 0.02,  # Cloudflare\u670d\u52a1\u4e0b\u7ebf<br \/>\n            522: 0.01,  # Cloudflare\u8fde\u63a5\u8d85\u65f6<br \/>\n            523: 0.005, # Cloudflare\u6765\u6e90\u4e0d\u53ef\u8fbe<br \/>\n            524: 0.008, # Cloudflare\u8d85\u65f6<\/p>\n<p>            # \u4fe1\u606f\u7c7b (\u7ea60.1%)<br \/>\n            100: 0.08,  # \u7ee7\u7eed<br \/>\n            101: 0.01,  # \u5207\u6362\u534f\u8bae<br \/>\n            103: 0.005, # \u65e9\u671f\u63d0\u793a<br \/>\n        }<\/p>\n<p>    def analyze_distribution(self):<br \/>\n        &#034;&#034;&#034;\u5206\u6790\u72b6\u6001\u7801\u5206\u5e03\u7279\u5f81&#034;&#034;&#034;<\/p>\n<p>        # \u6309\u7c7b\u522b\u6c47\u603b<br \/>\n        categories &#061; {<br \/>\n            &#039;1xx&#039;: 0, &#039;2xx&#039;: 0, &#039;3xx&#039;: 0, &#039;4xx&#039;: 0, &#039;5xx&#039;: 0<br \/>\n        }<\/p>\n<p>        for code, percentage in self.distribution.items():<br \/>\n            category &#061; f&#034;{code \/\/ 100}xx&#034;<br \/>\n            categories[category] &#043;&#061; percentage<\/p>\n<p>        # \u8ba1\u7b97\u5065\u5eb7\u5ea6\u6307\u6807<br \/>\n        total &#061; sum(self.distribution.values())<br \/>\n        success_rate &#061; categories[&#039;2xx&#039;] \/ total * 100<br \/>\n        error_rate &#061; (categories[&#039;4xx&#039;] &#043; categories[&#039;5xx&#039;]) \/ total * 100<\/p>\n<p>        return {<br \/>\n            &#039;categories&#039;: categories,<br \/>\n            &#039;success_rate&#039;: success_rate,<br \/>\n            &#039;error_rate&#039;: error_rate,<br \/>\n            &#039;top_codes&#039;: self._get_top_codes(10)<br \/>\n        }<\/p>\n<p>    def _get_top_codes(self, n):<br \/>\n        &#034;&#034;&#034;\u83b7\u53d6\u524dN\u4e2a\u6700\u5e38\u89c1\u72b6\u6001\u7801&#034;&#034;&#034;<br \/>\n        sorted_codes &#061; sorted(<br \/>\n            self.distribution.items(),<br \/>\n            key&#061;lambda x: x[1],<br \/>\n            reverse&#061;True<br \/>\n        )<br \/>\n        return sorted_codes[:n]<\/p>\n<h5>\u4e0d\u540c\u5e94\u7528\u7c7b\u578b\u7684\u72b6\u6001\u7801\u5206\u5e03<\/h5>\n<p>\u5185\u5bb9\u578b\u7f51\u7ad9&#xff08;CMS&#xff09;\u7279\u5f81&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9ad8\u6bd4\u4f8b\u7684200 OK&#xff08;60-70%&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u663e\u8457\u7684304 Not Modified&#xff08;20-30%&#xff09;<\/p>\n<\/li>\n<li>\n<p>404 Not Found\u8f83\u9ad8&#xff08;\u722c\u866b\u3001\u6b7b\u94fe&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>API\u670d\u52a1\u7279\u5f81&#xff1a;<\/p>\n<ul>\n<li>\n<p>200 OK\u4e3b\u5bfc&#xff08;70-80%&#xff09;<\/p>\n<\/li>\n<li>\n<p>201 Created\u8f83\u591a&#xff08;\u521b\u5efa\u8d44\u6e90&#xff09;<\/p>\n<\/li>\n<li>\n<p>4xx\u9519\u8bef\u6bd4\u4f8b\u8f83\u9ad8&#xff08;\u8f93\u5165\u9a8c\u8bc1&#xff09;<\/p>\n<\/li>\n<li>\n<p>429 Too Many Requests&#xff08;\u901f\u7387\u9650\u5236&#xff09;<\/p>\n<\/li>\n<\/ul>\n<p>\u7535\u5b50\u5546\u52a1\u7f51\u7ad9\u7279\u5f81&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6df7\u5408200\/304\u54cd\u5e94<\/p>\n<\/li>\n<li>\n<p>\u8f83\u9ad8\u6bd4\u4f8b\u7684\u91cd\u5b9a\u5411&#xff08;302&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u8d2d\u7269\u8f66\u76f8\u5173\u9519\u8bef&#xff08;409\u51b2\u7a81&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h5>\u72b6\u6001\u7801\u8d8b\u52bf\u5206\u6790<\/h5>\n<p>python<\/p>\n<p>class StatusCodeTrendAnalyzer:<br \/>\n    &#034;&#034;&#034;\u72b6\u6001\u7801\u8d8b\u52bf\u5206\u6790\u5668&#034;&#034;&#034;<\/p>\n<p>    def analyze_trends(self, historical_data):<br \/>\n        &#034;&#034;&#034;<br \/>\n        \u5206\u6790\u72b6\u6001\u7801\u5386\u53f2\u8d8b\u52bf<\/p>\n<p>        historical_data: \u6309\u65f6\u95f4\u5e8f\u5217\u7684\u72b6\u6001\u7801\u8ba1\u6570<br \/>\n        &#034;&#034;&#034;<\/p>\n<p>        trends &#061; {}<\/p>\n<p>        for status_code in self.important_codes:<br \/>\n            trend &#061; self._calculate_trend(<br \/>\n                historical_data[status_code]<br \/>\n            )<\/p>\n<p>            trends[status_code] &#061; {<br \/>\n                &#039;current&#039;: historical_data[status_code][-1],<br \/>\n                &#039;trend&#039;: trend[&#039;direction&#039;],<br \/>\n                &#039;change_pct&#039;: trend[&#039;percentage_change&#039;],<br \/>\n                &#039;anomaly&#039;: self._detect_anomaly(<br \/>\n                    historical_data[status_code]<br \/>\n                )<br \/>\n            }<\/p>\n<p>        return trends<\/p>\n<p>    def _calculate_trend(self, data_series):<br \/>\n        &#034;&#034;&#034;\u8ba1\u7b97\u65f6\u95f4\u5e8f\u5217\u8d8b\u52bf&#034;&#034;&#034;<br \/>\n        # \u4f7f\u7528\u7b80\u5355\u7ebf\u6027\u56de\u5f52<br \/>\n        n &#061; len(data_series)<br \/>\n        x &#061; list(range(n))<br \/>\n        y &#061; data_series<\/p>\n<p>        # \u8ba1\u7b97\u659c\u7387<br \/>\n        sum_x &#061; sum(x)<br \/>\n        sum_y &#061; sum(y)<br \/>\n        sum_xy &#061; sum(x_i * y_i for x_i, y_i in zip(x, y))<br \/>\n        sum_x2 &#061; sum(x_i ** 2 for x_i in x)<\/p>\n<p>        numerator &#061; n * sum_xy &#8211; sum_x * sum_y<br \/>\n        denominator &#061; n * sum_x2 &#8211; sum_x ** 2<\/p>\n<p>        if denominator &#061;&#061; 0:<br \/>\n            slope &#061; 0<br \/>\n        else:<br \/>\n            slope &#061; numerator \/ denominator<\/p>\n<p>        # \u5224\u65ad\u8d8b\u52bf\u65b9\u5411<br \/>\n        if slope &gt; 0.1:<br \/>\n            direction &#061; &#034;increasing&#034;<br \/>\n        elif slope &lt; -0.1:<br \/>\n            direction &#061; &#034;decreasing&#034;<br \/>\n        else:<br \/>\n            direction &#061; &#034;stable&#034;<\/p>\n<p>        # \u8ba1\u7b97\u767e\u5206\u6bd4\u53d8\u5316<br \/>\n        if data_series[0] !&#061; 0:<br \/>\n            percentage_change &#061; (<br \/>\n                (data_series[-1] &#8211; data_series[0]) \/<br \/>\n                data_series[0] * 100<br \/>\n            )<br \/>\n        else:<br \/>\n            percentage_change &#061; 0<\/p>\n<p>        return {<br \/>\n            &#039;slope&#039;: slope,<br \/>\n            &#039;direction&#039;: direction,<br \/>\n            &#039;percentage_change&#039;: percentage_change<br \/>\n        }<\/p>\n<p>    def _detect_anomaly(self, data_series):<br \/>\n        &#034;&#034;&#034;\u68c0\u6d4b\u5f02\u5e38\u6ce2\u52a8&#034;&#034;&#034;<br \/>\n        if len(data_series) &lt; 3:<br \/>\n            return False<\/p>\n<p>        # \u4f7f\u7528Z-score\u68c0\u6d4b\u5f02\u5e38<br \/>\n        mean &#061; sum(data_series) \/ len(data_series)<br \/>\n        variance &#061; sum((x &#8211; mean) ** 2 for x in data_series) \/ len(data_series)<br \/>\n        std_dev &#061; variance ** 0.5<\/p>\n<p>        if std_dev &#061;&#061; 0:<br \/>\n            return False<\/p>\n<p>        # \u6700\u8fd1\u6570\u636e\u70b9\u7684Z-score<br \/>\n        recent &#061; data_series[-1]<br \/>\n        z_score &#061; abs((recent &#8211; mean) \/ std_dev)<\/p>\n<p>        return z_score &gt; 3  # 3\u4e2a\u6807\u51c6\u5dee\u4e4b\u5916\u4e3a\u5f02\u5e38<\/p>\n<h5>\u72b6\u6001\u7801\u76d1\u63a7\u544a\u8b66\u7b56\u7565<\/h5>\n<p>yaml<\/p>\n<p># \u72b6\u6001\u7801\u76d1\u63a7\u914d\u7f6e\u793a\u4f8b<br \/>\nstatus_code_monitoring:<br \/>\n  # \u603b\u4f53\u6210\u529f\u7387\u544a\u8b66<br \/>\n  overall_success_rate:<br \/>\n    warning_threshold: 95%    # \u4f4e\u4e8e95%\u8b66\u544a<br \/>\n    critical_threshold: 90%   # \u4f4e\u4e8e90%\u7d27\u6025<\/p>\n<p>  # \u7279\u5b9a\u72b6\u6001\u7801\u9608\u503c<br \/>\n  individual_codes:<br \/>\n    404:  # \u672a\u627e\u5230<br \/>\n      warning_threshold: 5%   # \u8d85\u8fc75%\u8b66\u544a<br \/>\n      critical_threshold: 10% # \u8d85\u8fc710%\u7d27\u6025<\/p>\n<p>    500:  # \u670d\u52a1\u5668\u9519\u8bef<br \/>\n      warning_threshold: 1%   # \u8d85\u8fc71%\u8b66\u544a<br \/>\n      critical_threshold: 5%  # \u8d85\u8fc75%\u7d27\u6025<\/p>\n<p>    502:  # \u9519\u8bef\u7f51\u5173<br \/>\n      warning_threshold: 0.5% # \u8d85\u8fc70.5%\u8b66\u544a<br \/>\n      critical_threshold: 2%  # \u8d85\u8fc72%\u7d27\u6025<\/p>\n<p>    503:  # \u670d\u52a1\u4e0d\u53ef\u7528<br \/>\n      warning_threshold: 0.5% # \u8d85\u8fc70.5%\u8b66\u544a<br \/>\n      critical_threshold: 2%  # \u8d85\u8fc72%\u7d27\u6025<\/p>\n<p>    429:  # \u8bf7\u6c42\u8fc7\u591a<br \/>\n      warning_threshold: 1%   # \u8d85\u8fc71%\u8b66\u544a<br \/>\n      critical_threshold: 5%  # \u8d85\u8fc75%\u7d27\u6025<\/p>\n<p>  # \u8d8b\u52bf\u76d1\u63a7<br \/>\n  trends:<br \/>\n    sudden_increase:<br \/>\n      codes: [404, 500, 502, 503]<br \/>\n      threshold: 50%  # \u77ed\u65f6\u95f4\u5185\u589e\u957f50%\u89e6\u53d1<br \/>\n      time_window: 5m<\/p>\n<p>    sudden_decrease:<br \/>\n      codes: [200, 304]<br \/>\n      threshold: 30%  # \u77ed\u65f6\u95f4\u5185\u4e0b\u964d30%\u89e6\u53d1<br \/>\n      time_window: 5m<\/p>\n<p>  # \u5173\u8054\u76d1\u63a7<br \/>\n  correlations:<br \/>\n    &#8211; when: 404 AND 500 increase<br \/>\n      then: check_application_deployment<br \/>\n    &#8211; when: 502 AND 503 increase<br \/>\n      then: check_upstream_services<br \/>\n    &#8211; when: 429 increase<br \/>\n      then: check_rate_limits_and_bots<\/p>\n<h2><\/h2>\n<h5><\/h5>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c1\u7ae0&#xff1a;HTTP\u534f\u8bae\u4e0e\u72b6\u6001\u7801\u6982\u8ff01.1 HTTP\u534f\u8bae\u7684\u57fa\u672c\u6a21\u578bHTTP\u534f\u8bae\u7684\u6f14\u8fdb\u5386\u7a0bHTTP&#xff08;HyperText Transfer Protocol&#xff09;\u534f\u8bae\u81ea1990\u5e74\u8bde\u751f\u4ee5\u6765&#xff0c;\u5df2\u7ecf\u7ecf\u5386\u4e86\u591a\u4e2a\u7248\u672c\u7684\u6f14\u8fdb\u3002\u5176\u57fa\u672c\u6a21\u578b\u59cb\u7ec8\u4fdd\u6301\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784&#xff0c;\u4f46\u5b9e\u73b0\u7ec6\u8282\u548c\u6027\u80fd\u7279\u6027\u6709\u4e86\u663e\u8457\u6539\u8fdb\u3002HTTP\u4e8b\u52a1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;HTTP\u6d88\u606f\u7ed3\u6784\u8be6\u89e3HTTP\u6d88\u606f\u7531\u8d77\u59cb\u884c\u3001\u5934\u90e8\u5b57\u6bb5\u548c\u6d88\u606f\u4f53\u4e09\u90e8\u5206\u7ec4\u6210\u3002\u5bf9\u4e8e\u72b6\u6001\u7801&amp;#xff0c<\/p>\n","protected":false},"author":2,"featured_media":60889,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[43],"topic":[],"class_list":["post-60893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/60893.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c1\u7ae0&#xff1a;HTTP\u534f\u8bae\u4e0e\u72b6\u6001\u7801\u6982\u8ff01.1 HTTP\u534f\u8bae\u7684\u57fa\u672c\u6a21\u578bHTTP\u534f\u8bae\u7684\u6f14\u8fdb\u5386\u7a0bHTTP&#xff08;HyperText Transfer Protocol&#xff09;\u534f\u8bae\u81ea1990\u5e74\u8bde\u751f\u4ee5\u6765&#xff0c;\u5df2\u7ecf\u7ecf\u5386\u4e86\u591a\u4e2a\u7248\u672c\u7684\u6f14\u8fdb\u3002\u5176\u57fa\u672c\u6a21\u578b\u59cb\u7ec8\u4fdd\u6301\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784&#xff0c;\u4f46\u5b9e\u73b0\u7ec6\u8282\u548c\u6027\u80fd\u7279\u6027\u6709\u4e86\u663e\u8457\u6539\u8fdb\u3002HTTP\u4e8b\u52a1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;HTTP\u6d88\u606f\u7ed3\u6784\u8be6\u89e3HTTP\u6d88\u606f\u7531\u8d77\u59cb\u884c\u3001\u5934\u90e8\u5b57\u6bb5\u548c\u6d88\u606f\u4f53\u4e09\u90e8\u5206\u7ec4\u6210\u3002\u5bf9\u4e8e\u72b6\u6001\u7801&amp;#xff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/60893.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-16T07:25:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072537-6969e7f1b79a3.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60893.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/60893.html\",\"name\":\"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-16T07:25:42+00:00\",\"dateModified\":\"2026-01-16T07:25:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/60893.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/60893.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60893.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/60893.html","og_locale":"zh_CN","og_type":"article","og_title":"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c1\u7ae0&#xff1a;HTTP\u534f\u8bae\u4e0e\u72b6\u6001\u7801\u6982\u8ff01.1 HTTP\u534f\u8bae\u7684\u57fa\u672c\u6a21\u578bHTTP\u534f\u8bae\u7684\u6f14\u8fdb\u5386\u7a0bHTTP&#xff08;HyperText Transfer Protocol&#xff09;\u534f\u8bae\u81ea1990\u5e74\u8bde\u751f\u4ee5\u6765&#xff0c;\u5df2\u7ecf\u7ecf\u5386\u4e86\u591a\u4e2a\u7248\u672c\u7684\u6f14\u8fdb\u3002\u5176\u57fa\u672c\u6a21\u578b\u59cb\u7ec8\u4fdd\u6301\u5ba2\u6237\u7aef-\u670d\u52a1\u5668\u67b6\u6784&#xff0c;\u4f46\u5b9e\u73b0\u7ec6\u8282\u548c\u6027\u80fd\u7279\u6027\u6709\u4e86\u663e\u8457\u6539\u8fdb\u3002HTTP\u4e8b\u52a1\u7684\u5b8c\u6574\u751f\u547d\u5468\u671f&#xff1a;HTTP\u6d88\u606f\u7ed3\u6784\u8be6\u89e3HTTP\u6d88\u606f\u7531\u8d77\u59cb\u884c\u3001\u5934\u90e8\u5b57\u6bb5\u548c\u6d88\u606f\u4f53\u4e09\u90e8\u5206\u7ec4\u6210\u3002\u5bf9\u4e8e\u72b6\u6001\u7801&amp;#xff0c","og_url":"https:\/\/www.wsisp.com\/helps\/60893.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-16T07:25:42+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260116072537-6969e7f1b79a3.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"16 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/60893.html","url":"https:\/\/www.wsisp.com\/helps\/60893.html","name":"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-16T07:25:42+00:00","dateModified":"2026-01-16T07:25:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/60893.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/60893.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/60893.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"HTTP \u72b6\u6001\u7801\uff1a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u901a\u4fe1\u8bed\u8a00\u2014\u2014\u7b2c\u4e00\u90e8\u5206\uff1aHTTP\u72b6\u6001\u7801\u57fa\u7840\u7406\u8bba"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=60893"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60893\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/60889"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=60893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=60893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=60893"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=60893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}