@@ -87,8 +87,9 @@ namespace web { namespace http
8787 }
8888
8989 std::unique_ptr<tcp::socket> m_socket;
90+ #ifndef __APPLE__
9091 std::unique_ptr<boost::asio::ssl::stream<tcp::socket>> m_ssl_stream;
91-
92+ # endif
9293 uri m_what;
9394 size_t m_known_size;
9495 size_t m_current_size;
@@ -120,18 +121,21 @@ namespace web { namespace http
120121 m_socket.reset ();
121122 }
122123
124+ #ifndef __APPLE__
123125 if (m_ssl_stream)
124126 {
125127 shutdown_socket (m_ssl_stream->lowest_layer ());
126128 m_ssl_stream.reset ();
127129 }
130+ #endif
128131 }
129132
130133 void cancel (const boost::system::error_code& ec)
131134 {
132135 if (!ec)
133136 {
134137 m_timedout = true ;
138+ #ifndef __APPLE__
135139 if (m_ssl_stream)
136140 {
137141 boost::system::error_code error;
@@ -141,6 +145,7 @@ namespace web { namespace http
141145 report_error (" Failed to cancel the socket" , error);
142146 }
143147 else
148+ #endif
144149 {
145150 auto sock = m_socket.get ();
146151 if (sock != nullptr )
@@ -182,9 +187,14 @@ namespace web { namespace http
182187
183188 if (what.scheme () == " https" )
184189 {
190+ #ifndef __APPLE__
185191 boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
186192 context.set_default_verify_paths ();
187193 ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, context));
194+ #else
195+ ctx->report_exception (http_exception (" https is not supported" ));
196+ return ;
197+ #endif
188198 }
189199 else
190200 ctx->m_socket .reset (new tcp::socket (m_io_service));
@@ -208,8 +218,14 @@ namespace web { namespace http
208218 request_stream << method << " " << resource << " " << " HTTP/1.1" << CRLF << " Host: " << host;
209219
210220 int port = what.port ();
211- if (port == 0 )
221+ if (what.is_port_default ())
222+ {
223+ #ifndef __APPLE__
212224 port = (ctx->m_ssl_stream ? 443 : 80 );
225+ #else
226+ port = 80 ;
227+ #endif
228+ }
213229 request_stream << " :" << port << CRLF;
214230
215231 // Check user specified transfer-encoding
@@ -243,7 +259,9 @@ namespace web { namespace http
243259
244260 request_stream << flatten_http_headers (ctx->m_request .headers ());
245261
262+ #ifndef __APPLE__
246263 if (!ctx->m_ssl_stream )
264+ #endif
247265 request_stream << " Connection: close" << CRLF; // so we can just read to EOF
248266
249267 request_stream << CRLF;
@@ -290,6 +308,7 @@ namespace web { namespace http
290308 else
291309 {
292310 auto endpoint = *endpoints;
311+ #ifndef __APPLE__
293312 if (ctx->m_ssl_stream )
294313 {
295314 // Check to turn off server certificate verification.
@@ -306,6 +325,7 @@ namespace web { namespace http
306325 ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
307326 }
308327 else
328+ #endif
309329 ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
310330 }
311331 }
@@ -314,9 +334,11 @@ namespace web { namespace http
314334 {
315335 if (!ec)
316336 {
337+ #ifndef __APPLE__
317338 if (ctx->m_ssl_stream )
318339 ctx->m_ssl_stream ->async_handshake (boost::asio::ssl::stream_base::client, boost::bind (&client::handle_handshake, this , boost::asio::placeholders::error, ctx));
319340 else
341+ #endif
320342 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
321343 }
322344 else if (endpoints == tcp::resolver::iterator ())
@@ -327,6 +349,7 @@ namespace web { namespace http
327349 {
328350 boost::system::error_code ignore;
329351 auto endpoint = *endpoints;
352+ #ifndef __APPLE__
330353 if (ctx->m_ssl_stream )
331354 {
332355 ctx->m_ssl_stream ->lowest_layer ().shutdown (tcp::socket::shutdown_both, ignore);
@@ -350,6 +373,7 @@ namespace web { namespace http
350373 ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
351374 }
352375 else
376+ #endif
353377 {
354378 ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
355379 ctx->m_socket ->close ();
@@ -359,14 +383,15 @@ namespace web { namespace http
359383 }
360384 }
361385
386+ #ifndef __APPLE__
362387 void handle_handshake (const boost::system::error_code& ec, linux_request_context* ctx)
363388 {
364389 if (!ec)
365390 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
366391 else
367392 ctx->report_error (" Error code in handle_handshake is " , ec, httpclient_errorcode_context::handshake);
368393 }
369-
394+ # endif
370395 void handle_write_chunked_body (const boost::system::error_code& ec, linux_request_context* ctx)
371396 {
372397 if (ec)
@@ -394,10 +419,12 @@ namespace web { namespace http
394419 ctx->m_request_buf .consume (offset);
395420 ctx->m_current_size += readSize;
396421 ctx->m_uploaded += (size64_t )readSize;
422+ #ifndef __APPLE__
397423 if (ctx->m_ssl_stream )
398424 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
399425 boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
400426 else
427+ #endif
401428 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
402429 boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
403430 });
@@ -431,10 +458,12 @@ namespace web { namespace http
431458 ctx->m_uploaded += (size64_t )actualSize;
432459 ctx->m_current_size += actualSize;
433460 ctx->m_request_buf .commit (actualSize);
461+ #ifndef __APPLE__
434462 if (ctx->m_ssl_stream )
435463 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
436464 boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
437465 else
466+ #endif
438467 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
439468 boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
440469 });
@@ -468,10 +497,12 @@ namespace web { namespace http
468497 }
469498
470499 // Read until the end of entire headers
500+ #ifndef __APPLE__
471501 if (ctx->m_ssl_stream )
472502 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF+CRLF,
473503 boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
474504 else
505+ #endif
475506 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF+CRLF,
476507 boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
477508 }
@@ -562,10 +593,12 @@ namespace web { namespace http
562593 boost::bind (&client::handle_read_content, this , boost::asio::placeholders::error, ctx), ctx);
563594 else
564595 {
596+ #ifndef __APPLE__
565597 if (ctx->m_ssl_stream )
566598 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
567599 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
568600 else
601+ #endif
569602 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
570603 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
571604 }
@@ -576,13 +609,15 @@ namespace web { namespace http
576609 void async_read_until_buffersize (size_t size, ReadHandler handler, linux_request_context* ctx)
577610 {
578611 size_t size_to_read = 0 ;
612+ #ifndef __APPLE__
579613 if (ctx->m_ssl_stream )
580614 {
581615 if (ctx->m_response_buf .size () < size)
582616 size_to_read = size - ctx->m_response_buf .size ();
583617 boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
584618 }
585619 else
620+ #endif
586621 {
587622 if (ctx->m_response_buf .size () < size)
588623 size_to_read = size - ctx->m_response_buf .size ();
@@ -656,10 +691,12 @@ namespace web { namespace http
656691 }
657692 ctx->m_response_buf .consume (to_read + CRLF.size ()); // consume crlf
658693
694+ #ifndef __APPLE__
659695 if (ctx->m_ssl_stream )
660696 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
661697 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
662698 else
699+ #endif
663700 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
664701 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
665702 });
@@ -677,13 +714,13 @@ namespace web { namespace http
677714
678715 if (ec)
679716 {
680- if (ec == boost::asio::error::eof && ctx->m_known_size == std::numeric_limits<size_t >::max ())
681- ctx->m_known_size = ctx->m_current_size + ctx->m_response_buf .size ();
682- else
683- {
684- ctx->report_error (" Failed to read response body" , ec, httpclient_errorcode_context::readbody);
685- return ;
686- }
717+ if (ec == boost::asio::error::eof && ctx->m_known_size == std::numeric_limits<size_t >::max ())
718+ ctx->m_known_size = ctx->m_current_size + ctx->m_response_buf .size ();
719+ else
720+ {
721+ ctx->report_error (" Failed to read response body" , ec, httpclient_errorcode_context::readbody);
722+ return ;
723+ }
687724 }
688725 auto progress = ctx->m_request ._get_impl ()->_progress_handler ();
689726 if ( progress )
0 commit comments