@@ -93,9 +93,7 @@ namespace web { namespace http
9393 }
9494
9595 std::unique_ptr<tcp::socket> m_socket;
96- #ifndef __APPLE__
9796 std::unique_ptr<boost::asio::ssl::stream<tcp::socket>> m_ssl_stream;
98- #endif
9997 uri m_what;
10098 size_t m_known_size;
10199 size_t m_current_size;
@@ -112,7 +110,7 @@ namespace web { namespace http
112110 socket.shutdown (tcp::socket::shutdown_both, ignore);
113111 socket.close ();
114112 }
115-
113+
116114 ~linux_request_context ()
117115 {
118116 if (m_timer)
@@ -126,32 +124,28 @@ namespace web { namespace http
126124 shutdown_socket (*m_socket);
127125 m_socket.reset ();
128126 }
129-
130- #ifndef __APPLE__
127+
131128 if (m_ssl_stream)
132129 {
133130 shutdown_socket (m_ssl_stream->lowest_layer ());
134131 m_ssl_stream.reset ();
135132 }
136- #endif
137133 }
138134
139135 void cancel (const boost::system::error_code& ec)
140136 {
141137 if (!ec)
142138 {
143139 m_timedout = true ;
144- #ifndef __APPLE__
145140 if (m_ssl_stream)
146141 {
147142 boost::system::error_code error;
148143 m_ssl_stream->lowest_layer ().cancel (error);
149-
144+
150145 if (error)
151146 report_error (" Failed to cancel the socket" , error);
152147 }
153148 else
154- #endif
155149 {
156150 auto sock = m_socket.get ();
157151 if (sock != nullptr )
@@ -163,7 +157,7 @@ namespace web { namespace http
163157 }
164158
165159 public:
166- linux_request_context (std::shared_ptr<_http_client_communicator> &client, http_request request)
160+ linux_request_context (std::shared_ptr<_http_client_communicator> &client, http_request request)
167161 : request_context(client, request)
168162 , m_known_size(0 )
169163 , m_needChunked(false )
@@ -193,22 +187,17 @@ namespace web { namespace http
193187
194188 if (what.scheme () == " https" )
195189 {
196- #ifndef __APPLE__
197190 boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
198191 context.set_default_verify_paths ();
199192 ctx->m_ssl_stream .reset (new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, context));
200- #else
201- ctx->report_exception (http_exception (" https is not supported" ));
202- return ;
203- #endif
204193 }
205194 else
206195 ctx->m_socket .reset (new tcp::socket (m_io_service));
207196
208197 if (resource == " " ) resource = " /" ;
209198
210199 auto method = ctx->m_request .method ();
211-
200+
212201 // stop injection of headers via method
213202 // resource should be ok, since it's been encoded
214203 // and host won't resolve
@@ -226,11 +215,7 @@ namespace web { namespace http
226215 int port = what.port ();
227216 if (what.is_port_default ())
228217 {
229- #ifndef __APPLE__
230218 port = (ctx->m_ssl_stream ? 443 : 80 );
231- #else
232- port = 80 ;
233- #endif
234219 }
235220 request_stream << " :" << port << CRLF;
236221
@@ -265,11 +250,12 @@ namespace web { namespace http
265250
266251 request_stream << flatten_http_headers (ctx->m_request .headers ());
267252
268- #ifndef __APPLE__
269253 if (!ctx->m_ssl_stream )
270- #endif
271- request_stream << " Connection: close" << CRLF; // so we can just read to EOF
272-
254+ {
255+ // so we can just read to EOF
256+ request_stream << " Connection: close" << CRLF;
257+ }
258+
273259 request_stream << CRLF;
274260
275261 tcp::resolver::query query (host, utility::conversions::print_string (port));
@@ -314,7 +300,6 @@ namespace web { namespace http
314300 else
315301 {
316302 auto endpoint = *endpoints;
317- #ifndef __APPLE__
318303 if (ctx->m_ssl_stream )
319304 {
320305 // Check to turn off server certificate verification.
@@ -331,21 +316,24 @@ namespace web { namespace http
331316 ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
332317 }
333318 else
334- # endif
319+ {
335320 ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
321+ }
336322 }
337323 }
338324
339325 void handle_connect (const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_request_context> ctx)
340326 {
341327 if (!ec)
342328 {
343- #ifndef __APPLE__
344329 if (ctx->m_ssl_stream )
330+ {
345331 ctx->m_ssl_stream ->async_handshake (boost::asio::ssl::stream_base::client, boost::bind (&client::handle_handshake, this , boost::asio::placeholders::error, ctx));
332+ }
346333 else
347- # endif
334+ {
348335 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
336+ }
349337 }
350338 else if (endpoints == tcp::resolver::iterator ())
351339 {
@@ -355,7 +343,6 @@ namespace web { namespace http
355343 {
356344 boost::system::error_code ignore;
357345 auto endpoint = *endpoints;
358- #ifndef __APPLE__
359346 if (ctx->m_ssl_stream )
360347 {
361348 ctx->m_ssl_stream ->lowest_layer ().shutdown (tcp::socket::shutdown_both, ignore);
@@ -379,7 +366,6 @@ namespace web { namespace http
379366 ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
380367 }
381368 else
382- #endif
383369 {
384370 ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
385371 ctx->m_socket ->close ();
@@ -389,15 +375,13 @@ namespace web { namespace http
389375 }
390376 }
391377
392- #ifndef __APPLE__
393378 void handle_handshake (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
394379 {
395380 if (!ec)
396381 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
397382 else
398383 ctx->report_error (" Error code in handle_handshake is " , ec, httpclient_errorcode_context::handshake);
399384 }
400- #endif
401385 void handle_write_chunked_body (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
402386 {
403387 if (ec)
@@ -429,12 +413,10 @@ namespace web { namespace http
429413 ctx->m_request_buf .consume (offset);
430414 ctx->m_current_size += readSize;
431415 ctx->m_uploaded += (size64_t )readSize;
432- #ifndef __APPLE__
433416 if (ctx->m_ssl_stream )
434417 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
435418 boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
436419 else
437- #endif
438420 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
439421 boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
440422 });
@@ -472,12 +454,10 @@ namespace web { namespace http
472454 ctx->m_uploaded += (size64_t )actualSize;
473455 ctx->m_current_size += actualSize;
474456 ctx->m_request_buf .commit (actualSize);
475- #ifndef __APPLE__
476457 if (ctx->m_ssl_stream )
477458 boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
478459 boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
479460 else
480- #endif
481461 boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
482462 boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
483463 });
@@ -513,14 +493,12 @@ namespace web { namespace http
513493 return ;
514494 }
515495 }
516-
496+
517497 // Read until the end of entire headers
518- #ifndef __APPLE__
519498 if (ctx->m_ssl_stream )
520499 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF+CRLF,
521500 boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
522501 else
523- #endif
524502 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF+CRLF,
525503 boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
526504 }
@@ -615,12 +593,10 @@ namespace web { namespace http
615593 boost::bind (&client::handle_read_content, this , boost::asio::placeholders::error, ctx), ctx);
616594 else
617595 {
618- #ifndef __APPLE__
619596 if (ctx->m_ssl_stream )
620597 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
621598 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
622599 else
623- #endif
624600 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
625601 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
626602 }
@@ -631,15 +607,13 @@ namespace web { namespace http
631607 void async_read_until_buffersize (size_t size, ReadHandler handler, std::shared_ptr<linux_request_context> ctx)
632608 {
633609 size_t size_to_read = 0 ;
634- #ifndef __APPLE__
635610 if (ctx->m_ssl_stream )
636611 {
637612 if (ctx->m_response_buf .size () < size)
638613 size_to_read = size - ctx->m_response_buf .size ();
639614 boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
640615 }
641616 else
642- #endif
643617 {
644618 if (ctx->m_response_buf .size () < size)
645619 size_to_read = size - ctx->m_response_buf .size ();
@@ -717,12 +691,10 @@ namespace web { namespace http
717691 }
718692 ctx->m_response_buf .consume (to_read + CRLF.size ()); // consume crlf
719693
720- #ifndef __APPLE__
721694 if (ctx->m_ssl_stream )
722695 boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
723696 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
724697 else
725- #endif
726698 boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
727699 boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
728700 });
0 commit comments