Hi Elina,  (cc: basex-talk)

Happy to help. That email correspondence is a bit old, and the code
referenced is ancient. I suspect your problems creating the headers in
XQuery restxq are due to default namespace prefix changes, rest vs restxq,
way back when.

You are correct that enabling the supplied CORS filter in web.xml works for
GET and POST but not PUT.
The reason is that PUT is not in the default AllowedMethods [1]

As an exercise I have created a little sample that uses only RESTXQ
facilities. [2] It assumes the web.xml CORS filter is not enabled.

As supplied it has:
A cors.html file, to be opened directly in the browser, i.e. using the file
protocol.
A cors.xqm intended to be put in the webapp folder of a local basexhttp
running on 8984

Only the PUT request is allowed as I have commented out the Xquery
generation of the CORS headers for GET and POST.
Note PUT is a non-simple CORS request and will result in the browser
sending an additional request using the OPTIONS method [3]
This can be seen in the screenshot and is handled in the cors.xqm code.

Hope this helps
/Andy

[1]
https://www.eclipse.org/jetty/documentation/current/cross-origin-filter.html
[2] https://gist.github.com/apb2006/ea6a901a570b04f94e0e0e21098a5402
[3]
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Preflighted_requests

[image: image.png]

On Fri, 7 Aug 2020 at 13:53, Elina Koskentalo <ekosk...@gmail.com> wrote:

> Hello Andy,
>
> I hope you don't mind me contacting you, I found this email corresponding
> between you and another person about BaseX and adding
> the Access-Control-Allow-Origin header to the response.
> https://mailman.uni-konstanz.de/pipermail/basex-talk/2017-February/011782.html
>
> I have a very similar issue than what you are talking about there. I don't
> manage to define a rule in the restxq file that would simply add
> Access-Control-Allow-Origin header to or requests. I already manipulated
> the filters in the web.xml file which now works for GET but for PUT I still
> get the CORS issue back.
>
> Would you have any tips for me? Thank you very much in advance!
>
> Best regards,
> Elina Koskentalo
> ekosk...@gmail.com
>

Reply via email to