kennethreitz/requests — pull request #1684 by dandavison (2013-10-17 16:38:46+00:00)
Title: Raise error instead of using invalid user-supplied content-type

#### Problem

When making a POST request with the `files` argument, one should not specify the `'content-type'` header. This is because internally, requests forms the content-type header with a boundary string matching that used in the body; if this boundary string is not present in the header then there will be a server-side error. However, if the user does supply a content-type header, then although requests still forms the correct header internally, it silently drops it in favor of the user-supplied header, which it knows to be invalid, because the user has no way of knowing the boundary string that requests will send in the body.

#### Example

```python
from test_requests import httpbin
import requests
url = httpbin('post')
with open('requirements.txt') as f:
resp = requests.post(url, files={'some': f},
headers={'content-type': 'multipart/form-data'})
resp.raise_for_status()

# requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR
```

#### Proposed fix

This PR raises an exception if the user attempts to supply a value for the `'content-type'` header when making a POST request with the `files` argument.

The example above now results in a client-side `ValueError`:

```python
# ValueError: 'content-type' should not be specified in headers dict when using the `files` argument.
```