# 178. Working with HTTP Headers

**Snippet 1: Sending Custom Headers in a Request**

```python
import requests

url = 'https://httpbin.org/get'
headers = {'User-Agent': 'my-app/1.0'}
response = requests.get(url, headers=headers)

print(response.text)
```

***

**Snippet 2: Inspecting Response Headers**

```python
import requests

url = 'https://httpbin.org/headers'
response = requests.get(url)

print("Response Headers:")
print(response.headers)
```

***

**Snippet 3: Adding Multiple Headers**

```python
import requests

url = 'https://httpbin.org/get'
headers = {
    'User-Agent': 'my-app/1.0',
    'Accept': 'application/json',
    'Authorization': 'Bearer your_token_here'
}
response = requests.get(url, headers=headers)

print(response.text)
```

***

**Snippet 4: Using Default Headers in Requests**

```python
import requests

url = 'https://httpbin.org/get'
session = requests.Session()
session.headers.update({'User-Agent': 'my-app/1.0'})

response = session.get(url)

print(response.text)
```

***

**Snippet 5: Passing Headers with POST Request**

```python
import requests

url = 'https://httpbin.org/post'
data = {'key': 'value'}
headers = {'Content-Type': 'application/json'}

response = requests.post(url, json=data, headers=headers)

print(response.text)
```

***

**Snippet 6: Extracting Specific Header from Response**

```python
import requests

url = 'https://httpbin.org/headers'
response = requests.get(url)

# Access a specific header value
content_type = response.headers.get('Content-Type')

print(f"Content-Type: {content_type}")
```

***

**Snippet 7: Handling Cookies in Headers**

```python
import requests

url = 'https://httpbin.org/cookies'
headers = {'User-Agent': 'my-app/1.0'}
cookies = {'session_id': 'your_session_id'}

response = requests.get(url, headers=headers, cookies=cookies)

print(response.text)
```

***

**Snippet 8: Setting Custom User-Agent**

```python
import requests

url = 'https://httpbin.org/user-agent'
headers = {'User-Agent': 'my-custom-user-agent/1.0'}

response = requests.get(url, headers=headers)

print(response.json())
```

***

**Snippet 9: Checking for a Specific Header in Response**

```python
import requests

url = 'https://httpbin.org/headers'
response = requests.get(url)

# Check if a specific header exists in the response
if 'Content-Type' in response.headers:
    print("Content-Type header exists")
else:
    print("Content-Type header not found")
```

***

**Snippet 10: Sending Headers with PUT Request**

```python
import requests

url = 'https://httpbin.org/put'
data = {'key': 'value'}
headers = {'Authorization': 'Bearer your_token_here'}

response = requests.put(url, json=data, headers=headers)

print(response.text)
```

***
