On 13 Dec 2014, at 19:52, Raja Naresh <[email protected]> wrote:
> Hello Everyone, 
> 
> Is there a way I can handle HTTP OPTIONS request in pyramid? I am trying to 
> make a CORS request with a custom header hence it's preflighted and I want to 
> handle the HTTP OPTIONS request. Any kind of help is appreciated. Thank you.

Handling OPTIONS is no different than handling any other request method as fast 
as Pyramid is concerned. The simplest way to do that is to specify the 
request_method parameter for the view_config decorator:

@view_config(route_name=‘my-route’, request_method=‘OPTIONS’, 
renderer=’string'):
def my_route_options(context, request):
    request.response.headers.update({
        ‘Access-Control-Allow-Methods’: ‘POST,GET,OPTIONS’,
        ‘Access-Control-Allow-Credentials’: ‘true’})
    return ''


If you are writing a REST backend you may also want to look at rest-toolkit 
(see http://rest-toolkit.readthedocs.org/en/latest/ 
<http://rest-toolkit.readthedocs.org/en/latest/> ) which will automatically 
handle OPTIONS for you.

Regards,
Wichert.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to