Skip to content

Commit

Permalink
Merge pull request #175 from igorbastosib/master
Browse files Browse the repository at this point in the history
Adding function to retrive ContentType
  • Loading branch information
viniciussanchez authored Oct 7, 2023
2 parents 4900db9 + f3f7955 commit 8ef3ac3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/RESTRequest4D.Request.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ TRequestClient = class(TInterfacedObject, IRequest)
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string; const AOptions: TRESTRequestParameterOptions = []): IRequest;
function ClearParams: IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: TStrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
Expand Down Expand Up @@ -268,6 +269,12 @@ function TRequestClient.ClearParams: IRequest;
FRESTRequest.Params.Delete(FRESTRequest.Params.ParameterByName(FParams[I]));
end;

function TRequestClient.ContentType: string;
begin
if Assigned(FRESTRequest.Params.ParameterByName('Content-Type')) then
Result := FRESTRequest.Params.ParameterByName('Content-Type').Value;
end;

function TRequestClient.ContentType(const AContentType: string): IRequest;
begin
Result := Self;
Expand Down
3 changes: 2 additions & 1 deletion src/RESTRequest4D.Request.Contract.pas
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ interface
function ClearHeaders: IRequest;
function ClearParams: IRequest;
function UserAgent(const AName: string): IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function AddCookies(const ACookies: TStrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
function AddField(const AFieldName: string; const AValue: string): IRequest; overload;
Expand Down
8 changes: 7 additions & 1 deletion src/RESTRequest4D.Request.FPHTTPClient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ TRequestFPHTTPClient = class(TInterfacedObject, IRequest)
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string): IRequest;
function ClearParams: IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: Tstrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
Expand Down Expand Up @@ -430,6 +431,11 @@ function TRequestFPHTTPClient.ClearParams: IRequest;
FParams.Clear;
end;

function TRequestFPHTTPClient.ContentType: string;
begin
Result := FHeaders.Values['Content-Type'];
end;

function TRequestFPHTTPClient.ContentType(const AContentType: string): IRequest;
begin
Result := Self;
Expand Down
8 changes: 7 additions & 1 deletion src/RESTRequest4D.Request.Indy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ TRequestIndy = class(TInterfacedObject, IRequest)
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string): IRequest;
function ClearParams: IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: TStrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
Expand Down Expand Up @@ -439,6 +440,11 @@ function TRequestIndy.ClearParams: IRequest;
FParams.Clear;
end;

function TRequestIndy.ContentType: string;
begin
Result := FIdHTTP.Request.CustomHeaders.Values['Content-Type'];
end;

function TRequestIndy.ContentType(const AContentType: string): IRequest;
begin
Result := Self;
Expand Down
8 changes: 7 additions & 1 deletion src/RESTRequest4D.Request.NetHTTP.pas
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ TRequestNetHTTP = class(TInterfacedObject, IRequest)
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string): IRequest;
function ClearParams: IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: TStrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
Expand Down Expand Up @@ -350,6 +351,11 @@ function TRequestNetHTTP.ClearParams: IRequest;
FParams.Clear;
end;

function TRequestNetHTTP.ContentType: string;
begin
Result := FNetHTTPClient.CustHeaders.Value['Content-Type'];
end;

function TRequestNetHTTP.ContentType(const AContentType: string): IRequest;
begin
Result := Self;
Expand Down
8 changes: 7 additions & 1 deletion src/RESTRequest4D.Request.Synapse.pas
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ TRequestSynapse = class(TInterfacedObject, IRequest)
function ClearHeaders: IRequest;
function AddHeader(const AName, AValue: string): IRequest;
function ClearParams: IRequest;
function ContentType(const AContentType: string): IRequest;
function ContentType(const AContentType: string): IRequest; overload;
function ContentType: string; overload;
function UserAgent(const AName: string): IRequest;
function AddCookies(const ACookies: Tstrings): IRequest;
function AddCookie(const ACookieName, ACookieValue: string): IRequest;
Expand Down Expand Up @@ -493,6 +494,11 @@ function TRequestSynapse.ClearParams: IRequest;
FParams.Clear;
end;

function TRequestSynapse.ContentType: string;
begin
Result := FHeaders.Values['Content-Type'];
end;

function TRequestSynapse.ContentType(const AContentType: string): IRequest;
begin
Result := Self;
Expand Down

0 comments on commit 8ef3ac3

Please sign in to comment.