Compatibility adjustments in the new RESTClient

This commit is contained in:
João Antônio Duarte 2020-11-10 19:13:02 -03:00
parent 2871e131df
commit 8ba8213a6e
4 changed files with 29 additions and 27 deletions

View File

@ -1415,9 +1415,9 @@ end;
function TRESTClient.SendHTTPCommandWithBody(const ACommand: TMVCHTTPMethodType;
const AAccept, AContentMediaType, AContentCharset, AResource, ABody: string): IRESTResponse;
var
lBytes: TArray<Byte>;
lContentCharset: string;
lEncoding: TEncoding;
lTmpStrStream: TStringStream;
begin
Result := TRESTResponse.Create;
@ -1449,8 +1449,12 @@ begin
lEncoding := TEncoding.GetEncoding(lContentCharset);
try
lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, TEncoding.Default.GetBytes(ABody));
RawBody.WriteData(lBytes, Length(lBytes));
lTmpStrStream := TStringStream.Create(ABody, lEncoding, False);
try
RawBody.LoadFromStream(lTmpStrStream);
finally
lTmpStrStream.Free;
end
finally
lEncoding.Free;
end;

View File

@ -538,7 +538,6 @@ begin
try
fRawBody.Clear;
lBytes := TEncoding.Convert(TEncoding.Default, lEncoding, TEncoding.Default.GetBytes(aBody));
lBytes := lEncoding.GetBytes(aBody);
fRawBody.WriteData(lBytes, Length(lBytes));
SetContentType(BuildContentType(lContentType, lContentCharset));

View File

@ -66,7 +66,6 @@ procedure TMVCMustacheViewEngine.Execute(const ViewName: string; const OutputStr
var
I: Integer;
lPartialName: string;
lData: TObject;
lViewFileName: string;
lViewTemplate: RawUTF8;
lViewEngine: TSynMustache;

View File

@ -2061,24 +2061,24 @@ begin
Assert.areEqual<Integer>(HTTP_STATUS.BadRequest, res.StatusCode, 'wrong TDateTime (2)');
// Correct without 'T'
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12 12:12:12', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode, 'wrong TDateTime (3)');
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12 12:12:12');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode, 'wrong TDateTime (3)');
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.Content);
// Correct in extended form with zero UTC offset
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12T12:12:12Z', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12T12:12:12Z');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.Content);
// Correct in extended form without timezone
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12T12:12:12', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode);
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12T12:12:12');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode);
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.Content);
// Correct in extended form with timezone
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12T12:12:12.000Z', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12T12:12:12.000Z');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.Content);
// TTime, wrong and correct
res := RESTClient.Get('/typed/ttime1/121212');
@ -2092,22 +2092,22 @@ end;
procedure TServerTest.TestTypedDateTimeTypes_UTC;
var
res: IRESTResponse;
res: IMVCRESTResponse;
begin
// If no UTC zone is defined, server must assume its local time zone
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12 12:12:12', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode, 'wrong TDateTime (3)');
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12 12:12:12');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode, 'wrong TDateTime (3)');
Assert.areEqual('2016-10-12T12:12:12.000+02:00 modified from server', res.Content);
// With UTC zero offset, server must return time expressed as its local UTC
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12T12:12:12Z', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12T12:12:12Z');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.Content);
// Correct in extended form with timezone
res := RESTClient.doGET('/typed/tdatetime1/2016-10-12T12:12:12.000Z', []);
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.ResponseCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.BodyAsString);
res := RESTClient.Get('/typed/tdatetime1/2016-10-12T12:12:12.000Z');
Assert.areEqual<Integer>(HTTP_STATUS.OK, res.StatusCode);
Assert.areEqual('2016-10-12T14:12:12.000+02:00 modified from server', res.Content);
end;
procedure TBaseServerTest.DoLoginWith(UserName: string);