1
1
/* **
2
2
* ==++==
3
3
*
4
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Copyright (c) Microsoft Corporation. All rights reserved.
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
8
* http://www.apache.org/licenses/LICENSE-2.0
9
- *
9
+ *
10
10
* Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,7 +49,7 @@ typedef void* native_handle;}}}
49
49
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
50
50
#include < ppltasks.h>
51
51
namespace pplx = Concurrency;
52
- #else
52
+ #else
53
53
#include " pplx/pplxtasks.h"
54
54
#endif
55
55
@@ -66,7 +66,7 @@ namespace pplx = Concurrency;
66
66
#include " cpprest/oauth2.h"
67
67
68
68
// / The web namespace contains functionality common to multiple protocols like HTTP and WebSockets.
69
- namespace web
69
+ namespace web
70
70
{
71
71
// / Declarations and functionality for the HTTP protocol.
72
72
namespace http
@@ -88,7 +88,7 @@ namespace details {
88
88
#else
89
89
class winhttp_client ;
90
90
#endif // __cplusplus_winrt
91
- }
91
+ }
92
92
#endif // _MS_WINDOWS
93
93
94
94
// / <summary>
@@ -98,7 +98,7 @@ namespace details {
98
98
class http_client_config
99
99
{
100
100
public:
101
- http_client_config () :
101
+ http_client_config () :
102
102
m_guarantee_order (false ),
103
103
m_timeout (utility::seconds(30 )),
104
104
m_chunksize (0 )
@@ -217,7 +217,7 @@ class http_client_config
217
217
// / Set the timeout
218
218
// / </summary>
219
219
// / <param name="timeout">The timeout (in seconds) used for each send and receive operation on the client.</param>
220
- void set_timeout (utility::seconds timeout)
220
+ void set_timeout (const utility::seconds & timeout)
221
221
{
222
222
m_timeout = timeout;
223
223
}
@@ -284,7 +284,7 @@ class http_client_config
284
284
}
285
285
286
286
// / <summary>
287
- // / Sets the request buffering property.
287
+ // / Sets the request buffering property.
288
288
// / If true, in cases where the request body/stream doesn't support seeking the request data will be buffered.
289
289
// / This can help in situations where an authentication challenge might be expected.
290
290
// / </summary>
@@ -296,12 +296,12 @@ class http_client_config
296
296
}
297
297
#endif
298
298
#endif
299
-
299
+
300
300
// / <summary>
301
301
// / Sets a callback to enable custom setting of winhttp options
302
302
// / </summary>
303
303
// / <param name="callback">A user callback allowing for customization of the request</param>
304
- void set_nativehandle_options (std::function<void (native_handle)> callback)
304
+ void set_nativehandle_options (const std::function<void (native_handle)> & callback)
305
305
{
306
306
m_set_user_nativehandle_options = callback;
307
307
}
@@ -369,7 +369,7 @@ class http_client
369
369
// / Note the destructor doesn't necessarily close the connection and release resources.
370
370
// / The connection is reference counted with the http_responses.
371
371
// / </summary>
372
- ~http_client () {}
372
+ ~http_client () _noexcept {}
373
373
374
374
// / <summary>
375
375
// / Gets the base uri
@@ -398,7 +398,7 @@ class http_client
398
398
// / Adds an HTTP pipeline stage to the client.
399
399
// / </summary>
400
400
// / <param name="stage">A shared pointer to a pipeline stage.</param>
401
- void add_handler (std::shared_ptr<http::http_pipeline_stage> stage)
401
+ void add_handler (const std::shared_ptr<http::http_pipeline_stage> & stage)
402
402
{
403
403
m_pipeline->append (stage);
404
404
}
@@ -409,17 +409,17 @@ class http_client
409
409
// / <param name="request">Request to send.</param>
410
410
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
411
411
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
412
- _ASYNCRTIMP pplx::task<http_response> request (http_request request, pplx::cancellation_token token = pplx::cancellation_token::none());
412
+ _ASYNCRTIMP pplx::task<http_response> request (http_request request, const pplx::cancellation_token & token = pplx::cancellation_token::none());
413
413
414
414
// / <summary>
415
415
// / Asynchronously sends an HTTP request.
416
416
// / </summary>
417
417
// / <param name="mtd">HTTP request method.</param>
418
418
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
419
419
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
420
- pplx::task<http_response> request (method mtd, pplx::cancellation_token token = pplx::cancellation_token::none())
420
+ pplx::task<http_response> request (const method & mtd, const pplx::cancellation_token & token = pplx::cancellation_token::none())
421
421
{
422
- http_request msg (std::move ( mtd) );
422
+ http_request msg (mtd);
423
423
return request (msg, token);
424
424
}
425
425
@@ -431,11 +431,11 @@ class http_client
431
431
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
432
432
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
433
433
pplx::task<http_response> request (
434
- method mtd,
434
+ const method & mtd,
435
435
const utility::string_t &path_query_fragment,
436
- pplx::cancellation_token token = pplx::cancellation_token::none())
436
+ const pplx::cancellation_token & token = pplx::cancellation_token::none())
437
437
{
438
- http_request msg (std::move ( mtd) );
438
+ http_request msg (mtd);
439
439
msg.set_request_uri (path_query_fragment);
440
440
return request (msg, token);
441
441
}
@@ -449,12 +449,12 @@ class http_client
449
449
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
450
450
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
451
451
pplx::task<http_response> request (
452
- method mtd,
453
- const utility::string_t &path_query_fragment,
452
+ const method & mtd,
453
+ const utility::string_t &path_query_fragment,
454
454
const json::value &body_data,
455
- pplx::cancellation_token token = pplx::cancellation_token::none())
455
+ const pplx::cancellation_token & token = pplx::cancellation_token::none())
456
456
{
457
- http_request msg (std::move ( mtd) );
457
+ http_request msg (mtd);
458
458
msg.set_request_uri (path_query_fragment);
459
459
msg.set_body (body_data);
460
460
return request (msg, token);
@@ -469,16 +469,17 @@ class http_client
469
469
// / <param name="body_data">String containing the text to use in the message body.</param>
470
470
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
471
471
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
472
+ // TODO overload???Not sure...
472
473
pplx::task<http_response> request (
473
- method mtd,
474
+ const method & mtd,
474
475
const utility::string_t &path_query_fragment,
475
476
const utility::string_t &body_data,
476
- utility::string_t content_type = _XPLATSTR(" text/plain" ),
477
- pplx::cancellation_token token = pplx::cancellation_token::none())
477
+ const utility::string_t & content_type = _XPLATSTR(" text/plain" ),
478
+ const pplx::cancellation_token & token = pplx::cancellation_token::none())
478
479
{
479
- http_request msg (std::move ( mtd) );
480
+ http_request msg (mtd);
480
481
msg.set_request_uri (path_query_fragment);
481
- msg.set_body (body_data, std::move ( content_type) );
482
+ msg.set_body (body_data, content_type);
482
483
return request (msg, token);
483
484
}
484
485
@@ -490,11 +491,12 @@ class http_client
490
491
// / <param name="body_data">String containing the text to use in the message body.</param>
491
492
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
492
493
// / <returns>An asynchronous operation that is completed once a response from the request is received.</returns>
494
+ // TODO overload not usre???
493
495
pplx::task<http_response> request (
494
- method mtd,
496
+ const method & mtd,
495
497
const utility::string_t &path_query_fragment,
496
498
const utility::string_t &body_data,
497
- pplx::cancellation_token token)
499
+ const pplx::cancellation_token & token)
498
500
{
499
501
return request (mtd, path_query_fragment, body_data, _XPLATSTR (" text/plain" ), token);
500
502
}
@@ -510,15 +512,15 @@ class http_client
510
512
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
511
513
// / <returns>A task that is completed once a response from the request is received.</returns>
512
514
pplx::task<http_response> request (
513
- method mtd,
515
+ const method & mtd,
514
516
const utility::string_t &path_query_fragment,
515
- concurrency::streams::istream body,
516
- utility::string_t content_type = _XPLATSTR(" application/octet-stream" ),
517
- pplx::cancellation_token token = pplx::cancellation_token::none())
517
+ const concurrency::streams::istream & body,
518
+ const utility::string_t & content_type = _XPLATSTR(" application/octet-stream" ),
519
+ const pplx::cancellation_token & token = pplx::cancellation_token::none())
518
520
{
519
- http_request msg (std::move ( mtd) );
521
+ http_request msg (mtd);
520
522
msg.set_request_uri (path_query_fragment);
521
- msg.set_body (body, std::move ( content_type) );
523
+ msg.set_body (body, content_type);
522
524
return request (msg, token);
523
525
}
524
526
@@ -531,10 +533,10 @@ class http_client
531
533
// / <param name="token">Cancellation token for cancellation of this request operation.</param>
532
534
// / <returns>A task that is completed once a response from the request is received.</returns>
533
535
pplx::task<http_response> request (
534
- method mtd,
536
+ const method & mtd,
535
537
const utility::string_t &path_query_fragment,
536
- concurrency::streams::istream body,
537
- pplx::cancellation_token token)
538
+ const concurrency::streams::istream & body,
539
+ const pplx::cancellation_token & token)
538
540
{
539
541
return request (mtd, path_query_fragment, body, _XPLATSTR (" application/octet-stream" ), token);
540
542
}
@@ -552,16 +554,16 @@ class http_client
552
554
// / <returns>A task that is completed once a response from the request is received.</returns>
553
555
// / <remarks>Winrt requires to provide content_length.</remarks>
554
556
pplx::task<http_response> request (
555
- method mtd,
557
+ const method & mtd,
556
558
const utility::string_t &path_query_fragment,
557
- concurrency::streams::istream body,
559
+ const concurrency::streams::istream & body,
558
560
size_t content_length,
559
- utility::string_t content_type= _XPLATSTR(" application/octet-stream" ),
560
- pplx::cancellation_token token = pplx::cancellation_token::none())
561
+ const utility::string_t & content_type = _XPLATSTR(" application/octet-stream" ),
562
+ const pplx::cancellation_token & token = pplx::cancellation_token::none())
561
563
{
562
- http_request msg (std::move ( mtd) );
564
+ http_request msg (mtd);
563
565
msg.set_request_uri (path_query_fragment);
564
- msg.set_body (body, content_length, std::move ( content_type) );
566
+ msg.set_body (body, content_length, content_type);
565
567
return request (msg, token);
566
568
}
567
569
@@ -576,22 +578,22 @@ class http_client
576
578
// / <returns>A task that is completed once a response from the request is received.</returns>
577
579
// / <remarks>Winrt requires to provide content_length.</remarks>
578
580
pplx::task<http_response> request (
579
- method mtd,
581
+ const method & mtd,
580
582
const utility::string_t &path_query_fragment,
581
- concurrency::streams::istream body,
583
+ const concurrency::streams::istream & body,
582
584
size_t content_length,
583
- pplx::cancellation_token token)
585
+ const pplx::cancellation_token & token)
584
586
{
585
587
return request (mtd, path_query_fragment, body, content_length, _XPLATSTR (" application/octet-stream" ), token);
586
588
}
587
589
588
590
private:
589
591
590
592
void build_pipeline (uri base_uri, http_client_config client_config);
591
-
593
+
592
594
std::shared_ptr<::web::http::http_pipeline> m_pipeline;
593
595
};
594
596
595
- }}} // namespaces
597
+ }}}
596
598
597
599
#endif /* _CASA_HTTP_CLIENT_H */
0 commit comments