unit XData.Web.Request;

interface

uses
  XData.Web.Headers;

type
  JSValue = type Variant;

  IHttpRequest = interface
  ['{782AF543-EFEB-4DA5-AC25-842DF76723A0}']
    function GetMethod: string;
    procedure SetMethod(const Value: string);
    function GetUri: string;
    procedure SetUri(const Value: string);
    function GetHeaders: THttpHeaders;
    function GetContent: JSValue;
    procedure SetContent(const Value: JSValue);
    property Method: string read GetMethod write SetMethod;
    property Uri: string read GetUri write SetUri;
    property Headers: THttpHeaders read GetHeaders;
    property Content: JSValue read GetContent write SetContent;
  end;

  THttpRequest = class(TInterfacedObject, IHttpRequest)
  private
    FMethod: string;
    FUri: string;
    FHeaders: THttpHeaders;
    FContent: JSValue;
    function GetMethod: string;
    procedure SetMethod(const Value: string);
    function GetUri: string;
    procedure SetUri(const Value: string);
    function GetHeaders: THttpHeaders;
    function GetContent: JSValue;
    procedure SetContent(const Value: JSValue);
  public
    constructor Create; reintroduce;
    destructor Destroy; override;
    property Method: string read GetMethod write SetMethod;
    property Uri: string read GetUri write SetUri;
    property Headers: THttpHeaders read GetHeaders;
    property Content: JSValue read GetContent write SetContent;
  end;

implementation

uses
  SysUtils;

{ THttpRequest }

constructor THttpRequest.Create;
begin
  FHeaders := THttpHeaders.Create;
end;

destructor THttpRequest.Destroy;
begin
  FHeaders.Free;
  inherited;
end;

function THttpRequest.GetContent: JSValue;
begin
  Result := FContent;
end;

function THttpRequest.GetHeaders: THttpHeaders;
begin
  Result := FHeaders;
end;

function THttpRequest.GetMethod: string;
begin
  Result := FMethod;
end;

function THttpRequest.GetUri: string;
begin
  Result := FUri;
end;

procedure THttpRequest.SetContent(const Value: JSValue);
begin
  FContent := Value;
end;

procedure THttpRequest.SetMethod(const Value: string);
begin
  FMethod := UpperCase(Value);
end;

procedure THttpRequest.SetUri(const Value: string);
begin
  FUri := Value;
end;

end.
