Skip to content

Commit

Permalink
Issue #100: introduced a way to send a redirect to the client browser…
Browse files Browse the repository at this point in the history
… through IMARSResponse interface. (#101)
  • Loading branch information
andrea-magni authored Nov 19, 2020
1 parent ef688d7 commit 95c314a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/MARS.Core.RequestAndResponse.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface
procedure SetContent(const AContent: string);
procedure SetHeader(const AName, AValue: string);
procedure SetCookie(const AName, AValue, ADomain, APath: string; const AExpiration: TDateTime; const ASecure: Boolean);
procedure RedirectTo(const AURL: string);

property Content: string read GetContent write SetContent;
property ContentStream: TStream read GetContentStream write SetContentStream;
Expand Down
6 changes: 6 additions & 0 deletions Source/MARS.http.Server.DCS.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TMARSDCSResponse = class(TInterfacedObject, IMARSResponse)
procedure SetHeader(const AName: string; const AValue: string);
procedure SetStatusCode(const AStatusCode: Integer);
procedure SetCookie(const AName, AValue, ADomain, APath: string; const AExpiration: TDateTime; const ASecure: Boolean);
procedure RedirectTo(const AURL: string);
// -------------------------------------------------------------------------
constructor Create(ADCSResponse: ICrossHttpResponse); virtual;
end;
Expand Down Expand Up @@ -582,6 +583,11 @@ function TMARSDCSResponse.GetStatusCode: Integer;
Result := FDCSResponse.StatusCode;
end;

procedure TMARSDCSResponse.RedirectTo(const AURL: string);
begin
FDCSResponse.Redirect(AURL);
end;

procedure TMARSDCSResponse.SetContent(const AContent: string);
begin
FDCSResponse.Send(AContent);
Expand Down
7 changes: 7 additions & 0 deletions Source/MARS.http.Server.Indy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ TMARSWebResponse = class(TInterfacedObject, IMARSResponse)
procedure SetHeader(const AName: string; const AValue: string); inline;
procedure SetStatusCode(const AStatusCode: Integer); inline;
procedure SetCookie(const AName, AValue, ADomain, APath: string; const AExpiration: TDateTime; const ASecure: Boolean); inline;
procedure RedirectTo(const AURL: string);
// -------------------------------------------------------------------------
constructor Create(AWebResponse: TWebResponse); virtual;
end;
Expand Down Expand Up @@ -525,6 +526,12 @@ function TMARSWebResponse.GetStatusCode: Integer;
Result := FWebResponse.StatusCode;
end;

procedure TMARSWebResponse.RedirectTo(const AURL: string);
begin
FWebResponse.SendRedirect(AURL);
FWebResponse.SendResponse;
end;

procedure TMARSWebResponse.SetContent(const AContent: string);
begin
FWebResponse.Content := AContent;
Expand Down

0 comments on commit 95c314a

Please sign in to comment.