File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ public bool CanWriteResult(OutputFormatterCanWriteContext context)
34
34
public Task WriteAsync ( OutputFormatterWriteContext context )
35
35
{
36
36
var response = context . HttpContext . Response ;
37
- response . ContentLength = 0 ;
38
37
39
38
if ( response . StatusCode == StatusCodes . Status200OK )
40
39
{
Original file line number Diff line number Diff line change @@ -130,6 +130,26 @@ public async Task WriteAsync_WritesTheStatusCode204()
130
130
Assert . Equal ( StatusCodes . Status204NoContent , context . HttpContext . Response . StatusCode ) ;
131
131
}
132
132
133
+ [ Fact ]
134
+ public async Task WriteAsync_DoesNotHaveContentLengthSet ( )
135
+ {
136
+ // Arrange
137
+ var context = new OutputFormatterWriteContext (
138
+ new DefaultHttpContext ( ) ,
139
+ new TestHttpResponseStreamWriterFactory ( ) . CreateWriter ,
140
+ typeof ( string ) ,
141
+ @object : null ) ;
142
+
143
+ var formatter = new HttpNoContentOutputFormatter ( ) ;
144
+
145
+ // Act
146
+ await formatter . WriteAsync ( context ) ;
147
+
148
+ // Assert
149
+ // No Content responses shouldn't have a Content-Length.
150
+ Assert . Null ( context . HttpContext . Response . ContentLength ) ;
151
+ }
152
+
133
153
[ Fact ]
134
154
public async Task WriteAsync_ContextStatusCodeSet_WritesSameStatusCode ( )
135
155
{
You can’t perform that action at this time.
0 commit comments