@@ -44,7 +44,6 @@ using namespace concurrency;
44
44
#else
45
45
#include < boost/asio.hpp>
46
46
#include < boost/bind.hpp>
47
- #include < boost/asio/ssl.hpp>
48
47
#include < boost/algorithm/string.hpp>
49
48
#include < pplx/threadpool.h>
50
49
#endif
@@ -62,10 +61,41 @@ using namespace web::http::details;
62
61
63
62
namespace web { namespace http { namespace client { namespace details
64
63
{
64
+ const bool valid_chars [] =
65
+ {
66
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // 0-15
67
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , // 16-31
68
+ 0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 1 , 0 , // 32-47
69
+ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , // 48-63
70
+ 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 64-79
71
+ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , // 80-95
72
+ 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , // 96-111
73
+ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 // 112-127
74
+ };
75
+
65
76
#ifdef _MS_WINDOWS
66
77
static const utility::char_t * get_with_body = _XPLATSTR(" A GET or HEAD request should not have an entity body." );
67
78
#endif
68
79
80
+ #if (!defined(_MS_WINDOWS) || defined(__cplusplus_winrt))
81
+ // Checks if the method contains any invalid characters
82
+ static bool validate_method (const utility::string_t & method)
83
+ {
84
+ for (auto iter = method.begin (); iter != method.end (); iter++)
85
+ {
86
+ char_t ch = *iter;
87
+
88
+ if (size_t (ch) >= 128 )
89
+ return false ;
90
+
91
+ if (!valid_chars[ch])
92
+ return false ;
93
+ }
94
+
95
+ return true ;
96
+ }
97
+ #endif
98
+
69
99
// Helper function to trim leading and trailing null characters from a string.
70
100
static void trim_nulls (utility::string_t &str)
71
101
{
@@ -125,32 +155,14 @@ namespace web { namespace http { namespace client { namespace details
125
155
{
126
156
}
127
157
128
- // TFS 579619 - 1206: revisit whether error_code is really needed for Linux
129
- void complete_headers (const unsigned long error_code = 0 )
158
+ void complete_headers ()
130
159
{
131
160
// We have already read (and transmitted) the request body. Should we explicitly close the stream?
132
161
// Well, there are test cases that assumes that the istream is valid when t receives the response!
133
162
// For now, we will drop our reference which will close the stream if the user doesn't have one.
134
163
m_request.set_body (Concurrency::streams::istream ());
135
-
136
164
m_received_hdrs = true ;
137
- m_response.set_error_code (error_code);
138
-
139
- if (m_response.error_code () == 0 )
140
- {
141
- m_request_completion.set (m_response);
142
- }
143
- #ifdef _MS_WINDOWS
144
- else
145
- {
146
- m_request_completion.set_exception (http_exception (m_response.error_code ()));
147
- }
148
- #else
149
- else
150
- {
151
- m_request_completion.set_exception (http_exception ((int )error_code, _XPLATSTR (" Error reading headers" )));
152
- }
153
- #endif
165
+ m_request_completion.set (m_response);
154
166
}
155
167
156
168
// / <summary>
@@ -169,21 +181,17 @@ namespace web { namespace http { namespace client { namespace details
169
181
#ifdef _MS_WINDOWS
170
182
// Helper function to report an error, set task completion event, and close the request handle.
171
183
172
- // Note: I'm keeping the message parameter in case we decide to log errors again, or add the message
173
- // to the exception message. For now.
174
184
void report_error (const utility::string_t & errorMessage)
175
185
{
176
- report_error ( GetLastError (), errorMessage);
186
+ report_exception ( http_exception ( errorMessage) );
177
187
}
178
188
179
189
#endif
180
190
181
191
void report_error (unsigned long error_code, const utility::string_t & errorMessage)
182
192
{
183
- UNREFERENCED_PARAMETER (errorMessage);
184
-
185
193
m_response.set_error_code (error_code);
186
- report_exception (http_exception ((int )m_response.error_code ()));
194
+ report_exception (http_exception ((int )m_response.error_code (), errorMessage ));
187
195
}
188
196
189
197
template <typename _ExceptionType>
0 commit comments