@@ -87,8 +87,9 @@ namespace web { namespace http
87
87
}
88
88
89
89
std::unique_ptr<tcp::socket> m_socket;
90
+ #ifndef __APPLE__
90
91
std::unique_ptr<boost::asio::ssl::stream<tcp::socket>> m_ssl_stream;
91
-
92
+ # endif
92
93
uri m_what;
93
94
size_t m_known_size;
94
95
size_t m_current_size;
@@ -120,18 +121,21 @@ namespace web { namespace http
120
121
m_socket.reset ();
121
122
}
122
123
124
+ #ifndef __APPLE__
123
125
if (m_ssl_stream)
124
126
{
125
127
shutdown_socket (m_ssl_stream->lowest_layer ());
126
128
m_ssl_stream.reset ();
127
129
}
130
+ #endif
128
131
}
129
132
130
133
void cancel (const boost::system::error_code& ec)
131
134
{
132
135
if (!ec)
133
136
{
134
137
m_timedout = true ;
138
+ #ifndef __APPLE__
135
139
if (m_ssl_stream)
136
140
{
137
141
boost::system::error_code error;
@@ -141,6 +145,7 @@ namespace web { namespace http
141
145
report_error (" Failed to cancel the socket" , error);
142
146
}
143
147
else
148
+ #endif
144
149
{
145
150
auto sock = m_socket.get ();
146
151
if (sock != nullptr )
@@ -182,9 +187,14 @@ namespace web { namespace http
182
187
183
188
if (what.scheme () == " https" )
184
189
{
190
+ #ifndef __APPLE__
185
191
boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
186
192
context.set_default_verify_paths ();
187
193
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
188
198
}
189
199
else
190
200
ctx->m_socket .reset (new tcp::socket (m_io_service));
@@ -208,8 +218,14 @@ namespace web { namespace http
208
218
request_stream << method << " " << resource << " " << " HTTP/1.1" << CRLF << " Host: " << host;
209
219
210
220
int port = what.port ();
211
- if (port == 0 )
221
+ if (what.is_port_default ())
222
+ {
223
+ #ifndef __APPLE__
212
224
port = (ctx->m_ssl_stream ? 443 : 80 );
225
+ #else
226
+ port = 80 ;
227
+ #endif
228
+ }
213
229
request_stream << " :" << port << CRLF;
214
230
215
231
// Check user specified transfer-encoding
@@ -243,7 +259,9 @@ namespace web { namespace http
243
259
244
260
request_stream << flatten_http_headers (ctx->m_request .headers ());
245
261
262
+ #ifndef __APPLE__
246
263
if (!ctx->m_ssl_stream )
264
+ #endif
247
265
request_stream << " Connection: close" << CRLF; // so we can just read to EOF
248
266
249
267
request_stream << CRLF;
@@ -290,6 +308,7 @@ namespace web { namespace http
290
308
else
291
309
{
292
310
auto endpoint = *endpoints;
311
+ #ifndef __APPLE__
293
312
if (ctx->m_ssl_stream )
294
313
{
295
314
// Check to turn off server certificate verification.
@@ -306,6 +325,7 @@ namespace web { namespace http
306
325
ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
307
326
}
308
327
else
328
+ #endif
309
329
ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
310
330
}
311
331
}
@@ -314,9 +334,11 @@ namespace web { namespace http
314
334
{
315
335
if (!ec)
316
336
{
337
+ #ifndef __APPLE__
317
338
if (ctx->m_ssl_stream )
318
339
ctx->m_ssl_stream ->async_handshake (boost::asio::ssl::stream_base::client, boost::bind (&client::handle_handshake, this , boost::asio::placeholders::error, ctx));
319
340
else
341
+ #endif
320
342
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
321
343
}
322
344
else if (endpoints == tcp::resolver::iterator ())
@@ -327,6 +349,7 @@ namespace web { namespace http
327
349
{
328
350
boost::system::error_code ignore;
329
351
auto endpoint = *endpoints;
352
+ #ifndef __APPLE__
330
353
if (ctx->m_ssl_stream )
331
354
{
332
355
ctx->m_ssl_stream ->lowest_layer ().shutdown (tcp::socket::shutdown_both, ignore);
@@ -350,6 +373,7 @@ namespace web { namespace http
350
373
ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
351
374
}
352
375
else
376
+ #endif
353
377
{
354
378
ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
355
379
ctx->m_socket ->close ();
@@ -359,14 +383,15 @@ namespace web { namespace http
359
383
}
360
384
}
361
385
386
+ #ifndef __APPLE__
362
387
void handle_handshake (const boost::system::error_code& ec, linux_request_context* ctx)
363
388
{
364
389
if (!ec)
365
390
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
366
391
else
367
392
ctx->report_error (" Error code in handle_handshake is " , ec, httpclient_errorcode_context::handshake);
368
393
}
369
-
394
+ # endif
370
395
void handle_write_chunked_body (const boost::system::error_code& ec, linux_request_context* ctx)
371
396
{
372
397
if (ec)
@@ -394,10 +419,12 @@ namespace web { namespace http
394
419
ctx->m_request_buf .consume (offset);
395
420
ctx->m_current_size += readSize;
396
421
ctx->m_uploaded += (size64_t )readSize;
422
+ #ifndef __APPLE__
397
423
if (ctx->m_ssl_stream )
398
424
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
399
425
boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
400
426
else
427
+ #endif
401
428
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
402
429
boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
403
430
});
@@ -431,10 +458,12 @@ namespace web { namespace http
431
458
ctx->m_uploaded += (size64_t )actualSize;
432
459
ctx->m_current_size += actualSize;
433
460
ctx->m_request_buf .commit (actualSize);
461
+ #ifndef __APPLE__
434
462
if (ctx->m_ssl_stream )
435
463
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
436
464
boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
437
465
else
466
+ #endif
438
467
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
439
468
boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
440
469
});
@@ -468,10 +497,12 @@ namespace web { namespace http
468
497
}
469
498
470
499
// Read until the end of entire headers
500
+ #ifndef __APPLE__
471
501
if (ctx->m_ssl_stream )
472
502
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF+CRLF,
473
503
boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
474
504
else
505
+ #endif
475
506
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF+CRLF,
476
507
boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
477
508
}
@@ -562,10 +593,12 @@ namespace web { namespace http
562
593
boost::bind (&client::handle_read_content, this , boost::asio::placeholders::error, ctx), ctx);
563
594
else
564
595
{
596
+ #ifndef __APPLE__
565
597
if (ctx->m_ssl_stream )
566
598
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
567
599
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
568
600
else
601
+ #endif
569
602
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
570
603
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
571
604
}
@@ -576,13 +609,15 @@ namespace web { namespace http
576
609
void async_read_until_buffersize (size_t size, ReadHandler handler, linux_request_context* ctx)
577
610
{
578
611
size_t size_to_read = 0 ;
612
+ #ifndef __APPLE__
579
613
if (ctx->m_ssl_stream )
580
614
{
581
615
if (ctx->m_response_buf .size () < size)
582
616
size_to_read = size - ctx->m_response_buf .size ();
583
617
boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
584
618
}
585
619
else
620
+ #endif
586
621
{
587
622
if (ctx->m_response_buf .size () < size)
588
623
size_to_read = size - ctx->m_response_buf .size ();
@@ -656,10 +691,12 @@ namespace web { namespace http
656
691
}
657
692
ctx->m_response_buf .consume (to_read + CRLF.size ()); // consume crlf
658
693
694
+ #ifndef __APPLE__
659
695
if (ctx->m_ssl_stream )
660
696
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
661
697
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
662
698
else
699
+ #endif
663
700
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
664
701
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
665
702
});
@@ -677,13 +714,13 @@ namespace web { namespace http
677
714
678
715
if (ec)
679
716
{
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
+ }
687
724
}
688
725
auto progress = ctx->m_request ._get_impl ()->_progress_handler ();
689
726
if ( progress )
0 commit comments