http_proxy.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #include "http_proxy.h"
  24. #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
  25. #include <curl/curl.h>
  26. #include "sendf.h"
  27. #include "http.h"
  28. #include "url.h"
  29. #include "select.h"
  30. #include "progress.h"
  31. #include "non-ascii.h"
  32. #include "connect.h"
  33. #include "curlx.h"
  34. #include "vtls/vtls.h"
  35. /* The last 3 #include files should be in this order */
  36. #include "curl_printf.h"
  37. #include "curl_memory.h"
  38. #include "memdebug.h"
  39. /*
  40. * Perform SSL initialization for HTTPS proxy. Sets
  41. * proxy_ssl_connected connection bit when complete. Can be
  42. * called multiple times.
  43. */
  44. static CURLcode https_proxy_connect(struct connectdata *conn, int sockindex)
  45. {
  46. #ifdef USE_SSL
  47. CURLcode result = CURLE_OK;
  48. DEBUGASSERT(conn->http_proxy.proxytype == CURLPROXY_HTTPS);
  49. if(!conn->bits.proxy_ssl_connected[sockindex]) {
  50. /* perform SSL initialization for this socket */
  51. result =
  52. Curl_ssl_connect_nonblocking(conn, sockindex,
  53. &conn->bits.proxy_ssl_connected[sockindex]);
  54. if(result)
  55. conn->bits.close = TRUE; /* a failed connection is marked for closure to
  56. prevent (bad) re-use or similar */
  57. }
  58. return result;
  59. #else
  60. (void) conn;
  61. (void) sockindex;
  62. return CURLE_NOT_BUILT_IN;
  63. #endif
  64. }
  65. CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
  66. {
  67. if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
  68. const CURLcode result = https_proxy_connect(conn, sockindex);
  69. if(result)
  70. return result;
  71. if(!conn->bits.proxy_ssl_connected[sockindex])
  72. return result; /* wait for HTTPS proxy SSL initialization to complete */
  73. }
  74. if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
  75. #ifndef CURL_DISABLE_PROXY
  76. /* for [protocol] tunneled through HTTP proxy */
  77. struct HTTP http_proxy;
  78. void *prot_save;
  79. const char *hostname;
  80. int remote_port;
  81. CURLcode result;
  82. /* BLOCKING */
  83. /* We want "seamless" operations through HTTP proxy tunnel */
  84. /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the
  85. * member conn->proto.http; we want [protocol] through HTTP and we have
  86. * to change the member temporarily for connecting to the HTTP
  87. * proxy. After Curl_proxyCONNECT we have to set back the member to the
  88. * original pointer
  89. *
  90. * This function might be called several times in the multi interface case
  91. * if the proxy's CONNECT response is not instant.
  92. */
  93. prot_save = conn->data->req.protop;
  94. memset(&http_proxy, 0, sizeof(http_proxy));
  95. conn->data->req.protop = &http_proxy;
  96. connkeep(conn, "HTTP proxy CONNECT");
  97. /* for the secondary socket (FTP), use the "connect to host"
  98. * but ignore the "connect to port" (use the secondary port)
  99. */
  100. if(conn->bits.conn_to_host)
  101. hostname = conn->conn_to_host.name;
  102. else if(sockindex == SECONDARYSOCKET)
  103. hostname = conn->secondaryhostname;
  104. else
  105. hostname = conn->host.name;
  106. if(sockindex == SECONDARYSOCKET)
  107. remote_port = conn->secondary_port;
  108. else if(conn->bits.conn_to_port)
  109. remote_port = conn->conn_to_port;
  110. else
  111. remote_port = conn->remote_port;
  112. result = Curl_proxyCONNECT(conn, sockindex, hostname, remote_port);
  113. conn->data->req.protop = prot_save;
  114. if(CURLE_OK != result)
  115. return result;
  116. Curl_safefree(conn->allocptr.proxyuserpwd);
  117. #else
  118. return CURLE_NOT_BUILT_IN;
  119. #endif
  120. }
  121. /* no HTTP tunnel proxy, just return */
  122. return CURLE_OK;
  123. }
  124. bool Curl_connect_complete(struct connectdata *conn)
  125. {
  126. return !conn->connect_state ||
  127. (conn->connect_state->tunnel_state == TUNNEL_COMPLETE);
  128. }
  129. bool Curl_connect_ongoing(struct connectdata *conn)
  130. {
  131. return conn->connect_state &&
  132. (conn->connect_state->tunnel_state != TUNNEL_COMPLETE);
  133. }
  134. static CURLcode connect_init(struct connectdata *conn, bool reinit)
  135. {
  136. struct http_connect_state *s;
  137. if(!reinit) {
  138. DEBUGASSERT(!conn->connect_state);
  139. s = calloc(1, sizeof(struct http_connect_state));
  140. if(!s)
  141. return CURLE_OUT_OF_MEMORY;
  142. infof(conn->data, "allocate connect buffer!\n");
  143. conn->connect_state = s;
  144. }
  145. else {
  146. DEBUGASSERT(conn->connect_state);
  147. s = conn->connect_state;
  148. }
  149. s->tunnel_state = TUNNEL_INIT;
  150. s->keepon = TRUE;
  151. s->line_start = s->connect_buffer;
  152. s->ptr = s->line_start;
  153. s->cl = 0;
  154. s->close_connection = FALSE;
  155. return CURLE_OK;
  156. }
  157. static void connect_done(struct connectdata *conn)
  158. {
  159. struct http_connect_state *s = conn->connect_state;
  160. s->tunnel_state = TUNNEL_COMPLETE;
  161. infof(conn->data, "CONNECT phase completed!\n");
  162. }
  163. static CURLcode CONNECT(struct connectdata *conn,
  164. int sockindex,
  165. const char *hostname,
  166. int remote_port)
  167. {
  168. int subversion = 0;
  169. struct Curl_easy *data = conn->data;
  170. struct SingleRequest *k = &data->req;
  171. CURLcode result;
  172. curl_socket_t tunnelsocket = conn->sock[sockindex];
  173. struct http_connect_state *s = conn->connect_state;
  174. #define SELECT_OK 0
  175. #define SELECT_ERROR 1
  176. if(Curl_connect_complete(conn))
  177. return CURLE_OK; /* CONNECT is already completed */
  178. conn->bits.proxy_connect_closed = FALSE;
  179. do {
  180. timediff_t check;
  181. if(TUNNEL_INIT == s->tunnel_state) {
  182. /* BEGIN CONNECT PHASE */
  183. char *host_port;
  184. Curl_send_buffer *req_buffer;
  185. infof(data, "Establish HTTP proxy tunnel to %s:%d\n",
  186. hostname, remote_port);
  187. /* This only happens if we've looped here due to authentication
  188. reasons, and we don't really use the newly cloned URL here
  189. then. Just free() it. */
  190. free(data->req.newurl);
  191. data->req.newurl = NULL;
  192. /* initialize a dynamic send-buffer */
  193. req_buffer = Curl_add_buffer_init();
  194. if(!req_buffer)
  195. return CURLE_OUT_OF_MEMORY;
  196. host_port = aprintf("%s:%d", hostname, remote_port);
  197. if(!host_port) {
  198. Curl_add_buffer_free(&req_buffer);
  199. return CURLE_OUT_OF_MEMORY;
  200. }
  201. /* Setup the proxy-authorization header, if any */
  202. result = Curl_http_output_auth(conn, "CONNECT", host_port, TRUE);
  203. free(host_port);
  204. if(!result) {
  205. char *host = NULL;
  206. const char *proxyconn = "";
  207. const char *useragent = "";
  208. const char *http = (conn->http_proxy.proxytype == CURLPROXY_HTTP_1_0) ?
  209. "1.0" : "1.1";
  210. bool ipv6_ip = conn->bits.ipv6_ip;
  211. char *hostheader;
  212. /* the hostname may be different */
  213. if(hostname != conn->host.name)
  214. ipv6_ip = (strchr(hostname, ':') != NULL);
  215. hostheader = /* host:port with IPv6 support */
  216. aprintf("%s%s%s:%d", ipv6_ip?"[":"", hostname, ipv6_ip?"]":"",
  217. remote_port);
  218. if(!hostheader) {
  219. Curl_add_buffer_free(&req_buffer);
  220. return CURLE_OUT_OF_MEMORY;
  221. }
  222. if(!Curl_checkProxyheaders(conn, "Host")) {
  223. host = aprintf("Host: %s\r\n", hostheader);
  224. if(!host) {
  225. free(hostheader);
  226. Curl_add_buffer_free(&req_buffer);
  227. return CURLE_OUT_OF_MEMORY;
  228. }
  229. }
  230. if(!Curl_checkProxyheaders(conn, "Proxy-Connection"))
  231. proxyconn = "Proxy-Connection: Keep-Alive\r\n";
  232. if(!Curl_checkProxyheaders(conn, "User-Agent") &&
  233. data->set.str[STRING_USERAGENT])
  234. useragent = conn->allocptr.uagent;
  235. result =
  236. Curl_add_bufferf(&req_buffer,
  237. "CONNECT %s HTTP/%s\r\n"
  238. "%s" /* Host: */
  239. "%s" /* Proxy-Authorization */
  240. "%s" /* User-Agent */
  241. "%s", /* Proxy-Connection */
  242. hostheader,
  243. http,
  244. host?host:"",
  245. conn->allocptr.proxyuserpwd?
  246. conn->allocptr.proxyuserpwd:"",
  247. useragent,
  248. proxyconn);
  249. if(host)
  250. free(host);
  251. free(hostheader);
  252. if(!result)
  253. result = Curl_add_custom_headers(conn, TRUE, req_buffer);
  254. if(!result)
  255. /* CRLF terminate the request */
  256. result = Curl_add_bufferf(&req_buffer, "\r\n");
  257. if(!result) {
  258. /* Send the connect request to the proxy */
  259. /* BLOCKING */
  260. result =
  261. Curl_add_buffer_send(&req_buffer, conn,
  262. &data->info.request_size, 0, sockindex);
  263. }
  264. req_buffer = NULL;
  265. if(result)
  266. failf(data, "Failed sending CONNECT to proxy");
  267. }
  268. Curl_add_buffer_free(&req_buffer);
  269. if(result)
  270. return result;
  271. s->tunnel_state = TUNNEL_CONNECT;
  272. s->perline = 0;
  273. } /* END CONNECT PHASE */
  274. check = Curl_timeleft(data, NULL, TRUE);
  275. if(check <= 0) {
  276. failf(data, "Proxy CONNECT aborted due to timeout");
  277. return CURLE_OPERATION_TIMEDOUT;
  278. }
  279. if(!Curl_conn_data_pending(conn, sockindex))
  280. /* return so we'll be called again polling-style */
  281. return CURLE_OK;
  282. /* at this point, the tunnel_connecting phase is over. */
  283. { /* READING RESPONSE PHASE */
  284. int error = SELECT_OK;
  285. while(s->keepon && !error) {
  286. ssize_t gotbytes;
  287. /* make sure we have space to read more data */
  288. if(s->ptr >= &s->connect_buffer[CONNECT_BUFFER_SIZE]) {
  289. failf(data, "CONNECT response too large!");
  290. return CURLE_RECV_ERROR;
  291. }
  292. /* Read one byte at a time to avoid a race condition. Wait at most one
  293. second before looping to ensure continuous pgrsUpdates. */
  294. result = Curl_read(conn, tunnelsocket, s->ptr, 1, &gotbytes);
  295. if(result == CURLE_AGAIN)
  296. /* socket buffer drained, return */
  297. return CURLE_OK;
  298. if(Curl_pgrsUpdate(conn))
  299. return CURLE_ABORTED_BY_CALLBACK;
  300. if(result) {
  301. s->keepon = FALSE;
  302. break;
  303. }
  304. else if(gotbytes <= 0) {
  305. if(data->set.proxyauth && data->state.authproxy.avail) {
  306. /* proxy auth was requested and there was proxy auth available,
  307. then deem this as "mere" proxy disconnect */
  308. conn->bits.proxy_connect_closed = TRUE;
  309. infof(data, "Proxy CONNECT connection closed\n");
  310. }
  311. else {
  312. error = SELECT_ERROR;
  313. failf(data, "Proxy CONNECT aborted");
  314. }
  315. s->keepon = FALSE;
  316. break;
  317. }
  318. if(s->keepon > TRUE) {
  319. /* This means we are currently ignoring a response-body */
  320. s->ptr = s->connect_buffer;
  321. if(s->cl) {
  322. /* A Content-Length based body: simply count down the counter
  323. and make sure to break out of the loop when we're done! */
  324. s->cl--;
  325. if(s->cl <= 0) {
  326. s->keepon = FALSE;
  327. s->tunnel_state = TUNNEL_COMPLETE;
  328. break;
  329. }
  330. }
  331. else {
  332. /* chunked-encoded body, so we need to do the chunked dance
  333. properly to know when the end of the body is reached */
  334. CHUNKcode r;
  335. ssize_t tookcareof = 0;
  336. /* now parse the chunked piece of data so that we can
  337. properly tell when the stream ends */
  338. r = Curl_httpchunk_read(conn, s->ptr, 1, &tookcareof);
  339. if(r == CHUNKE_STOP) {
  340. /* we're done reading chunks! */
  341. infof(data, "chunk reading DONE\n");
  342. s->keepon = FALSE;
  343. /* we did the full CONNECT treatment, go COMPLETE */
  344. s->tunnel_state = TUNNEL_COMPLETE;
  345. }
  346. }
  347. continue;
  348. }
  349. s->perline++; /* amount of bytes in this line so far */
  350. /* if this is not the end of a header line then continue */
  351. if(*s->ptr != 0x0a) {
  352. s->ptr++;
  353. continue;
  354. }
  355. /* convert from the network encoding */
  356. result = Curl_convert_from_network(data, s->line_start,
  357. (size_t)s->perline);
  358. /* Curl_convert_from_network calls failf if unsuccessful */
  359. if(result)
  360. return result;
  361. /* output debug if that is requested */
  362. if(data->set.verbose)
  363. Curl_debug(data, CURLINFO_HEADER_IN,
  364. s->line_start, (size_t)s->perline);
  365. if(!data->set.suppress_connect_headers) {
  366. /* send the header to the callback */
  367. int writetype = CLIENTWRITE_HEADER;
  368. if(data->set.include_header)
  369. writetype |= CLIENTWRITE_BODY;
  370. result = Curl_client_write(conn, writetype,
  371. s->line_start, s->perline);
  372. if(result)
  373. return result;
  374. }
  375. data->info.header_size += (long)s->perline;
  376. data->req.headerbytecount += (long)s->perline;
  377. /* Newlines are CRLF, so the CR is ignored as the line isn't
  378. really terminated until the LF comes. Treat a following CR
  379. as end-of-headers as well.*/
  380. if(('\r' == s->line_start[0]) ||
  381. ('\n' == s->line_start[0])) {
  382. /* end of response-headers from the proxy */
  383. s->ptr = s->connect_buffer;
  384. if((407 == k->httpcode) && !data->state.authproblem) {
  385. /* If we get a 407 response code with content length
  386. when we have no auth problem, we must ignore the
  387. whole response-body */
  388. s->keepon = 2;
  389. if(s->cl) {
  390. infof(data, "Ignore %" CURL_FORMAT_CURL_OFF_T
  391. " bytes of response-body\n", s->cl);
  392. }
  393. else if(s->chunked_encoding) {
  394. CHUNKcode r;
  395. infof(data, "Ignore chunked response-body\n");
  396. /* We set ignorebody true here since the chunked
  397. decoder function will acknowledge that. Pay
  398. attention so that this is cleared again when this
  399. function returns! */
  400. k->ignorebody = TRUE;
  401. if(s->line_start[1] == '\n') {
  402. /* this can only be a LF if the letter at index 0
  403. was a CR */
  404. s->line_start++;
  405. }
  406. /* now parse the chunked piece of data so that we can
  407. properly tell when the stream ends */
  408. r = Curl_httpchunk_read(conn, s->line_start + 1, 1, &gotbytes);
  409. if(r == CHUNKE_STOP) {
  410. /* we're done reading chunks! */
  411. infof(data, "chunk reading DONE\n");
  412. s->keepon = FALSE;
  413. /* we did the full CONNECT treatment, go to COMPLETE */
  414. s->tunnel_state = TUNNEL_COMPLETE;
  415. }
  416. }
  417. else {
  418. /* without content-length or chunked encoding, we
  419. can't keep the connection alive since the close is
  420. the end signal so we bail out at once instead */
  421. s->keepon = FALSE;
  422. }
  423. }
  424. else
  425. s->keepon = FALSE;
  426. if(!s->cl)
  427. /* we did the full CONNECT treatment, go to COMPLETE */
  428. s->tunnel_state = TUNNEL_COMPLETE;
  429. continue;
  430. }
  431. s->line_start[s->perline] = 0; /* zero terminate the buffer */
  432. if((checkprefix("WWW-Authenticate:", s->line_start) &&
  433. (401 == k->httpcode)) ||
  434. (checkprefix("Proxy-authenticate:", s->line_start) &&
  435. (407 == k->httpcode))) {
  436. bool proxy = (k->httpcode == 407) ? TRUE : FALSE;
  437. char *auth = Curl_copy_header_value(s->line_start);
  438. if(!auth)
  439. return CURLE_OUT_OF_MEMORY;
  440. result = Curl_http_input_auth(conn, proxy, auth);
  441. free(auth);
  442. if(result)
  443. return result;
  444. }
  445. else if(checkprefix("Content-Length:", s->line_start)) {
  446. if(k->httpcode/100 == 2) {
  447. /* A client MUST ignore any Content-Length or Transfer-Encoding
  448. header fields received in a successful response to CONNECT.
  449. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */
  450. infof(data, "Ignoring Content-Length in CONNECT %03d response\n",
  451. k->httpcode);
  452. }
  453. else {
  454. (void)curlx_strtoofft(s->line_start +
  455. strlen("Content-Length:"), NULL, 10, &s->cl);
  456. }
  457. }
  458. else if(Curl_compareheader(s->line_start, "Connection:", "close"))
  459. s->close_connection = TRUE;
  460. else if(checkprefix("Transfer-Encoding:", s->line_start)) {
  461. if(k->httpcode/100 == 2) {
  462. /* A client MUST ignore any Content-Length or Transfer-Encoding
  463. header fields received in a successful response to CONNECT.
  464. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */
  465. infof(data, "Ignoring Transfer-Encoding in "
  466. "CONNECT %03d response\n", k->httpcode);
  467. }
  468. else if(Curl_compareheader(s->line_start,
  469. "Transfer-Encoding:", "chunked")) {
  470. infof(data, "CONNECT responded chunked\n");
  471. s->chunked_encoding = TRUE;
  472. /* init our chunky engine */
  473. Curl_httpchunk_init(conn);
  474. }
  475. }
  476. else if(Curl_compareheader(s->line_start,
  477. "Proxy-Connection:", "close"))
  478. s->close_connection = TRUE;
  479. else if(2 == sscanf(s->line_start, "HTTP/1.%d %d",
  480. &subversion,
  481. &k->httpcode)) {
  482. /* store the HTTP code from the proxy */
  483. data->info.httpproxycode = k->httpcode;
  484. }
  485. s->perline = 0; /* line starts over here */
  486. s->ptr = s->connect_buffer;
  487. s->line_start = s->ptr;
  488. } /* while there's buffer left and loop is requested */
  489. if(Curl_pgrsUpdate(conn))
  490. return CURLE_ABORTED_BY_CALLBACK;
  491. if(error)
  492. return CURLE_RECV_ERROR;
  493. if(data->info.httpproxycode/100 != 2) {
  494. /* Deal with the possibly already received authenticate
  495. headers. 'newurl' is set to a new URL if we must loop. */
  496. result = Curl_http_auth_act(conn);
  497. if(result)
  498. return result;
  499. if(conn->bits.close)
  500. /* the connection has been marked for closure, most likely in the
  501. Curl_http_auth_act() function and thus we can kill it at once
  502. below */
  503. s->close_connection = TRUE;
  504. }
  505. if(s->close_connection && data->req.newurl) {
  506. /* Connection closed by server. Don't use it anymore */
  507. Curl_closesocket(conn, conn->sock[sockindex]);
  508. conn->sock[sockindex] = CURL_SOCKET_BAD;
  509. break;
  510. }
  511. } /* END READING RESPONSE PHASE */
  512. /* If we are supposed to continue and request a new URL, which basically
  513. * means the HTTP authentication is still going on so if the tunnel
  514. * is complete we start over in INIT state */
  515. if(data->req.newurl && (TUNNEL_COMPLETE == s->tunnel_state)) {
  516. connect_init(conn, TRUE); /* reinit */
  517. }
  518. } while(data->req.newurl);
  519. if(data->info.httpproxycode/100 != 2) {
  520. if(s->close_connection && data->req.newurl) {
  521. conn->bits.proxy_connect_closed = TRUE;
  522. infof(data, "Connect me again please\n");
  523. connect_done(conn);
  524. }
  525. else {
  526. free(data->req.newurl);
  527. data->req.newurl = NULL;
  528. /* failure, close this connection to avoid re-use */
  529. streamclose(conn, "proxy CONNECT failure");
  530. Curl_closesocket(conn, conn->sock[sockindex]);
  531. conn->sock[sockindex] = CURL_SOCKET_BAD;
  532. }
  533. /* to back to init state */
  534. s->tunnel_state = TUNNEL_INIT;
  535. if(conn->bits.proxy_connect_closed)
  536. /* this is not an error, just part of the connection negotiation */
  537. return CURLE_OK;
  538. failf(data, "Received HTTP code %d from proxy after CONNECT",
  539. data->req.httpcode);
  540. return CURLE_RECV_ERROR;
  541. }
  542. s->tunnel_state = TUNNEL_COMPLETE;
  543. /* If a proxy-authorization header was used for the proxy, then we should
  544. make sure that it isn't accidentally used for the document request
  545. after we've connected. So let's free and clear it here. */
  546. Curl_safefree(conn->allocptr.proxyuserpwd);
  547. conn->allocptr.proxyuserpwd = NULL;
  548. data->state.authproxy.done = TRUE;
  549. infof(data, "Proxy replied %d to CONNECT request\n",
  550. data->info.httpproxycode);
  551. data->req.ignorebody = FALSE; /* put it (back) to non-ignore state */
  552. conn->bits.rewindaftersend = FALSE; /* make sure this isn't set for the
  553. document request */
  554. return CURLE_OK;
  555. }
  556. void Curl_connect_free(struct Curl_easy *data)
  557. {
  558. struct connectdata *conn = data->conn;
  559. struct http_connect_state *s = conn->connect_state;
  560. if(s) {
  561. free(s);
  562. conn->connect_state = NULL;
  563. }
  564. }
  565. /*
  566. * Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
  567. * function will issue the necessary commands to get a seamless tunnel through
  568. * this proxy. After that, the socket can be used just as a normal socket.
  569. */
  570. CURLcode Curl_proxyCONNECT(struct connectdata *conn,
  571. int sockindex,
  572. const char *hostname,
  573. int remote_port)
  574. {
  575. CURLcode result;
  576. if(!conn->connect_state) {
  577. result = connect_init(conn, FALSE);
  578. if(result)
  579. return result;
  580. }
  581. result = CONNECT(conn, sockindex, hostname, remote_port);
  582. if(result || Curl_connect_complete(conn))
  583. connect_done(conn);
  584. return result;
  585. }
  586. #else
  587. void Curl_connect_free(struct Curl_easy *data)
  588. {
  589. (void)data;
  590. }
  591. #endif /* CURL_DISABLE_PROXY */