כותרות HTTP נפוצות
כותרות HTTP הן זוגות של מפתח-ערך שנשלחות בתחילת כל בקשה ותשובה. הן נושאות מטא-נתונים כמו סוג התוכן, כללי מטמון ואימות. השתמשו בדף זה כדי לזהות את הכותרות הנפוצות ביותר בבנייה או באיתור באגים בתעבורת רשת.
| כותרת | כיוון | מטרה |
|---|---|---|
| Host | request | Identifies the server's host and port (from the URL). |
| User-Agent | request | Reports the client software (browser, OS, bot) making the request. |
| Accept | request | Lists the response media types (MIME) the client can handle. |
| Authorization | request | Carries credentials (token, Basic auth) to authenticate the client. |
| Content-Type | request/response | States the media type of the request or response body. |
| Content-Length | request/response | Gives the size in bytes of the request or response body. |
| Cookie | request | Sends stored key/value pairs from a previous response back to the server. |
| Set-Cookie | response | Server instructs the client to store a cookie for later requests. |
| Cache-Control | request/response | Directs caching behaviour: no-cache, max-age, private, etc. |
| ETag | response | Opaque identifier for a resource version, used for revalidation. |
| If-None-Match | request | Sends an ETag; server returns 304 if the resource is unchanged. |
| Location | response | Points the client to a new URL for redirects (3xx) or created resources. |
| Access-Control-Allow-Origin | response | Permits a browser to share a response across origins (CORS). |
| X-Forwarded-For | request | Records the client IP as seen through a proxy or load balancer. |
| Referer | request | Indicates the URL of the page that linked to the requested resource. |
הערות
- שמות כותרות אינם רגישים לרישיות; לפי המוסכמה כותבים אותם בצורת Title-Case (למשל Content-Type).
- כותרות בקשה מתארות את הלקוח; כותרות תשובה מתארות את תשובת השרת.
- הדפדפן קובע כותרות רבות (כמו Host ו-Referer) באופן אוטומטי — אל תזייף אותן.
שאלות נפוצות
- מה ההבדל בין כותרת בקשה לכותרת תשובה?
- כותרות בקשה נשלחות על ידי הלקוח (דפדפן או אפליקציה) לשרת; כותרות תשובה מוחזרות על ידי השרת עם התשובה שלו. חלקן, כמו Content-Type, מופיעות בשני הצדדים.
- האם שמות כותרות HTTP רגישים לרישיות?
- לא. לפי המפרט, שמות כותרות אינם רגישים לרישיות, כלומר Content-Type ו-content-type זהים. צורת Title-Case היא רק מוסכמה.
- למה משמשת כותרת Host?
- Host מספר לשרת לאיזה דומיין מכוון הבקשה. היא חובה ב-HTTP/1.1 ומאפשרת לשרת אחד לארח אתרים רבים לפי שם.
- איך עובדת המטמון עם כותרות?
- Cache-Control קובע כמה זמן אפשר לשמור תשובה במטמון; ETag ו-If-None-Match מאפשרות ללקוח לשאול 'השתנה?' ולקבל תשובת 304 Not Modified קלה.