Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.py obtain request headers

Tags:

python

web.py

im starting with python and web.py

im trying to build a REST api with it. i know hoy to use the basics of web.py but i still can figure a way to get the Content-Type of a request i got this post function defined:

  def POST(self,name):
        ct=web.ctx.env.get('Content-Type')
        return json.dumps({ 'body' : web.data(),'ct':ct } )

im trying to get the body data and the content type bit ct ends null

curl -H 'Accept: application/json' localhost:8080/test -d '{"a":"b"}' -H "Content-Type: application/json"

outputs

{"body": "{\"a\":\"b\"}", "ct": null}

thanks in advance

like image 471
Freaktor Avatar asked Mar 13 '13 19:03

Freaktor


1 Answers

The web.ctx.env structure gives you access to the WSGI environment variable. In WSGI apps, the content type header is named CONTENT_TYPE:

ct = web.ctx.env.get('CONTENT_TYPE')
like image 190
Martijn Pieters Avatar answered Sep 28 '22 04:09

Martijn Pieters