web:response-header & Set-Cookie
Tuesday, 18 September 2018 · 2 messages
BB
Bogdan Bogucki18 Sep 2018 00:30 #
Hello,
When I try invoke following code:
return (
web:response-header( map { 'media-type':
web:content-type($path) },
map { 'Cache-Control': 'max-age=3600,public' },
map { 'Set-Cookie': 'JSESSIONID=' || session:id() || ';max-age=1800' }
), file:read-binary($path)}
I receive error:
[XPTY0004] Unknown option 'Set-Cookie'.
I am able to set cookie using <rest:response>.
Following code is working:
return (
<rest:response>
<http:response status="200" message="OK">
<http:header name="media-type" value="{web:content-type($path)}"/>
<http:header name="Content-Type" value="text/html"/>
<http:header name="Cache-Control" value="max-age=3600,public"/>
<http:header name="Set-Cookie" value="{'JSESSIONID=' || session:id()
|| ';max-age=1800'}"/>
</http:response>
</rest:response>,
file:read-binary($path))
I think function
web:response-header should allow set cookie.
Regards
Bogdan BoguckiML
Marco Lettere18 Sep 2018 09:40 #
Hi Bogdan,
I assume the last map is for options only. All headers should go into the second map.
Try with:
return (
web:response-header( map { 'media-type':
web:content-type($path) },
map { 'Cache-Control': 'max-age=3600,public', 'Set-Cookie': 'JSESSIONID=' || session:id() || ';max-age=1800' },
map { 'status' : 200}
), file:read-binary($path)}
Quoted text · Bogdan Bogucki · 59 lines
On 18/09/2018 00:30, Bogdan Bogucki wrote: > > Hello, > > When I try invoke following code: > > return ( > > web:response-header( > > map { 'media-type': web:content-type($path) }, > > map { 'Cache-Control': 'max-age=3600,public' }, > > map { 'Set-Cookie': 'JSESSIONID=' || session:id() || > ';max-age=1800' } > > ), > > file:read-binary($path) > > } > > I receive error: > > [XPTY0004] Unknown option 'Set-Cookie'. > > I am able to set cookie using <rest:response>. > > Following code is working: > > return ( > > <rest:response> > > <http:response status="200" message="OK"> > > <http:header name="media-type" value="{web:content-type($path)}"/> > > <http:header name="Content-Type" value="text/html"/> > > <http:header name="Cache-Control" value="max-age=3600,public"/> > > <http:header name="Set-Cookie" value="{'JSESSIONID=' || > session:id() || ';max-age=1800'}"/> > > </http:response> > > </rest:response>, > > file:read-binary($path) > > ) > > I think function web:response-header should allow set cookie. > > Regards > Bogdan Bogucki >
Written for BaseX 9.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery