getting request's headers inside a Web Application
Tuesday, 15 June 2021 · 4 messages · last reply 16 Jun 2021
D
dudzikp15 Jun 2021 16:33 #
Dear all,
I do not see an option to obtain the headers from the HTTP request from inside webapp function. Just like in the example:
declare
%rest:GET
%rest:path('tests-html')
???%rest:headers('User-Agent')???
%output:method('html')
function page-main:start-empty(
???$user-agent as xs:string???
) as element(html) {
...
}
Is this possible?
BR
AB
Andy Bunce15 Jun 2021 18:07 #
Hi BR,
When called from within a WebApp this should give the result you are looking for..
*
request:header*( 'User-Agent')
See https://docs.basex.org/wiki/Request_Module#request:header
/AndyQuoted text · dudzikp at yahoo.com · 22 lines
On Tue, 15 Jun 2021 at 15:33, dudzikp at yahoo.com <dudzikp at yahoo.com> wrote: > Dear all, > > I do not see an option to obtain the headers from the HTTP request from > inside webapp function. Just like in the example: > > declare > %rest:GET > %rest:path('tests-html') > ???%rest:headers('User-Agent')??? > %output:method('html') > function page-main:start-empty( > ???$user-agent as xs:string??? > ) as element(html) { > ... > } > > Is this possible? > > > BR >
CG
Hi BR,
You can also use the %rest:header-param annotation:
declare
%rest:path('/test')
%rest:header-param('User-Agent', '{$agent}')
function local:test($agent) {
element agent { $agent }
};Check out [1] for "User-Agent" and additional examples.
Best,
Christian
[1] https://docs.basex.org/wiki/RESTXQ
Quoted text · dudzikp at yahoo.com · 21 lines
On Tue, Jun 15, 2021 at 4:33 PM dudzikp at yahoo.com <dudzikp at yahoo.com> wrote: > > Dear all, > > I do not see an option to obtain the headers from the HTTP request from inside webapp function. Just like in the example: > > declare > %rest:GET > %rest:path('tests-html') > ???%rest:headers('User-Agent')??? > %output:method('html') > function page-main:start-empty( > ???$user-agent as xs:string??? > ) as element(html) { > ... > } > > Is this possible? > > > BR
D
dudzikp16 Jun 2021 09:06 #
Thanks guys! I have no idea how I missed that.
BR
Quoted text · Christian Grün · 1 line
On Tuesday, June 15, 2021, 6:21:34 PM GMT+2, Christian Grün <christian.gruen at gmail.com> wrote:
Hi BR,
You can also use the %rest:header-param annotation:
declare
%rest:path('/test')
%rest:header-param('User-Agent', '{$agent}')
function local:test($agent) {
element agent { $agent }
};Check out [1] for "User-Agent" and additional examples.
Best,
Christian
[1] https://docs.basex.org/wiki/RESTXQ
Quoted text · dudzikp at yahoo.com · 21 lines
On Tue, Jun 15, 2021 at 4:33 PM dudzikp at yahoo.com <dudzikp at yahoo.com> wrote: > > Dear all, > > I do not see an option to obtain the headers from the HTTP request from inside webapp function. Just like in the example: > > declare > %rest:GET > %rest:path('tests-html') > ???%rest:headers('User-Agent')??? > %output:method('html') > function page-main:start-empty( > ???$user-agent as xs:string??? > ) as element(html) { > ... > } > > Is this possible? > > > BR
Written for BaseX 9.5. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery