RESTXQ : existing annotation for response headers ?
Dear all,
When I want to set response headers (for example to force a "save as..."), I currently have to write a specific response before the response body :
<rest:response>
<http:response>
<http:header name="Content-Type" value="text/comma-separated-values; charset=utf-8"/>
<http:header name="Content-Disposition" value="attachment; filename={concat($base, '_Parthenay.csv')}"/>
</http:response>
</rest:response>Is there an annotation to set header values directly in the function declaration ?
Best regards, Fabrice
Hello Fabrice,
for the content type you can use
%output:encoding("UTF-8") %output:media-type("text/comma-separated-values")
I don't think there is an annotation for content disposition as it is too specific. However, if you open the link in a new tab most browser should automatically try to download them. We also deliver csv files in a project via the same mechanism and I didn't encounter any problems in major browsers.
Cheers Dirk
Quoted text · Etanchaud Fabrice · 37 lines
On 11/30/2015 03:07 PM, Etanchaud Fabrice wrote: > > Dear all, > > > > When I want to set response headers (for example to force a “save as…”), > > I currently have to write a specific response before the response body : > > > > <rest:response> > > <http:response> > > <http:header name="Content-Type" > value="text/comma-separated-values; charset=utf-8"/> > > <http:header name="Content-Disposition" value="attachment; > filename={concat($base, '_Parthenay.csv')}"/> > > </http:response> > > </rest:response> > > > > Is there an annotation to set header values directly in the function > declaration ? > > > > Best regards, > > Fabrice >
Hi Fabrice,
There is currently no way to specify these headers via annotations. It may indeed be tricky, because there are many cases in which the headers are dynamically generated (such as in your example: concat(..)).
Did you try the web:response-header function [1]?
Cheers, Christian
[1] http://docs.basex.org/wiki/Web_Module#web:response-header
Quoted text · Etanchaud Fabrice · 36 lines
On Mon, Nov 30, 2015 at 3:07 PM, Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> wrote: > Dear all, > > > > When I want to set response headers (for example to force a “save as…”), > > I currently have to write a specific response before the response body : > > > > <rest:response> > > <http:response> > > <http:header name="Content-Type" value="text/comma-separated-values; > charset=utf-8"/> > > <http:header name="Content-Disposition" value="attachment; > filename={concat($base, '_Parthenay.csv')}"/> > > </http:response> > > </rest:response> > > > > Is there an annotation to set header values directly in the function > declaration ? > > > > Best regards, > > Fabrice
Hello Dirk and Christian,
Thank you for your - as usual ! - fast reply.
web:response-header is exactly the function I was about to reinvent...
and you are right Christian, I should have realized that annotation would not help, since my header value is dynamically computed...
Have a nice week !
Regards, Fabrice
-----Message d'origine-----
Quoted text · Christian Grün · 49 lines
De : Christian Grün [mailto:christian.gruen at gmail.com] Envoyé : lundi 30 novembre 2015 15:15 À : Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> Cc : basex-talk at mailman.uni-konstanz.de Objet : Re: [basex-talk] RESTXQ : existing annotation for response headers ? Hi Fabrice, There is currently no way to specify these headers via annotations. It may indeed be tricky, because there are many cases in which the headers are dynamically generated (such as in your example: concat(..)). Did you try the web:response-header function [1]? Cheers, Christian [1] http://docs.basex.org/wiki/Web_Module#web:response-header On Mon, Nov 30, 2015 at 3:07 PM, Etanchaud Fabrice <Fabrice.Etanchaud at horanet.com> wrote: > Dear all, > > > > When I want to set response headers (for example to force a “save > as…”), > > I currently have to write a specific response before the response body : > > > > <rest:response> > > <http:response> > > <http:header name="Content-Type" > value="text/comma-separated-values; > charset=utf-8"/> > > <http:header name="Content-Disposition" value="attachment; > filename={concat($base, '_Parthenay.csv')}"/> > > </http:response> > > </rest:response> > > > > Is there an annotation to set header values directly in the function > declaration ? > > > > Best regards, > > Fabrice
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.