Skip to content

Commit ca10b01

Browse files
committed
Fixing incorrect assumption in code about thread safetly of initialization of function local static variables. VS 2013 didn't implement magic statics.
1 parent 5a86616 commit ca10b01

File tree

8 files changed

+363
-299
lines changed

8 files changed

+363
-299
lines changed

Release/include/cpprest/details/http_helpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ namespace details
8181
/// </summary>
8282
utility::string_t get_default_charset(const utility::string_t &content_type);
8383

84+
/// <summary>
85+
/// Helper function to get the default HTTP reason phrase for a status code.
86+
/// </summary>
87+
utility::string_t get_default_reason_phrase(status_code code);
88+
8489
/// <summary>
8590
/// Helper functions to convert a series of bytes from a charset to utf-8 or utf-16.
8691
/// These APIs deal with checking for and handling byte order marker (BOM).

Release/include/cpprest/oauth1.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ class oauth1_token
135135
{
136136
public:
137137

138+
/// <summary>
139+
/// Constructs an initially empty invalid access token.
140+
/// </summary>
141+
oauth1_token() {}
142+
138143
/// <summary>
139144
/// Constructs a OAuth1 token from a given access token and secret.
140145
/// </summary>
@@ -222,8 +227,6 @@ class oauth1_token
222227
private:
223228
friend class oauth1_config;
224229

225-
oauth1_token() {}
226-
227230
utility::string_t m_token;
228231
utility::string_t m_secret;
229232
std::map<utility::string_t, utility::string_t> m_additional_parameters;
@@ -366,21 +369,7 @@ class oauth1_config
366369
/// Get token.
367370
/// </summary>
368371
/// <returns>Token.</returns>
369-
const oauth1_token& token() const
370-
{
371-
if (m_is_authorization_completed)
372-
{
373-
// Return the token object only if authorization has been completed.
374-
// Otherwise the token object holds a temporary token which should not be
375-
// returned to the user.
376-
return m_token;
377-
}
378-
else
379-
{
380-
static const oauth1_token empty_token;
381-
return empty_token;
382-
}
383-
}
372+
_ASYNCRTIMP const oauth1_token& token() const;
384373

385374
/// <summary>
386375
/// Set token.

Release/src/http/client/http_client_msg.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,7 @@ utility::string_t details::_http_response::to_string() const
8686
auto reason_phrase = m_reason_phrase;
8787
if(reason_phrase.empty())
8888
{
89-
static http_status_to_phrase idToPhraseMap[] = {
90-
#define _PHRASES
91-
#define DAT(a,b,c) {status_codes::a, c},
92-
#include "cpprest/details/http_constants.dat"
93-
#undef _PHRASES
94-
#undef DAT
95-
};
96-
97-
for( auto iter = std::begin(idToPhraseMap); iter != std::end(idToPhraseMap); ++iter)
98-
{
99-
if( iter->id == status_code() )
100-
{
101-
reason_phrase = iter->phrase;
102-
break;
103-
}
104-
}
89+
reason_phrase = get_default_reason_phrase(status_code());
10590
}
10691

10792
utility::ostringstream_t buffer;

0 commit comments

Comments
 (0)