0

I have the following code but httplib still treats the header 'emptyheader' as key:value pair.

h = httplib.HTTPConnection("somewhere:5000")
headers = {}
headers['emptyheader'] = None
h.request('POST', '/somewhere', '', headers)

How do I send the sane request but with a valueless header 'emptyheader'?

Will
  • 3
  • 3

2 Answers2

1

Set the header value to '':

headers['emptyheader'] = ''

would output:

emptyheader: \r\n

which is conform with the HTTP specification for message headers.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
0

No way to do it using httplib. 'headers' parameter must be a dictionary. httplib then constructs headers as colon-separated name-value pairs.

And I think requests module does the same thing.

So, as an option, try curl:

subprocess.call(['curl', '-i', '-H', '"emptyheader"', '"http://somewhere:5000/somewhere"'])

But, I'm not sure why do you need it: http headers are key:value pairs by design.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195