@@ -93,9 +93,7 @@ namespace web { namespace http
93
93
}
94
94
95
95
std::unique_ptr<tcp::socket> m_socket;
96
- #ifndef __APPLE__
97
96
std::unique_ptr<boost::asio::ssl::stream<tcp::socket>> m_ssl_stream;
98
- #endif
99
97
uri m_what;
100
98
size_t m_known_size;
101
99
size_t m_current_size;
@@ -112,7 +110,7 @@ namespace web { namespace http
112
110
socket.shutdown (tcp::socket::shutdown_both, ignore);
113
111
socket.close ();
114
112
}
115
-
113
+
116
114
~linux_request_context ()
117
115
{
118
116
if (m_timer)
@@ -126,32 +124,28 @@ namespace web { namespace http
126
124
shutdown_socket (*m_socket);
127
125
m_socket.reset ();
128
126
}
129
-
130
- #ifndef __APPLE__
127
+
131
128
if (m_ssl_stream)
132
129
{
133
130
shutdown_socket (m_ssl_stream->lowest_layer ());
134
131
m_ssl_stream.reset ();
135
132
}
136
- #endif
137
133
}
138
134
139
135
void cancel (const boost::system::error_code& ec)
140
136
{
141
137
if (!ec)
142
138
{
143
139
m_timedout = true ;
144
- #ifndef __APPLE__
145
140
if (m_ssl_stream)
146
141
{
147
142
boost::system::error_code error;
148
143
m_ssl_stream->lowest_layer ().cancel (error);
149
-
144
+
150
145
if (error)
151
146
report_error (" Failed to cancel the socket" , error);
152
147
}
153
148
else
154
- #endif
155
149
{
156
150
auto sock = m_socket.get ();
157
151
if (sock != nullptr )
@@ -163,7 +157,7 @@ namespace web { namespace http
163
157
}
164
158
165
159
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)
167
161
: request_context(client, request)
168
162
, m_known_size(0 )
169
163
, m_needChunked(false )
@@ -193,22 +187,17 @@ namespace web { namespace http
193
187
194
188
if (what.scheme () == " https" )
195
189
{
196
- #ifndef __APPLE__
197
190
boost::asio::ssl::context context (boost::asio::ssl::context::sslv23);
198
191
context.set_default_verify_paths ();
199
192
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
204
193
}
205
194
else
206
195
ctx->m_socket .reset (new tcp::socket (m_io_service));
207
196
208
197
if (resource == " " ) resource = " /" ;
209
198
210
199
auto method = ctx->m_request .method ();
211
-
200
+
212
201
// stop injection of headers via method
213
202
// resource should be ok, since it's been encoded
214
203
// and host won't resolve
@@ -226,11 +215,7 @@ namespace web { namespace http
226
215
int port = what.port ();
227
216
if (what.is_port_default ())
228
217
{
229
- #ifndef __APPLE__
230
218
port = (ctx->m_ssl_stream ? 443 : 80 );
231
- #else
232
- port = 80 ;
233
- #endif
234
219
}
235
220
request_stream << " :" << port << CRLF;
236
221
@@ -265,11 +250,12 @@ namespace web { namespace http
265
250
266
251
request_stream << flatten_http_headers (ctx->m_request .headers ());
267
252
268
- #ifndef __APPLE__
269
253
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
+
273
259
request_stream << CRLF;
274
260
275
261
tcp::resolver::query query (host, utility::conversions::print_string (port));
@@ -314,7 +300,6 @@ namespace web { namespace http
314
300
else
315
301
{
316
302
auto endpoint = *endpoints;
317
- #ifndef __APPLE__
318
303
if (ctx->m_ssl_stream )
319
304
{
320
305
// Check to turn off server certificate verification.
@@ -331,21 +316,24 @@ namespace web { namespace http
331
316
ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
332
317
}
333
318
else
334
- # endif
319
+ {
335
320
ctx->m_socket ->async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
321
+ }
336
322
}
337
323
}
338
324
339
325
void handle_connect (const boost::system::error_code& ec, tcp::resolver::iterator endpoints, std::shared_ptr<linux_request_context> ctx)
340
326
{
341
327
if (!ec)
342
328
{
343
- #ifndef __APPLE__
344
329
if (ctx->m_ssl_stream )
330
+ {
345
331
ctx->m_ssl_stream ->async_handshake (boost::asio::ssl::stream_base::client, boost::bind (&client::handle_handshake, this , boost::asio::placeholders::error, ctx));
332
+ }
346
333
else
347
- # endif
334
+ {
348
335
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
336
+ }
349
337
}
350
338
else if (endpoints == tcp::resolver::iterator ())
351
339
{
@@ -355,7 +343,6 @@ namespace web { namespace http
355
343
{
356
344
boost::system::error_code ignore;
357
345
auto endpoint = *endpoints;
358
- #ifndef __APPLE__
359
346
if (ctx->m_ssl_stream )
360
347
{
361
348
ctx->m_ssl_stream ->lowest_layer ().shutdown (tcp::socket::shutdown_both, ignore);
@@ -379,7 +366,6 @@ namespace web { namespace http
379
366
ctx->m_ssl_stream ->lowest_layer ().async_connect (endpoint, boost::bind (&client::handle_connect, this , boost::asio::placeholders::error, ++endpoints, ctx));
380
367
}
381
368
else
382
- #endif
383
369
{
384
370
ctx->m_socket ->shutdown (tcp::socket::shutdown_both, ignore);
385
371
ctx->m_socket ->close ();
@@ -389,15 +375,13 @@ namespace web { namespace http
389
375
}
390
376
}
391
377
392
- #ifndef __APPLE__
393
378
void handle_handshake (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
394
379
{
395
380
if (!ec)
396
381
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf , boost::bind (&client::handle_write_request, this , boost::asio::placeholders::error, ctx));
397
382
else
398
383
ctx->report_error (" Error code in handle_handshake is " , ec, httpclient_errorcode_context::handshake);
399
384
}
400
- #endif
401
385
void handle_write_chunked_body (const boost::system::error_code& ec, std::shared_ptr<linux_request_context> ctx)
402
386
{
403
387
if (ec)
@@ -429,12 +413,10 @@ namespace web { namespace http
429
413
ctx->m_request_buf .consume (offset);
430
414
ctx->m_current_size += readSize;
431
415
ctx->m_uploaded += (size64_t )readSize;
432
- #ifndef __APPLE__
433
416
if (ctx->m_ssl_stream )
434
417
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
435
418
boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
436
419
else
437
- #endif
438
420
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
439
421
boost::bind (readSize != 0 ? &client::handle_write_chunked_body : &client::handle_write_body, this , boost::asio::placeholders::error, ctx));
440
422
});
@@ -472,12 +454,10 @@ namespace web { namespace http
472
454
ctx->m_uploaded += (size64_t )actualSize;
473
455
ctx->m_current_size += actualSize;
474
456
ctx->m_request_buf .commit (actualSize);
475
- #ifndef __APPLE__
476
457
if (ctx->m_ssl_stream )
477
458
boost::asio::async_write (*ctx->m_ssl_stream , ctx->m_request_buf ,
478
459
boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
479
460
else
480
- #endif
481
461
boost::asio::async_write (*ctx->m_socket , ctx->m_request_buf ,
482
462
boost::bind (&client::handle_write_large_body, this , boost::asio::placeholders::error, ctx));
483
463
});
@@ -513,14 +493,12 @@ namespace web { namespace http
513
493
return ;
514
494
}
515
495
}
516
-
496
+
517
497
// Read until the end of entire headers
518
- #ifndef __APPLE__
519
498
if (ctx->m_ssl_stream )
520
499
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF+CRLF,
521
500
boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
522
501
else
523
- #endif
524
502
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF+CRLF,
525
503
boost::bind (&client::handle_status_line, this , boost::asio::placeholders::error, ctx));
526
504
}
@@ -615,12 +593,10 @@ namespace web { namespace http
615
593
boost::bind (&client::handle_read_content, this , boost::asio::placeholders::error, ctx), ctx);
616
594
else
617
595
{
618
- #ifndef __APPLE__
619
596
if (ctx->m_ssl_stream )
620
597
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
621
598
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
622
599
else
623
- #endif
624
600
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
625
601
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
626
602
}
@@ -631,15 +607,13 @@ namespace web { namespace http
631
607
void async_read_until_buffersize (size_t size, ReadHandler handler, std::shared_ptr<linux_request_context> ctx)
632
608
{
633
609
size_t size_to_read = 0 ;
634
- #ifndef __APPLE__
635
610
if (ctx->m_ssl_stream )
636
611
{
637
612
if (ctx->m_response_buf .size () < size)
638
613
size_to_read = size - ctx->m_response_buf .size ();
639
614
boost::asio::async_read (*ctx->m_ssl_stream , ctx->m_response_buf , boost::asio::transfer_at_least (size_to_read), handler);
640
615
}
641
616
else
642
- #endif
643
617
{
644
618
if (ctx->m_response_buf .size () < size)
645
619
size_to_read = size - ctx->m_response_buf .size ();
@@ -717,12 +691,10 @@ namespace web { namespace http
717
691
}
718
692
ctx->m_response_buf .consume (to_read + CRLF.size ()); // consume crlf
719
693
720
- #ifndef __APPLE__
721
694
if (ctx->m_ssl_stream )
722
695
boost::asio::async_read_until (*ctx->m_ssl_stream , ctx->m_response_buf , CRLF,
723
696
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
724
697
else
725
- #endif
726
698
boost::asio::async_read_until (*ctx->m_socket , ctx->m_response_buf , CRLF,
727
699
boost::bind (&client::handle_chunk_header, this , boost::asio::placeholders::error, ctx));
728
700
});
0 commit comments