librelist archives

« back to archive

returning raw http (header + content )

returning raw http (header + content )

From:
bolang
Date:
2013-01-18 @ 02:26
Hi,
Is it possible to returning raw http (header + content) using flask? How?

For example : if user requesting /files/a.css, i will download a.css 
from another server and give it back to the user.
The file type will be arbitrary, can be any kind of files.
You can think it of like a proxy.

Thanks.

Re: [flask] returning raw http (header + content )

From:
Steven Kryskalla
Date:
2013-01-18 @ 02:39
On Thu, Jan 17, 2013 at 6:26 PM, bolang <boo.l4ng@gmail.com> wrote:
> Hi,
> Is it possible to returning raw http (header + content) using flask? How?

Yes, look into the Response, make_response, and send_file functions.

http://flask.pocoo.org/docs/api/#flask.Response
http://flask.pocoo.org/docs/api/#flask.make_response
http://flask.pocoo.org/docs/api/#flask.send_file

-Steve

Re: [flask] returning raw http (header + content )

From:
bolang
Date:
2013-01-18 @ 03:10
On 01/18/2013 09:39 AM, Steven Kryskalla wrote:
> On Thu, Jan 17, 2013 at 6:26 PM, bolang <boo.l4ng@gmail.com> wrote:
>> Hi,
>> Is it possible to returning raw http (header + content) using flask? How?
>
> Yes, look into the Response, make_response, and send_file functions.
>
> http://flask.pocoo.org/docs/api/#flask.Response
> http://flask.pocoo.org/docs/api/#flask.make_response

Thanks steve, make_response working fine for me.
resp = make_response(content)
for k,v in headers:
	resp.headers[k] = v
return resp

> http://flask.pocoo.org/docs/api/#flask.send_file
>
> -Steve
>