সাধারণ 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 পায়।