This repository was archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathweb_request.cpp
More file actions
47 lines (39 loc) · 1.42 KB
/
web_request.cpp
File metadata and controls
47 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#include "stdafx.h"
#include "cpprest/http_client.h"
#include "web_request.h"
namespace signalr
{
web_request::web_request(const web::uri &url)
: m_url(url)
{ }
void web_request::set_method(const utility::string_t &method)
{
m_request.set_method(method);
}
void web_request::set_client_config(const signalr_client_config& signalr_client_config)
{
m_signalr_client_config = signalr_client_config;
}
pplx::task<web_response> web_request::get_response()
{
web::http::client::http_client client(m_url, m_signalr_client_config.get_http_client_config());
m_request.headers() = m_signalr_client_config.get_http_headers();
if (!m_signalr_client_config.get_user_agent().empty())
{
m_request.headers()[_XPLATSTR("User-Agent")] = m_signalr_client_config.get_user_agent();
}
return client.request(m_request)
.then([](web::http::http_response response)
{
return web_response
{
response.status_code(),
response.reason_phrase(),
response.extract_string()
};
});
}
web_request::~web_request() = default;
}