@@ -251,6 +251,83 @@ TEST_FIXTURE(uri_address, response_stream_large_file_stream)
251
251
}
252
252
253
253
#if !defined(__cplusplus_winrt)
254
+
255
+ template <typename CharType>
256
+ class basic_throws_buffer : public streams ::details::streambuf_state_manager<CharType>
257
+ {
258
+ public:
259
+ basic_throws_buffer () : streams::details::streambuf_state_manager<CharType>(std::ios_base::out) {}
260
+
261
+ bool can_seek () const override { return true ; }
262
+ bool has_size () const override { return false ; }
263
+ size_t buffer_size (std::ios_base::openmode) const override { return 0 ; }
264
+ void set_buffer_size (size_t , std::ios_base::openmode) override {}
265
+ size_t in_avail () const override { return 0 ; }
266
+ pos_type getpos (std::ios_base::openmode) const override { return 0 ; }
267
+ pos_type seekpos (pos_type, std::ios_base::openmode) { return 0 ; }
268
+ pos_type seekoff (off_type, std::ios_base::seekdir, std::ios_base::openmode) override { return 0 ; }
269
+ bool acquire (_Out_writes_(count) CharType*&, _In_ size_t&) override { return false ; }
270
+ void release (_Out_writes_(count) CharType *, _In_ size_t) override {}
271
+
272
+ protected:
273
+ pplx::task<int_type> _putc (CharType) override { throw std::runtime_error (" error" ); }
274
+ pplx::task<size_t > _putn (const CharType *, size_t ) override { throw std::runtime_error (" error" ); }
275
+ pplx::task<int_type> _bumpc () override { throw std::runtime_error (" error" ); }
276
+ int_type _sbumpc () override { throw std::runtime_error (" error" ); }
277
+ pplx::task<int_type> _getc () override { throw std::runtime_error (" error" ); }
278
+ int_type _sgetc () override { throw std::runtime_error (" error" ); }
279
+ pplx::task<int_type> _nextc () override { throw std::runtime_error (" error" ); }
280
+ pplx::task<int_type> _ungetc () override { throw std::runtime_error (" error" ); }
281
+ pplx::task<size_t > _getn (_Out_writes_(count) CharType *, _In_ size_t) override { throw std::runtime_error (" error" ); }
282
+ size_t _scopy (_Out_writes_(count) CharType *, _In_ size_t) override { throw std::runtime_error (" error" ); }
283
+ pplx::task<bool > _sync () override { throw std::runtime_error (" error" ); }
284
+ CharType* _alloc (size_t ) override { throw std::runtime_error (" error" ); }
285
+ void _commit (size_t ) override { throw std::runtime_error (" error" ); }
286
+
287
+ pplx::task<void > _close_write () override
288
+ {
289
+ return pplx::task_from_exception<void >(std::invalid_argument (" test" ));
290
+ }
291
+ };
292
+
293
+ template <typename CharType>
294
+ class close_throws_buffer : public streams ::streambuf<CharType>
295
+ {
296
+ public:
297
+ close_throws_buffer () : streambuf<CharType>(std::shared_ptr<basic_throws_buffer<CharType>>(new basic_throws_buffer<CharType>())) {}
298
+ };
299
+
300
+ // Tests if an exception occurs and close throws an exception that the close
301
+ // one is ignored and doesn't bring down the process.
302
+ TEST_FIXTURE (uri_address, response_stream_close_throws_with_exception)
303
+ {
304
+ web::http::experimental::listener::http_listener listener (m_uri);
305
+ listener.open ().wait ();
306
+
307
+ streams::producer_consumer_buffer<uint8_t > buf;
308
+
309
+ listener.support ([buf](http_request request)
310
+ {
311
+ http_response response (200 );
312
+ response.set_body (streams::istream (buf), U (" text/plain" ));
313
+ response.headers ().add (header_names::connection, U (" close" ));
314
+ request.reply (response);
315
+ });
316
+
317
+ http_client_config config;
318
+ config.set_timeout (utility::seconds (1 ));
319
+ http_client client (m_uri, config);
320
+
321
+ close_throws_buffer<uint8_t > responseBody;
322
+ http_request msg (methods::GET);
323
+ msg.set_response_stream (responseBody.create_ostream ());
324
+ http_response rsp = client.request (msg).get ();
325
+ VERIFY_THROWS (rsp.content_ready ().get (), http_exception);
326
+
327
+ buf.close (std::ios_base::out).wait ();
328
+ listener.close ().wait ();
329
+ }
330
+
254
331
TEST_FIXTURE (uri_address, content_ready)
255
332
{
256
333
http_client client (m_uri);
0 commit comments