http_proxy.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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. /* a failed connection is marked for closure to prevent (bad) re-use or
  56. similar */
  57. connclose(conn, "TLS handshake failed");
  58. }
  59. return result;
  60. #else
  61. (void) conn;
  62. (void) sockindex;
  63. return CURLE_NOT_BUILT_IN;
  64. #endif
  65. }
  66. CURLcode Curl_proxy_connect(struct connectdata *conn, int sockindex)
  67. {
  68. if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
  69. const CURLcode result = https_proxy_connect(conn, sockindex);
  70. if(result)
  71. return result;
  72. if(!conn->bits.proxy_ssl_connected[sockindex])
  73. return result; /* wait for HTTPS proxy SSL initialization to complete */
  74. }
  75. if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
  76. #ifndef CURL_DISABLE_PROXY
  77. /* for [protocol] tunneled through HTTP proxy */
  78. struct HTTP http_proxy;
  79. void *prot_save;
  80. const char *hostname;
  81. int remote_port;
  82. CURLcode result;
  83. /* BLOCKING */
  84. /* We want "seamless" operations through HTTP proxy tunnel */
  85. /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the
  86. * member conn->proto.http; we want [protocol] through HTTP and we have
  87. * to change the member temporarily for connecting to the HTTP
  88. * proxy. After Curl_proxyCONNECT we have to set back the member to the
  89. * original pointer
  90. *
  91. * This function might be called several times in the multi interface case
  92. * if the proxy's CONNECT response is not instant.
  93. */
  94. prot_save = conn->data->req.protop;
  95. memset(&http_proxy, 0, sizeof(http_proxy));
  96. conn->data->req.protop = &http_proxy;
  97. connkeep(conn, "HTTP proxy CONNECT");
  98. /* for the secondary socket (FTP), use the "connect to host"
  99. * but ignore the "connect to port" (use the secondary port)
  100. */
  101. if(conn->bits.conn_to_host)
  102. hostname = conn->conn_to_host.name;
  103. else if(sockindex == SECONDARYSOCKET)
  104. hostname = conn->secondaryhostname;
  105. else
  106. hostname = conn->host.name;
  107. if(sockindex == SECONDARYSOCKET)
  108. remote_port = conn->secondary_port;
  109. else if(conn->bits.conn_to_port)
  110. remote_port = conn->conn_to_port;
  111. else
  112. remote_port = conn->remote_port;
  113. result = Curl_proxyCONNECT(conn, sockindex, hostname, remote_port);
  114. conn->data->req.protop = prot_save;
  115. if(CURLE_OK != result)
  116. return result;
  117. Curl_safefree(conn->allocptr.proxyuserpwd);
  118. #else
  119. return CURLE_NOT_BUILT_IN;
  120. #endif
  121. }
  122. /* no HTTP tunnel proxy, just return */
  123. return CURLE_OK;
  124. }
  125. bool Curl_connect_complete(struct connectdata *conn)
  126. {
  127. return !conn->connect_state ||
  128. (conn->connect_state->tunnel_state == TUNNEL_COMPLETE);
  129. }
  130. bool Curl_connect_ongoing(struct connectdata *conn)
  131. {
  132. return conn->connect_state &&
  133. (conn->connect_state->tunnel_state != TUNNEL_COMPLETE);
  134. }
  135. static CURLcode connect_init(struct connectdata *conn, bool reinit)
  136. {
  137. struct http_connect_state *s;
  138. if(!reinit) {
  139. DEBUGASSERT(!conn->connect_state);
  140. s = calloc(1, sizeof(struct http_connect_state));
  141. if(!s)
  142. return CURLE_OUT_OF_MEMORY;
  143. infof(conn->data, "allocate connect buffer!\n");
  144. conn->connect_state = s;
  145. Curl_dyn_init(&s->rcvbuf, DYN_PROXY_CONNECT_HEADERS);
  146. }
  147. else {
  148. DEBUGASSERT(conn->connect_state);
  149. s = conn->connect_state;
  150. Curl_dyn_reset(&s->rcvbuf);
  151. }
  152. s->tunnel_state = TUNNEL_INIT;
  153. s->keepon = TRUE;
  154. s->cl = 0;
  155. s->close_connection = FALSE;
  156. return CURLE_OK;
  157. }
  158. static void connect_done(struct connectdata *conn)
  159. {
  160. struct http_connect_state *s = conn->connect_state;
  161. s->tunnel_state = TUNNEL_COMPLETE;
  162. Curl_dyn_free(&s->rcvbuf);
  163. infof(conn->data, "CONNECT phase completed!\n");
  164. }
  165. static CURLcode CONNECT(struct connectdata *conn,
  166. int sockindex,
  167. const char *hostname,
  168. int remote_port)
  169. {
  170. int subversion = 0;
  171. struct Curl_easy *data = conn->data;
  172. struct SingleRequest *k = &data->req;
  173. CURLcode result;
  174. curl_socket_t tunnelsocket = conn->sock[sockindex];
  175. struct http_connect_state *s = conn->connect_state;
  176. char *linep;
  177. size_t perline;
  178. #define SELECT_OK 0
  179. #define SELECT_ERROR 1
  180. if(Curl_connect_complete(conn))
  181. return CURLE_OK; /* CONNECT is already completed */
  182. conn->bits.proxy_connect_closed = FALSE;
  183. do {
  184. timediff_t check;
  185. if(TUNNEL_INIT == s->tunnel_state) {
  186. /* BEGIN CONNECT PHASE */
  187. char *host_port;
  188. struct dynbuf req;
  189. infof(data, "Establish HTTP proxy tunnel to %s:%d\n",
  190. hostname, remote_port);
  191. /* This only happens if we've looped here due to authentication
  192. reasons, and we don't really use the newly cloned URL here
  193. then. Just free() it. */
  194. free(data->req.newurl);
  195. data->req.newurl = NULL;
  196. host_port = aprintf("%s:%d", hostname, remote_port);
  197. if(!host_port)
  198. return CURLE_OUT_OF_MEMORY;
  199. /* initialize a dynamic send-buffer */
  200. Curl_dyn_init(&req, DYN_HTTP_REQUEST);
  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_dyn_free(&req);
  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_dyn_free(&req);
  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_dyn_addf(&req,
  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);
  254. if(!result)
  255. /* CRLF terminate the request */
  256. result = Curl_dyn_add(&req, "\r\n");
  257. if(!result) {
  258. /* Send the connect request to the proxy */
  259. /* BLOCKING */
  260. result = Curl_buffer_send(&req, conn, &data->info.request_size, 0,
  261. sockindex);
  262. }
  263. if(result)
  264. failf(data, "Failed sending CONNECT to proxy");
  265. }
  266. Curl_dyn_free(&req);
  267. if(result)
  268. return result;
  269. s->tunnel_state = TUNNEL_CONNECT;
  270. } /* END CONNECT PHASE */
  271. check = Curl_timeleft(data, NULL, TRUE);
  272. if(check <= 0) {
  273. failf(data, "Proxy CONNECT aborted due to timeout");
  274. return CURLE_OPERATION_TIMEDOUT;
  275. }
  276. if(!Curl_conn_data_pending(conn, sockindex))
  277. /* return so we'll be called again polling-style */
  278. return CURLE_OK;
  279. /* at this point, the tunnel_connecting phase is over. */
  280. { /* READING RESPONSE PHASE */
  281. int error = SELECT_OK;
  282. while(s->keepon) {
  283. ssize_t gotbytes;
  284. char byte;
  285. /* Read one byte at a time to avoid a race condition. Wait at most one
  286. second before looping to ensure continuous pgrsUpdates. */
  287. result = Curl_read(conn, tunnelsocket, &byte, 1, &gotbytes);
  288. if(result == CURLE_AGAIN)
  289. /* socket buffer drained, return */
  290. return CURLE_OK;
  291. if(Curl_pgrsUpdate(conn))
  292. return CURLE_ABORTED_BY_CALLBACK;
  293. if(result) {
  294. s->keepon = FALSE;
  295. break;
  296. }
  297. else if(gotbytes <= 0) {
  298. if(data->set.proxyauth && data->state.authproxy.avail) {
  299. /* proxy auth was requested and there was proxy auth available,
  300. then deem this as "mere" proxy disconnect */
  301. conn->bits.proxy_connect_closed = TRUE;
  302. infof(data, "Proxy CONNECT connection closed\n");
  303. }
  304. else {
  305. error = SELECT_ERROR;
  306. failf(data, "Proxy CONNECT aborted");
  307. }
  308. s->keepon = FALSE;
  309. break;
  310. }
  311. if(s->keepon > TRUE) {
  312. /* This means we are currently ignoring a response-body */
  313. if(s->cl) {
  314. /* A Content-Length based body: simply count down the counter
  315. and make sure to break out of the loop when we're done! */
  316. s->cl--;
  317. if(s->cl <= 0) {
  318. s->keepon = FALSE;
  319. s->tunnel_state = TUNNEL_COMPLETE;
  320. break;
  321. }
  322. }
  323. else {
  324. /* chunked-encoded body, so we need to do the chunked dance
  325. properly to know when the end of the body is reached */
  326. CHUNKcode r;
  327. CURLcode extra;
  328. ssize_t tookcareof = 0;
  329. /* now parse the chunked piece of data so that we can
  330. properly tell when the stream ends */
  331. r = Curl_httpchunk_read(conn, &byte, 1, &tookcareof, &extra);
  332. if(r == CHUNKE_STOP) {
  333. /* we're done reading chunks! */
  334. infof(data, "chunk reading DONE\n");
  335. s->keepon = FALSE;
  336. /* we did the full CONNECT treatment, go COMPLETE */
  337. s->tunnel_state = TUNNEL_COMPLETE;
  338. }
  339. }
  340. continue;
  341. }
  342. if(Curl_dyn_addn(&s->rcvbuf, &byte, 1)) {
  343. failf(data, "CONNECT response too large!");
  344. return CURLE_RECV_ERROR;
  345. }
  346. /* if this is not the end of a header line then continue */
  347. if(byte != 0x0a)
  348. continue;
  349. linep = Curl_dyn_ptr(&s->rcvbuf);
  350. perline = Curl_dyn_len(&s->rcvbuf); /* amount of bytes in this line */
  351. /* convert from the network encoding */
  352. result = Curl_convert_from_network(data, linep, perline);
  353. /* Curl_convert_from_network calls failf if unsuccessful */
  354. if(result)
  355. return result;
  356. /* output debug if that is requested */
  357. if(data->set.verbose)
  358. Curl_debug(data, CURLINFO_HEADER_IN, linep, perline);
  359. if(!data->set.suppress_connect_headers) {
  360. /* send the header to the callback */
  361. int writetype = CLIENTWRITE_HEADER;
  362. if(data->set.include_header)
  363. writetype |= CLIENTWRITE_BODY;
  364. result = Curl_client_write(conn, writetype, linep, perline);
  365. if(result)
  366. return result;
  367. }
  368. data->info.header_size += (long)perline;
  369. data->req.headerbytecount += (long)perline;
  370. /* Newlines are CRLF, so the CR is ignored as the line isn't
  371. really terminated until the LF comes. Treat a following CR
  372. as end-of-headers as well.*/
  373. if(('\r' == linep[0]) ||
  374. ('\n' == linep[0])) {
  375. /* end of response-headers from the proxy */
  376. if((407 == k->httpcode) && !data->state.authproblem) {
  377. /* If we get a 407 response code with content length
  378. when we have no auth problem, we must ignore the
  379. whole response-body */
  380. s->keepon = 2;
  381. if(s->cl) {
  382. infof(data, "Ignore %" CURL_FORMAT_CURL_OFF_T
  383. " bytes of response-body\n", s->cl);
  384. }
  385. else if(s->chunked_encoding) {
  386. CHUNKcode r;
  387. CURLcode extra;
  388. infof(data, "Ignore chunked response-body\n");
  389. /* We set ignorebody true here since the chunked decoder
  390. function will acknowledge that. Pay attention so that this is
  391. cleared again when this function returns! */
  392. k->ignorebody = TRUE;
  393. if(linep[1] == '\n')
  394. /* this can only be a LF if the letter at index 0 was a CR */
  395. linep++;
  396. /* now parse the chunked piece of data so that we can properly
  397. tell when the stream ends */
  398. r = Curl_httpchunk_read(conn, linep + 1, 1, &gotbytes,
  399. &extra);
  400. if(r == CHUNKE_STOP) {
  401. /* we're done reading chunks! */
  402. infof(data, "chunk reading DONE\n");
  403. s->keepon = FALSE;
  404. /* we did the full CONNECT treatment, go to COMPLETE */
  405. s->tunnel_state = TUNNEL_COMPLETE;
  406. }
  407. }
  408. else {
  409. /* without content-length or chunked encoding, we
  410. can't keep the connection alive since the close is
  411. the end signal so we bail out at once instead */
  412. s->keepon = FALSE;
  413. }
  414. }
  415. else
  416. s->keepon = FALSE;
  417. if(!s->cl)
  418. /* we did the full CONNECT treatment, go to COMPLETE */
  419. s->tunnel_state = TUNNEL_COMPLETE;
  420. continue;
  421. }
  422. if((checkprefix("WWW-Authenticate:", linep) &&
  423. (401 == k->httpcode)) ||
  424. (checkprefix("Proxy-authenticate:", linep) &&
  425. (407 == k->httpcode))) {
  426. bool proxy = (k->httpcode == 407) ? TRUE : FALSE;
  427. char *auth = Curl_copy_header_value(linep);
  428. if(!auth)
  429. return CURLE_OUT_OF_MEMORY;
  430. result = Curl_http_input_auth(conn, proxy, auth);
  431. free(auth);
  432. if(result)
  433. return result;
  434. }
  435. else if(checkprefix("Content-Length:", linep)) {
  436. if(k->httpcode/100 == 2) {
  437. /* A client MUST ignore any Content-Length or Transfer-Encoding
  438. header fields received in a successful response to CONNECT.
  439. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */
  440. infof(data, "Ignoring Content-Length in CONNECT %03d response\n",
  441. k->httpcode);
  442. }
  443. else {
  444. (void)curlx_strtoofft(linep +
  445. strlen("Content-Length:"), NULL, 10, &s->cl);
  446. }
  447. }
  448. else if(Curl_compareheader(linep, "Connection:", "close"))
  449. s->close_connection = TRUE;
  450. else if(checkprefix("Transfer-Encoding:", linep)) {
  451. if(k->httpcode/100 == 2) {
  452. /* A client MUST ignore any Content-Length or Transfer-Encoding
  453. header fields received in a successful response to CONNECT.
  454. "Successful" described as: 2xx (Successful). RFC 7231 4.3.6 */
  455. infof(data, "Ignoring Transfer-Encoding in "
  456. "CONNECT %03d response\n", k->httpcode);
  457. }
  458. else if(Curl_compareheader(linep,
  459. "Transfer-Encoding:", "chunked")) {
  460. infof(data, "CONNECT responded chunked\n");
  461. s->chunked_encoding = TRUE;
  462. /* init our chunky engine */
  463. Curl_httpchunk_init(conn);
  464. }
  465. }
  466. else if(Curl_compareheader(linep, "Proxy-Connection:", "close"))
  467. s->close_connection = TRUE;
  468. else if(2 == sscanf(linep, "HTTP/1.%d %d",
  469. &subversion,
  470. &k->httpcode)) {
  471. /* store the HTTP code from the proxy */
  472. data->info.httpproxycode = k->httpcode;
  473. }
  474. Curl_dyn_reset(&s->rcvbuf);
  475. } /* while there's buffer left and loop is requested */
  476. if(Curl_pgrsUpdate(conn))
  477. return CURLE_ABORTED_BY_CALLBACK;
  478. if(error)
  479. return CURLE_RECV_ERROR;
  480. if(data->info.httpproxycode/100 != 2) {
  481. /* Deal with the possibly already received authenticate
  482. headers. 'newurl' is set to a new URL if we must loop. */
  483. result = Curl_http_auth_act(conn);
  484. if(result)
  485. return result;
  486. if(conn->bits.close)
  487. /* the connection has been marked for closure, most likely in the
  488. Curl_http_auth_act() function and thus we can kill it at once
  489. below */
  490. s->close_connection = TRUE;
  491. }
  492. if(s->close_connection && data->req.newurl) {
  493. /* Connection closed by server. Don't use it anymore */
  494. Curl_closesocket(conn, conn->sock[sockindex]);
  495. conn->sock[sockindex] = CURL_SOCKET_BAD;
  496. break;
  497. }
  498. } /* END READING RESPONSE PHASE */
  499. /* If we are supposed to continue and request a new URL, which basically
  500. * means the HTTP authentication is still going on so if the tunnel
  501. * is complete we start over in INIT state */
  502. if(data->req.newurl && (TUNNEL_COMPLETE == s->tunnel_state)) {
  503. connect_init(conn, TRUE); /* reinit */
  504. }
  505. } while(data->req.newurl);
  506. if(data->info.httpproxycode/100 != 2) {
  507. if(s->close_connection && data->req.newurl) {
  508. conn->bits.proxy_connect_closed = TRUE;
  509. infof(data, "Connect me again please\n");
  510. connect_done(conn);
  511. }
  512. else {
  513. free(data->req.newurl);
  514. data->req.newurl = NULL;
  515. /* failure, close this connection to avoid re-use */
  516. streamclose(conn, "proxy CONNECT failure");
  517. Curl_closesocket(conn, conn->sock[sockindex]);
  518. conn->sock[sockindex] = CURL_SOCKET_BAD;
  519. }
  520. /* to back to init state */
  521. s->tunnel_state = TUNNEL_INIT;
  522. if(conn->bits.proxy_connect_closed)
  523. /* this is not an error, just part of the connection negotiation */
  524. return CURLE_OK;
  525. Curl_dyn_free(&s->rcvbuf);
  526. failf(data, "Received HTTP code %d from proxy after CONNECT",
  527. data->req.httpcode);
  528. return CURLE_RECV_ERROR;
  529. }
  530. s->tunnel_state = TUNNEL_COMPLETE;
  531. /* If a proxy-authorization header was used for the proxy, then we should
  532. make sure that it isn't accidentally used for the document request
  533. after we've connected. So let's free and clear it here. */
  534. Curl_safefree(conn->allocptr.proxyuserpwd);
  535. conn->allocptr.proxyuserpwd = NULL;
  536. data->state.authproxy.done = TRUE;
  537. data->state.authproxy.multipass = FALSE;
  538. infof(data, "Proxy replied %d to CONNECT request\n",
  539. data->info.httpproxycode);
  540. data->req.ignorebody = FALSE; /* put it (back) to non-ignore state */
  541. conn->bits.rewindaftersend = FALSE; /* make sure this isn't set for the
  542. document request */
  543. Curl_dyn_free(&s->rcvbuf);
  544. return CURLE_OK;
  545. }
  546. void Curl_connect_free(struct Curl_easy *data)
  547. {
  548. struct connectdata *conn = data->conn;
  549. struct http_connect_state *s = conn->connect_state;
  550. if(s) {
  551. free(s);
  552. conn->connect_state = NULL;
  553. }
  554. }
  555. /*
  556. * Curl_proxyCONNECT() requires that we're connected to a HTTP proxy. This
  557. * function will issue the necessary commands to get a seamless tunnel through
  558. * this proxy. After that, the socket can be used just as a normal socket.
  559. */
  560. CURLcode Curl_proxyCONNECT(struct connectdata *conn,
  561. int sockindex,
  562. const char *hostname,
  563. int remote_port)
  564. {
  565. CURLcode result;
  566. if(!conn->connect_state) {
  567. result = connect_init(conn, FALSE);
  568. if(result)
  569. return result;
  570. }
  571. result = CONNECT(conn, sockindex, hostname, remote_port);
  572. if(result || Curl_connect_complete(conn))
  573. connect_done(conn);
  574. return result;
  575. }
  576. #else
  577. void Curl_connect_free(struct Curl_easy *data)
  578. {
  579. (void)data;
  580. }
  581. #endif /* CURL_DISABLE_PROXY */