librelist archives

« back to archive

how to preserve request.data

how to preserve request.data

From:
Dilshod Tadjibaev
Date:
2013-04-12 @ 03:08
How is it possible to preserve request.data? It will be empty if Flask
recognizes the mimetype according to the
documentation<http://flask.pocoo.org/docs/api/#flask.Request.stream>
.

Currently I have a need to preserve the request body to create a hmac
signature and verify an authenticity of a post request.

  ~ Dilshod Tadjibaev

Re: [flask] how to preserve request.data

From:
Andrew Kou
Date:
2013-04-12 @ 03:47
I believe that you need to directly access it via the environ in this case.

request.environ['wsgi.input']

This will likely work, but not sure if it is the best way.


On Thu, Apr 11, 2013 at 8:08 PM, Dilshod Tadjibaev <dilshod@gmail.com>wrote:

> How is it possible to preserve request.data? It will be empty if Flask
> recognizes the mimetype according to the 
documentation<http://flask.pocoo.org/docs/api/#flask.Request.stream>
> .
>
> Currently I have a need to preserve the request body to create a hmac
> signature and verify an authenticity of a post request.
>
>   ~ Dilshod Tadjibaev
>

Re: [flask] how to preserve request.data

From:
Zhao Xiaohong
Date:
2013-04-12 @ 05:04
See this snippet from Armin's [Advanced Flask Patterns](1) slide:

from flask import Flask, Request

class SimpleRequest(Request):
    want_form_data_parsed = False
    data = None

app = Flask(__name__)
app.request_class = SimpleRequest

1: http://www.pocoo.org/~blackbird/AdvFlaskPatterns.pdf

This is documented at

http://werkzeug.pocoo.org/docs/wrappers/#werkzeug.wrappers.BaseRequest.want_form_data_parsed



On Fri, Apr 12, 2013 at 11:47 AM, Andrew Kou <andrew.kou@gmail.com> wrote:

> I believe that you need to directly access it via the environ in this case.
>
> request.environ['wsgi.input']
>
> This will likely work, but not sure if it is the best way.
>
>
> On Thu, Apr 11, 2013 at 8:08 PM, Dilshod Tadjibaev <dilshod@gmail.com>wrote:
>
>> How is it possible to preserve request.data? It will be empty if Flask
>> recognizes the mimetype according to the 
documentation<http://flask.pocoo.org/docs/api/#flask.Request.stream>
>> .
>>
>> Currently I have a need to preserve the request body to create a hmac
>> signature and verify an authenticity of a post request.
>>
>>   ~ Dilshod Tadjibaev
>>
>
>


-- 
* Zhao Xiaohong

Re: [flask] how to preserve request.data

From:
Dilshod Tadjibaev
Date:
2013-04-12 @ 06:35
I suppose with this approach I would have to call "
werkzeug.formparser.parse_form_data" on stored stream data.

I think fundamentally the problem for me is that once the steam is read you
cannot seek back (see this
doc<http://werkzeug.pocoo.org/docs/request_data/#how-does-it-parse>
).

So I have to store the stream into StringIO as Andrew Kou pointed out and
set it back.

  ~ Dilshod


On Thu, Apr 11, 2013 at 10:04 PM, Zhao Xiaohong <mrluanma@gmail.com> wrote:

> See this snippet from Armin's [Advanced Flask Patterns](1) slide:
>
> from flask import Flask, Request
>
> class SimpleRequest(Request):
>     want_form_data_parsed = False
>     data = None
>
> app = Flask(__name__)
> app.request_class = SimpleRequest
>
> 1: http://www.pocoo.org/~blackbird/AdvFlaskPatterns.pdf
>
> This is documented at
> 
http://werkzeug.pocoo.org/docs/wrappers/#werkzeug.wrappers.BaseRequest.want_form_data_parsed
>
>
>
> On Fri, Apr 12, 2013 at 11:47 AM, Andrew Kou <andrew.kou@gmail.com> wrote:
>
>> I believe that you need to directly access it via the environ in this
>> case.
>>
>> request.environ['wsgi.input']
>>
>> This will likely work, but not sure if it is the best way.
>>
>>
>> On Thu, Apr 11, 2013 at 8:08 PM, Dilshod Tadjibaev <dilshod@gmail.com>wrote:
>>
>>> How is it possible to preserve request.data? It will be empty if Flask
>>> recognizes the mimetype according to the 
documentation<http://flask.pocoo.org/docs/api/#flask.Request.stream>
>>> .
>>>
>>> Currently I have a need to preserve the request body to create a hmac
>>> signature and verify an authenticity of a post request.
>>>
>>>   ~ Dilshod Tadjibaev
>>>
>>
>>
>
>
> --
> * Zhao Xiaohong
>