Jump to content
Sign in to follow this  
Lee Tony

Return run-time value to response custom headers

Recommended Posts

Hi,

 

I have a resource with GET request method return run-time value to the response custom headers. Call <Response.CustomHeaders> will prompt access violation, even though I already defined the <Response> field with <Context> attribute. Any ideas?

 

unit Unit7;

interface

uses
  MARS.Core.Attributes, MARS.Core.MediaType, MARS.Core.MessageBodyReaders,
  MARS.Core.MessageBodyWriters, MARS.Core.Response, Web.HTTPApp;

type
  [Path('resources')]
  TMARS_Resources = class
  protected
    [Context]
    Response: TWebResponse;
  public
    [GET, Produces(TMediaType.APPLICATION_JSON)]
    function GetItems: TMARSResponse;
  end;

implementation

uses
  MARS.Core.Registry;

function TMARS_Resources.GetItems: TMARSResponse;
begin
  Result := TMARSResponse.Create;
  Result.StatusCode := 200;

  Response.CustomHeaders.Values['customheader'] := 'runtimevalue'; //access violation
end;

initialization
  TMARSResourceRegistry.Instance.RegisterResource<TMARS_Resources>;
end.

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×