@@ -45,6 +45,7 @@ interface
4545 System.SysUtils,
4646 System.TypInfo,
4747 System.IOUtils,
48+ System.SysConst,
4849 System.SyncObjs,
4950 System.DateUtils,
5051 System.Generics.Collections,
@@ -470,6 +471,7 @@ TMVCWebResponse = class
470471 function GetStatusCode : Integer;
471472 function GetCookies : TCookieCollection;
472473 function GetContentType : string;
474+ function GetContentEncoding : string;
473475 function GetLocation : string;
474476 function GetContent : string;
475477 procedure SetReasonString (const AValue: string);
@@ -487,6 +489,7 @@ TMVCWebResponse = class
487489 property StatusCode: Integer read GetStatusCode write SetStatusCode;
488490 property ReasonString: string read GetReasonString write SetReasonString;
489491 property ContentType: string read GetContentType write SetContentType;
492+ property ContentEncoding: string read GetContentEncoding;
490493 property CustomHeaders: TStrings read GetCustomHeaders;
491494 property Cookies: TCookieCollection read GetCookies;
492495 property Location: string read GetLocation write SetLocation;
@@ -1317,7 +1320,6 @@ implementation
13171320 IdURI,
13181321 IdStack,
13191322 System.StrUtils,
1320- System.SysConst,
13211323 sqids,
13221324 MVCFramework.SysControllers,
13231325 MVCFramework.Serializer.JsonDataObjects,
@@ -2050,9 +2052,14 @@ function TMVCWebResponse.GetContent: string;
20502052 Result := FWebResponse.Content;
20512053end ;
20522054
2055+ function TMVCWebResponse.GetContentEncoding : string;
2056+ begin
2057+ Result := FWebResponse.ContentEncoding;
2058+ end ;
2059+
20532060function TMVCWebResponse.GetContentType : string;
20542061begin
2055- Result := FWebResponse.ContentType;
2062+ Result := BuildContentType( FWebResponse.ContentType, FWebResponse.ContentEncoding) ;
20562063end ;
20572064
20582065function TMVCWebResponse.GetCookies : TCookieCollection;
@@ -2087,14 +2094,13 @@ procedure TMVCWebResponse.SetContent(const AValue: string);
20872094
20882095procedure TMVCWebResponse.SetContentStream (const AStream: TStream; const AContentType: string);
20892096begin
2090- ContentType := AContentType;
20912097 FWebResponse.ContentStream := AStream;
2098+ ContentType := AContentType;
20922099end ;
20932100
20942101procedure TMVCWebResponse.SetContentType (const AValue: string);
20952102begin
2096- FWebResponse.ContentType := ' ' ;
2097- FWebResponse.ContentType := AValue;
2103+ FWebResponse.ContentType := aValue;
20982104end ;
20992105
21002106procedure TMVCWebResponse.SetCustomHeader (const AName, AValue: string);
@@ -4015,6 +4021,7 @@ constructor TMVCRenderer.Create;
40154021 inherited ;
40164022 FContext := nil ;
40174023 FContentCharset := TMVCConstants.DEFAULT_CONTENT_CHARSET;
4024+ FContentMediaType := TMVCConstants.DEFAULT_CONTENT_TYPE;
40184025 FResponseStream := nil ;
40194026end ;
40204027
@@ -4319,7 +4326,9 @@ procedure TMVCController.OnBeforeAction(AContext: TWebContext; const AActionName
43194326begin
43204327 AHandled := False;
43214328 if ContentType.IsEmpty then
4322- ContentType := Config[TMVCConfigKey.DefaultContentType];
4329+ begin
4330+ ContentType := BuildContentType(Config[TMVCConfigKey.DefaultContentType], Config[TMVCConfigKey.DefaultContentCharset]);
4331+ end ;
43234332 { Implement if need be. }
43244333end ;
43254334
@@ -4400,12 +4409,13 @@ procedure TMVCRenderer.Render(const AStatusCode: Integer);
44004409procedure TMVCRenderer.Render (const AContent: string);
44014410var
44024411 lOutEncoding: TEncoding;
4412+ lWebResponse: TMVCWebResponse;
44034413begin
4414+ lWebResponse := GetContext.Response;
4415+
44044416 if SameText(TMVCCharSet.UTF_8, FContentCharset) or SameText(TMVCCharSet.UTF_8_WITHOUT_DASH, FContentCharset) then
44054417 begin
4406- GetContext
4407- .Response
4408- .SetContentStream(TStringStream.Create(AContent, gEncodingUTF8, False), GetContentType)
4418+ lWebResponse.SetContentStream(TStringStream.Create(AContent, gEncodingUTF8, False), GetContentType);
44094419 end
44104420 else
44114421 begin
0 commit comments