librelist archives

« back to archive

auto HEAD request handling

auto HEAD request handling

From:
Jay Baker
Date:
2011-10-14 @ 22:06
Hi all. I read recently that Flask (or maybe Werkzeug) will handle HEAD
requests automatically if the equivalent GET request is being handled.

First, that is very cool.

Was this introduced recently, or is there some configuration required to
turn it on? I have an app that .7something and I am seeing HEAD requests
fail. I plan to upgrade anyway, but would like to get this issue sorted /
make sure I understand.

Thanks.

-- Jay

Re: [flask] auto HEAD request handling

From:
Armin Ronacher
Date:
2011-10-15 @ 08:43
Hi,

On 2011-10-15 12:06 AM, Jay Baker wrote:
> Hi all. I read recently that Flask (or maybe Werkzeug) will handle HEAD
> requests automatically if the equivalent GET request is being handled.
They should work out of the box with 0.7 or later.  Note that some WSGI 
servers might do some extra magic on top of that.

> Was this introduced recently, or is there some configuration required to
> turn it on? I have an app that .7something and I am seeing HEAD requests
> fail.
What does fail mean?


Regards,
Armin

Re: [flask] auto HEAD request handling

From:
Jay Baker
Date:
2011-10-18 @ 15:30
Sorry for the late reply ... I am getting a 500 response with the following
edited and stripped down stack trace

.../flask/app.py", line 1113, in make_response

raise ValueError('View function did not return a response')


ValueError: View function did not return a response



On Sat, Oct 15, 2011 at 3:43 AM, Armin Ronacher <armin.ronacher@active-4.com
> wrote:

> Hi,
>
> On 2011-10-15 12:06 AM, Jay Baker wrote:
> > Hi all. I read recently that Flask (or maybe Werkzeug) will handle HEAD
> > requests automatically if the equivalent GET request is being handled.
> They should work out of the box with 0.7 or later.  Note that some WSGI
> servers might do some extra magic on top of that.
>
> > Was this introduced recently, or is there some configuration required to
> > turn it on? I have an app that .7something and I am seeing HEAD requests
> > fail.
> What does fail mean?
>
>
> Regards,
> Armin
>

Re: [flask] auto HEAD request handling

From:
Jesse Dubay
Date:
2011-11-02 @ 16:44
> edited and stripped down stack trace

It would help us diagnose the problem if you posted the full stack
trace along with your view code. As a guess, you're probably doing
something like this:

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return 'asdf'
    elif request.method == 'POST':
        return 'ghjk'

and if the request method is "HEAD", no response is returned. Flask
will route the HEAD request to the view and won't throw a 405, but it
also won't lie to you about the request method.

Hope that helps!
Jesse

Re: [flask] auto HEAD request handling

From:
Jay Baker
Date:
2011-11-02 @ 17:21
Oh, I get it now. Yes, what you posted is essentially what I am looking at.
So if I add ...=='GET' or ...=='HEAD' ... then it will handle the rest?

On Wed, Nov 2, 2011 at 11:44 AM, Jesse Dubay <jesse@thefortytwo.net> wrote:

> > edited and stripped down stack trace
>
> It would help us diagnose the problem if you posted the full stack
> trace along with your view code. As a guess, you're probably doing
> something like this:
>
> @app.route('/', methods=['GET', 'POST'])
> def index():
>    if request.method == 'GET':
>        return 'asdf'
>    elif request.method == 'POST':
>        return 'ghjk'
>
> and if the request method is "HEAD", no response is returned. Flask
> will route the HEAD request to the view and won't throw a 405, but it
> also won't lie to you about the request method.
>
> Hope that helps!
> Jesse
>

Re: [flask] auto HEAD request handling

From:
Jesse Dubay
Date:
2011-11-02 @ 18:00
Yep! Alternatively, request.method in ('GET, 'HEAD'). A little more concise :)

Jesse

On Wed, Nov 2, 2011 at 10:21 AM, Jay Baker <jbaker.work@gmail.com> wrote:
> Oh, I get it now. Yes, what you posted is essentially what I am looking at.
> So if I add ...=='GET' or ...=='HEAD' ... then it will handle the rest?
>
> On Wed, Nov 2, 2011 at 11:44 AM, Jesse Dubay <jesse@thefortytwo.net> wrote:
>>
>> > edited and stripped down stack trace
>>
>> It would help us diagnose the problem if you posted the full stack
>> trace along with your view code. As a guess, you're probably doing
>> something like this:
>>
>> @app.route('/', methods=['GET', 'POST'])
>> def index():
>>    if request.method == 'GET':
>>        return 'asdf'
>>    elif request.method == 'POST':
>>        return 'ghjk'
>>
>> and if the request method is "HEAD", no response is returned. Flask
>> will route the HEAD request to the view and won't throw a 405, but it
>> also won't lie to you about the request method.
>>
>> Hope that helps!
>> Jesse
>
>

Re: [flask] auto HEAD request handling

From:
Jay Baker
Date:
2011-11-02 @ 15:11
Pinging this thread again as I am up against this one. The app in question
is running on App Engine. Does anyone know if their WSGI server might be
doing something to the head requests?

A little more detail ... it looks to me like the HEAD request is being
handled. I get a 500 response, not a 404. From the trace below, it appears
as though app.py is raising a ValueError "View did not return a response".
And I should add, these are for GET views that do work normally with a GET
request.

Thanks for any insight.

On Tue, Oct 18, 2011 at 10:30 AM, Jay Baker <jbaker.work@gmail.com> wrote:

> Sorry for the late reply ... I am getting a 500 response with the
> following edited and stripped down stack trace
>
> .../flask/app.py", line 1113, in make_response
>
> raise ValueError('View function did not return a response')
>
>
> ValueError: View function did not return a response
>
>
>
> On Sat, Oct 15, 2011 at 3:43 AM, Armin Ronacher <
> armin.ronacher@active-4.com> wrote:
>
>> Hi,
>>
>> On 2011-10-15 12:06 AM, Jay Baker wrote:
>> > Hi all. I read recently that Flask (or maybe Werkzeug) will handle HEAD
>> > requests automatically if the equivalent GET request is being handled.
>> They should work out of the box with 0.7 or later.  Note that some WSGI
>> servers might do some extra magic on top of that.
>>
>> > Was this introduced recently, or is there some configuration required to
>> > turn it on? I have an app that .7something and I am seeing HEAD requests
>> > fail.
>> What does fail mean?
>>
>>
>> Regards,
>> Armin
>>
>
>