सामान्य 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 हेडर के नाम में बड़े-छोटे अक्षर का फ़र्क होता है?
- नहीं। विनिर्देश के अनुसार हेडर नाम case-sensitive नहीं होते, इसलिए Content-Type और content-type एक ही हैं। Title-Case केवल परंपरा है।
- Host हेडर क्या करता है?
- Host सर्वर को बताता है कि अनुरोध किस डोमेन के लिए है। HTTP/1.1 में यह अनिवार्य है और एक सर्वर को नाम से कई साइटें होस्ट करने देता है।
- हेडर से कैश कैसे काम करता है?
- Cache-Control तय करता है कि उत्तर कितनी देर कैश किया जा सकता है; ETag व If-None-Match से क्लाइंट पूछता है 'क्या बदला?' और बिना बदले हल्का 304 Not Modified मिलता है।