Workaround for webroker apache (maybe IIS) integration

This commit is contained in:
Daniele Teti 2016-12-13 15:43:32 +01:00
parent 1abd87fba4
commit 97d944a56a

View File

@ -1613,23 +1613,24 @@ begin
end; end;
function TMVCWebRequest.Body: string; function TMVCWebRequest.Body: string;
{.$IF CompilerVersion <= 27 } { .$IF CompilerVersion <= 27 }
var var
InEnc: TEncoding; InEnc: TEncoding;
Buffer: TArray<Byte>; Buffer: TArray<Byte>;
I: Integer; I: Integer;
{.$ENDIF } { .$ENDIF }
begin begin
if FBody <> '' then if FBody <> '' then
Exit(FBody); Exit(FBody);
{.$IF CompilerVersion > 29 } { .$IF CompilerVersion > 29 }
// FWebRequest.ReadTotalContent; // FWebRequest.ReadTotalContent;
// Exit(FWebRequest.Content); // Exit(FWebRequest.Content);
{.$ELSE } { .$ELSE }
// Property FWebRequest.Content is broken. It doesn't correctly decode the response body // Property FWebRequest.Content is broken. It doesn't correctly decode the response body
// considering the content charser. So, here's the fix // considering the content charser. So, here's the fix
// check http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx // check http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx
FWebRequest.ReadTotalContent;
if FCharset.IsEmpty then if FCharset.IsEmpty then
begin begin
SetLength(Buffer, 10); SetLength(Buffer, 10);
@ -1645,14 +1646,15 @@ begin
InEnc := TEncoding.GetEncoding(FCharset); InEnc := TEncoding.GetEncoding(FCharset);
end; end;
try try
SetLength(Buffer, FWebRequest.ContentLength); // SetLength(Buffer, FWebRequest.ContentLength);
FWebRequest.ReadClient(Buffer[0], FWebRequest.ContentLength); // FWebRequest.RawContent
FBody := InEnc.GetString(Buffer); // FWebRequest.ReadClient(Buffer[0], FWebRequest.ContentLength);
FBody := InEnc.GetString(FWebRequest.RawContent);
Result := FBody; Result := FBody;
finally finally
InEnc.Free; InEnc.Free;
end end
{.$ENDIF } { .$ENDIF }
end; end;
function TMVCWebRequest.BodyAs<T>(const RootProperty: string): T; function TMVCWebRequest.BodyAs<T>(const RootProperty: string): T;
@ -2063,7 +2065,7 @@ begin
begin begin
Context.Response.SetContentStream( Context.Response.SetContentStream(
// TStringStream.Create(UTF8Encode(AContent), TEncoding.UTF8), // TStringStream.Create(UTF8Encode(AContent), TEncoding.UTF8),
TStringStream.Create({UTF8Encode(}AContent{)}, TEncoding.UTF8), TStringStream.Create( { UTF8Encode( } AContent { ) } , TEncoding.UTF8),
lContentType); lContentType);
// Context.Response.RawWebResponse.Content := ''; // Context.Response.RawWebResponse.Content := '';
// Context.Response.RawWebResponse.ContentStream := // Context.Response.RawWebResponse.ContentStream :=