@@ -47,8 +47,8 @@ public async Task WriteAsync(OutputFormatterWriteContext context)
47
47
{
48
48
ArgumentGuard . NotNull ( context , nameof ( context ) ) ;
49
49
50
+ HttpRequest request = context . HttpContext . Request ;
50
51
HttpResponse response = context . HttpContext . Response ;
51
- response . ContentType = _serializer . ContentType ;
52
52
53
53
await using TextWriter writer = context . WriterFactory ( response . Body , Encoding . UTF8 ) ;
54
54
string responseContent ;
@@ -67,23 +67,27 @@ public async Task WriteAsync(OutputFormatterWriteContext context)
67
67
response . StatusCode = ( int ) errorDocument . GetErrorStatusCode ( ) ;
68
68
}
69
69
70
- bool hasMatchingETag = SetETagResponseHeader ( context . HttpContext . Request , response , responseContent ) ;
70
+ bool hasMatchingETag = SetETagResponseHeader ( request , response , responseContent ) ;
71
71
72
72
if ( hasMatchingETag )
73
73
{
74
74
response . StatusCode = ( int ) HttpStatusCode . NotModified ;
75
75
responseContent = string . Empty ;
76
76
}
77
77
78
- if ( context . HttpContext . Request . Method == HttpMethod . Head . Method )
78
+ if ( request . Method == HttpMethod . Head . Method )
79
79
{
80
80
responseContent = string . Empty ;
81
81
}
82
82
83
- string url = context . HttpContext . Request . GetEncodedUrl ( ) ;
83
+ string url = request . GetEncodedUrl ( ) ;
84
84
85
- _traceWriter . LogMessage ( ( ) =>
86
- $ "Sending { response . StatusCode } response for { context . HttpContext . Request . Method } request at '{ url } ' with body: <<{ responseContent } >>") ;
85
+ if ( ! string . IsNullOrEmpty ( responseContent ) )
86
+ {
87
+ response . ContentType = _serializer . ContentType ;
88
+ }
89
+
90
+ _traceWriter . LogMessage ( ( ) => $ "Sending { response . StatusCode } response for { request . Method } request at '{ url } ' with body: <<{ responseContent } >>") ;
87
91
88
92
await writer . WriteAsync ( responseContent ) ;
89
93
await writer . FlushAsync ( ) ;
0 commit comments