http_proxy.c 22 KB

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