+ /* Connect to proxy if requested (command line option). */
+ if (NULL != use_proxy_host && NULL != use_proxy_port) {
+ fprintf(server_fd, "CONNECT %s:%s HTTP/1.0\r\n", host, port);
+ fprintf(server_fd, "\r\n");
+
+ /* Read response line from proxy server. */
+ result = read_http_request(server_fd, buffer, sizeof(buffer));
+ if (result == -1) {
+ /* Read error. */
+ send_close_forwarding_failure(client_fd);
+ return;
+ } else if (result == -2) {
+ /* EOF */
+ fclose(server_fd);
+ send_close_forwarding_failure(client_fd);
+ return;
+ }
+
+ /* Check response of proxy server. */
+ if (0 != strncmp(buffer, "HTTP/1.0 200", 12)) {
+#ifdef DEBUG
+ printf(" bad proxy response\n");
+#endif
+ fclose(server_fd);
+ send_close_forwarding_failure(client_fd);
+ return;
+ }
+ }
+
+#ifdef DEBUG
+ printf(" connection to server established\n");
+#endif
+