File tree Expand file tree Collapse file tree 2 files changed +14
-18
lines changed
WebApiClientCore/Attributes/ReturnAttributes Expand file tree Collapse file tree 2 files changed +14
-18
lines changed Original file line number Diff line number Diff line change 1- using System ;
2- using System . Net . Http . Headers ;
1+ using System . Net . Http . Headers ;
32using System . Threading . Tasks ;
43using WebApiClientCore . HttpContents ;
54
@@ -10,6 +9,11 @@ namespace WebApiClientCore.Attributes
109 /// </summary>
1110 public class JsonReturnAttribute : ApiReturnAttribute
1211 {
12+ /// <summary>
13+ /// text/json
14+ /// </summary>
15+ private static readonly MediaTypeHeaderValue textJson = new MediaTypeHeaderValue ( "text/json" ) ;
16+
1317 /// <summary>
1418 /// json内容的结果特性
1519 /// </summary>
@@ -35,13 +39,7 @@ public JsonReturnAttribute(double acceptQuality)
3539 /// <returns></returns>
3640 protected override bool IsMatchAcceptContentType ( MediaTypeHeaderValue ? responseContentType )
3741 {
38- var result = base . IsMatchAcceptContentType ( responseContentType ) ;
39- if ( result == false )
40- {
41- var mediaType = responseContentType ? . MediaType ;
42- result = string . Equals ( mediaType , "text/json" , StringComparison . OrdinalIgnoreCase ) ;
43- }
44- return result ;
42+ return base . IsMatchAcceptContentType ( responseContentType ) || base . IsMatchAcceptContentType ( textJson ) ;
4543 }
4644
4745 /// <summary>
Original file line number Diff line number Diff line change 1- using System ;
2- using System . Net . Http . Headers ;
1+ using System . Net . Http . Headers ;
32using System . Threading . Tasks ;
43using WebApiClientCore . HttpContents ;
54
@@ -10,6 +9,11 @@ namespace WebApiClientCore.Attributes
109 /// </summary>
1110 public class XmlReturnAttribute : ApiReturnAttribute
1211 {
12+ /// <summary>
13+ /// text/xml
14+ /// </summary>
15+ private static readonly MediaTypeHeaderValue textXml = new MediaTypeHeaderValue ( "text/xml" ) ;
16+
1317 /// <summary>
1418 /// json内容的结果特性
1519 /// </summary>
@@ -35,13 +39,7 @@ public XmlReturnAttribute(double acceptQuality)
3539 /// <returns></returns>
3640 protected override bool IsMatchAcceptContentType ( MediaTypeHeaderValue ? responseContentType )
3741 {
38- var result = base . IsMatchAcceptContentType ( responseContentType ) ;
39- if ( result == false )
40- {
41- var mediaType = responseContentType ? . MediaType ;
42- result = string . Equals ( mediaType , "text/xml" , StringComparison . OrdinalIgnoreCase ) ;
43- }
44- return result ;
42+ return base . IsMatchAcceptContentType ( responseContentType ) || base . IsMatchAcceptContentType ( textXml ) ;
4543 }
4644
4745 /// <summary>
You can’t perform that action at this time.
0 commit comments