Setting headers for HTTP reply

56 views
Skip to first unread message

vladac...@gmail.com

unread,
May 21, 2014, 3:15:11 AM5/21/14
to swi-p...@googlegroups.com
Hi,

I am trying to implement some CORS-enabled Web services. To do this, I need to be able to reply to an OPTIONS HTTP request with a reply having the following headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: <<list of allowed headers>>

I looked at the http_reply/3 predicate for this purpose, but I can't find any instructions/examples for how to set its arguments so that it sends a reply
with an empty body and containing (possibly among others) the headers above.

Could anyone give me some suggestions as to how to call this predicate, or how to otherwise send the described HTTP reply?


Best regards,
Vlad

Jan Wielemaker

unread,
May 21, 2014, 3:36:14 AM5/21/14
to vladac...@gmail.com, swi-p...@googlegroups.com
On 05/21/2014 09:15 AM, vladac...@gmail.com wrote:
> Hi,
>
> I am trying to implement some CORS-enabled Web services. To do this, I
> need to be able to reply to an OPTIONS HTTP request with a reply having
> the following headers:
>
> Access-Control-Allow-Origin: *
> Access-Control-Allow-Methods: GET, POST, PUT
> Access-Control-Allow-Headers: <<list of allowed headers>>
>
> I looked at the http_reply/3 predicate for this purpose, but I can't find any instructions/examples for how to set its arguments so that it sends a reply
> with an empty body and containing (possibly among others) the headers above.

Simply do this before sending the body:

format('Access-Control-Allow-Methods: GET, POST, PUT~n'),

etc.

You may wish to use library(http/http_cors). You may also need to
extend it though.

Cheers --- Jan

>
> Could anyone give me some suggestions as to how to call this predicate, or how to otherwise send the described HTTP reply?
>
> Best regards,
> Vlad
> |
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

vladac...@gmail.com

unread,
May 21, 2014, 6:01:17 AM5/21/14
to swi-p...@googlegroups.com, vladac...@gmail.com
Hi Jan,

Thank you for the suggestion. format/1 did the trick.

Best regards,
Vlad
Reply all
Reply to author
Forward
0 new messages