@@ -924,7 +924,6 @@ func testServeContent(t *testing.T, mode testMode) {
924
924
wantContentType string
925
925
wantContentRange string
926
926
wantStatus int
927
- wantContent []byte
928
927
}
929
928
htmlModTime := mustStat (t , "testdata/index.html" ).ModTime ()
930
929
tests := map [string ]testCase {
@@ -1140,24 +1139,6 @@ func testServeContent(t *testing.T, mode testMode) {
1140
1139
wantStatus : 412 ,
1141
1140
wantLastMod : htmlModTime .UTC ().Format (TimeFormat ),
1142
1141
},
1143
- "uses_writeTo_if_available_and_non-range" : {
1144
- content : & panicOnNonWriterTo {seekWriterTo : strings .NewReader ("foobar" )},
1145
- serveContentType : "text/plain; charset=utf-8" ,
1146
- wantContentType : "text/plain; charset=utf-8" ,
1147
- wantStatus : StatusOK ,
1148
- wantContent : []byte ("foobar" ),
1149
- },
1150
- "do_not_use_writeTo_for_range_requests" : {
1151
- content : & panicOnWriterTo {ReadSeeker : strings .NewReader ("foobar" )},
1152
- serveContentType : "text/plain; charset=utf-8" ,
1153
- reqHeader : map [string ]string {
1154
- "Range" : "bytes=0-4" ,
1155
- },
1156
- wantContentType : "text/plain; charset=utf-8" ,
1157
- wantContentRange : "bytes 0-4/6" ,
1158
- wantStatus : StatusPartialContent ,
1159
- wantContent : []byte ("fooba" ),
1160
- },
1161
1142
}
1162
1143
for testName , tt := range tests {
1163
1144
var content io.ReadSeeker
@@ -1171,8 +1152,7 @@ func testServeContent(t *testing.T, mode testMode) {
1171
1152
} else {
1172
1153
content = tt .content
1173
1154
}
1174
- contentOut := & strings.Builder {}
1175
- for _ , method := range []string {MethodGet , MethodHead } {
1155
+ for _ , method := range []string {"GET" , "HEAD" } {
1176
1156
//restore content in case it is consumed by previous method
1177
1157
if content , ok := content .(* strings.Reader ); ok {
1178
1158
content .Seek (0 , io .SeekStart )
@@ -1198,8 +1178,7 @@ func testServeContent(t *testing.T, mode testMode) {
1198
1178
if err != nil {
1199
1179
t .Fatal (err )
1200
1180
}
1201
- contentOut .Reset ()
1202
- io .Copy (contentOut , res .Body )
1181
+ io .Copy (io .Discard , res .Body )
1203
1182
res .Body .Close ()
1204
1183
if res .StatusCode != tt .wantStatus {
1205
1184
t .Errorf ("test %q using %q: got status = %d; want %d" , testName , method , res .StatusCode , tt .wantStatus )
@@ -1213,28 +1192,10 @@ func testServeContent(t *testing.T, mode testMode) {
1213
1192
if g , e := res .Header .Get ("Last-Modified" ), tt .wantLastMod ; g != e {
1214
1193
t .Errorf ("test %q using %q: got last-modified = %q, want %q" , testName , method , g , e )
1215
1194
}
1216
- if g , e := contentOut .String (), tt .wantContent ; e != nil && method == MethodGet && g != string (e ) {
1217
- t .Errorf ("test %q using %q: got unexpected content %q, want %q" , testName , method , g , e )
1218
- }
1219
1195
}
1220
1196
}
1221
1197
}
1222
1198
1223
- type seekWriterTo interface {
1224
- io.Seeker
1225
- io.WriterTo
1226
- }
1227
-
1228
- type panicOnNonWriterTo struct {
1229
- io.Reader
1230
- seekWriterTo
1231
- }
1232
-
1233
- type panicOnWriterTo struct {
1234
- io.ReadSeeker
1235
- io.WriterTo
1236
- }
1237
-
1238
1199
// Issue 12991
1239
1200
func TestServerFileStatError (t * testing.T ) {
1240
1201
rec := httptest .NewRecorder ()
0 commit comments