#1 2022-01-08 12:42:23

ttomas
Member
Registered: 2013-03-08
Posts: 135

MVCApplication add Response Header

Any hint how to add Response Header from MVCApplication.

    context := ServiceRunningContext;
    context.Request.Call^.OutHead := context.Request.Call^.OutHead + #13#10 + 'Test: test';

Trying this code from MVCApplication method, mORMot2/FPC, don't return Test Header.
I'm playing with htmx for client side (htmx.org) and need to trigger some events on client with response header.
https://htmx.org/docs/#requests
I need to send response header from mvc controller depending of business logic in mvc method.

Offline

#2 2022-01-08 13:56:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: MVCApplication add Response Header

I have just added a new "CustomOutHttpHeader" optional value, to be added to the MVC method context, which will be used to set the HTTP output headers.

See https://github.com/synopse/mORMot2/commit/51608b02

Offline

#3 2022-01-08 18:40:23

ttomas
Member
Registered: 2013-03-08
Posts: 135

Re: MVCApplication add Response Header

Thanks @ab, this will solve the problem.
Can you please at line 1740 add

    if head<>'' then
      fOutput.Header := fOutput.Header + #13#10 + head;

In case when CustomOutHttpHeader := '' mvc application raise exception:
{ "errorCode":500, "errorText":"Unsafe HTTP header rejected [Content-Type: text/html; charset=UTF-8$0d$0a$0d$0aETag: \"57A6E6D8\"]" }
In same method depend of business logic I insert none, one or many response headers.

Offline

#4 2022-01-09 07:46:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: MVCApplication add Response Header

Offline

Board footer

Powered by FluxBB