@@ -167,13 +167,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
167
167
bool ssl = false ;
168
168
if (protocol == " https" ) ssl = true ;
169
169
170
- char request[4096 ];
171
- char * end = request + sizeof (request);
172
- char * ptr = request;
173
-
174
- #define APPEND_FMT (fmt ) ptr += snprintf(ptr, end - ptr, fmt)
175
- #define APPEND_FMT1 (fmt, arg ) ptr += snprintf(ptr, end - ptr, fmt, arg)
176
- #define APPEND_FMT2 (fmt, arg1, arg2 ) ptr += snprintf(ptr, end - ptr, fmt, arg1, arg2)
170
+ std::stringstream request;
177
171
178
172
// exclude ssl here, because SSL assumes CONNECT support in the
179
173
// proxy and is handled at the lower layer
@@ -183,40 +177,39 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
183
177
{
184
178
// if we're using an http proxy and not an ssl
185
179
// connection, just do a regular http proxy request
186
- APPEND_FMT1 ( " GET %s HTTP/1.1\r\n " , url. c_str ()) ;
180
+ request << " GET " << url << " HTTP/1.1\r\n " ;
187
181
if (ps->type == settings_pack::http_pw)
188
- APPEND_FMT1 ( " Proxy-Authorization: Basic %s \r\n " , base64encode (
189
- ps->username + " :" + ps->password ). c_str ()) ;
182
+ request << " Proxy-Authorization: Basic " << base64encode (
183
+ ps->username + " :" + ps->password ) << " \r\n " ;
190
184
191
185
hostname = ps->hostname ;
192
186
port = ps->port ;
193
187
194
- APPEND_FMT1 ( " Host: %s " , hostname. c_str ()) ;
195
- if (port != default_port) APPEND_FMT1 ( " :%d \r\n " , port) ;
196
- else APPEND_FMT ( " \r\n " ) ;
188
+ request << " Host: " << hostname;
189
+ if (port != default_port) request << " : " << port << " \r\n " ;
190
+ else request << " \r\n " ;
197
191
}
198
192
else
199
193
{
200
- APPEND_FMT2 (" GET %s HTTP/1.1\r\n "
201
- " Host: %s" , path.c_str (), hostname.c_str ());
202
- if (port != default_port) APPEND_FMT1 (" :%d\r\n " , port);
203
- else APPEND_FMT (" \r\n " );
194
+ request << " GET " << path << " HTTP/1.1\r\n Host: " << hostname;
195
+ if (port != default_port) request << " :" << port << " \r\n " ;
196
+ else request << " \r\n " ;
204
197
}
205
198
206
- // APPEND_FMT( "Accept: */*\r\n") ;
199
+ // request << "Accept: */*\r\n";
207
200
208
201
if (!m_user_agent.empty ())
209
- APPEND_FMT1 ( " User-Agent: %s \r\n " , m_user_agent. c_str ()) ;
202
+ request << " User-Agent: " << m_user_agent << " \r\n " ;
210
203
211
204
if (m_bottled)
212
- APPEND_FMT ( " Accept-Encoding: gzip\r\n " ) ;
205
+ request << " Accept-Encoding: gzip\r\n " ;
213
206
214
207
if (!auth.empty ())
215
- APPEND_FMT1 ( " Authorization: Basic %s \r\n " , base64encode (auth). c_str ()) ;
208
+ request << " Authorization: Basic " << base64encode (auth) << " \r\n " ;
216
209
217
- APPEND_FMT ( " Connection: close\r\n\r\n " ) ;
210
+ request << " Connection: close\r\n\r\n " ;
218
211
219
- m_sendbuffer.assign (request);
212
+ m_sendbuffer.assign (request. str () );
220
213
m_url = url;
221
214
start (hostname, port, timeout, prio
222
215
, ps, ssl, handle_redirects, bind_addr, m_resolve_flags
0 commit comments