Lines Matching refs:Proxy
20 * @file proxy.c
159 struct Proxy
412 struct Proxy *proxy = (struct Proxy *)SPDY_get_cls_from_request(request);
414 if(!store_in_buffer(buf, size, &proxy->received_body, &proxy->received_body_size))
420 proxy->receiving_done = !more;
426 if(proxy->is_curl_read_paused)
428 if(CURLE_OK != (ret = curl_easy_pause(proxy->curl_handle, CURLPAUSE_CONT)))
447 struct Proxy *proxy = (struct Proxy *)cls;
451 assert(!proxy->spdy_error);
453 if(proxy->curl_error)
459 if(!proxy->http_body_size)//nothing to write now
462 if(proxy->curl_done || proxy->curl_error) *more = false;
466 ret = get_from_buffer(&(proxy->http_body), &(proxy->http_body_size), buffer, max);
474 if((proxy->curl_done || proxy->curl_error) && 0 == proxy->http_body_size) *more = false;
483 cleanup(struct Proxy *proxy)
487 //fprintf(stderr, "free proxy for %s\n", proxy->url);
489 if(CURLM_OK != (ret = curl_multi_remove_handle(multi_handle, proxy->curl_handle)))
497 curl_slist_free_all(proxy->curl_headers);
498 curl_easy_cleanup(proxy->curl_handle);
500 free(proxy->url);
501 free(proxy);
513 struct Proxy *proxy = (struct Proxy *)cls;
517 free(proxy->http_body);
518 proxy->http_body = NULL;
519 proxy->spdy_error = true;
521 cleanup(proxy);
531 struct Proxy *proxy = (struct Proxy *)userp;
544 if(!*(proxy->session_alive))
547 proxy->spdy_error = true;
548 proxy->curl_error = true;
553 if(NULL != proxy->response) return 0;
558 if(NULL == (proxy->response = SPDY_build_response_with_callback(proxy->status,
559 proxy->status_msg,
560 proxy->version,
561 proxy->headers,
563 proxy,
568 SPDY_name_value_destroy(proxy->headers);
569 proxy->headers = NULL;
570 free(proxy->status_msg);
571 proxy->status_msg = NULL;
572 free(proxy->version);
573 proxy->version = NULL;
575 if(SPDY_YES != SPDY_queue_response(proxy->request,
576 proxy->response,
580 proxy))
584 proxy->spdy_error = true;
585 proxy->curl_error = true;
586 PRINT_VERBOSE2("no queue in curl_header_cb for %s", proxy->url);
587 SPDY_destroy_response(proxy->response);
588 proxy->response = NULL;
598 if(NULL == proxy->version)
605 if(NULL == (proxy->version = strndup(line, i - pos)))
613 proxy->status = atoi(status);
620 if(NULL == (proxy->status_msg = strndup(&(line[pos]), i - pos)))
623 PRINT_VERBOSE2("Header line received '%s' '%i' '%s' ", proxy->version, proxy->status, proxy->status_msg);
645 if(SPDY_YES != SPDY_name_value_add(proxy->headers, name, ""))
657 if(SPDY_YES != (ret = SPDY_name_value_add(proxy->headers, name, value)))
660 if(NULL != (values = SPDY_name_value_lookup(proxy->headers, name, &num_values)))
686 struct Proxy *proxy = (struct Proxy *)userp;
689 if(!*(proxy->session_alive))
692 proxy->spdy_error = true;
693 proxy->curl_error = true;
697 if(!store_in_buffer(contents, realsize, &proxy->http_body, &proxy->http_body_size))
700 proxy->curl_error = true;
704 if(NULL == proxy->http_body)
705 proxy->http_body = malloc(realsize);
707 proxy->http_body = realloc(proxy->http_body, proxy->http_body_size + realsize);
708 if(NULL == proxy->http_body)
714 memcpy(proxy->http_body + proxy->http_body_size, contents, realsize);
715 proxy->http_body_size += realsize;
731 struct Proxy *proxy = (struct Proxy *)userp;
735 if((proxy->receiving_done && !proxy->received_body_size) || !proxy
741 if(!*(proxy->session_alive))
747 if(!proxy->received_body_size)//nothing to write now
750 proxy->is_curl_read_paused = true;
754 ret = get_from_buffer(&(proxy->received_body), &(proxy->received_body_size), ptr, max);
762 if(max >= proxy->received_body_size)
764 ret = proxy->received_body_size;
770 if(NULL == (newbody = malloc(proxy->received_body_size - max)))
775 memcpy(newbody, proxy->received_body + max, proxy->received_body_size - max);
777 memcpy(ptr, proxy->received_body, ret);
778 free(proxy->received_body);
779 proxy->received_body = newbody;
780 proxy->received_body_size -= ret;
792 struct Proxy *proxy = (struct Proxy *)cls;
793 struct curl_slist **curl_headers = (&(proxy->curl_headers));
846 struct Proxy *proxy;
851 proxy = SPDY_get_cls_from_request(request);
852 if(NULL != proxy)
861 if(NULL == (proxy = malloc(sizeof(struct Proxy))))
863 memset(proxy, 0, sizeof(struct Proxy));
865 //fprintf(stderr, "new proxy for %s\n", path);
869 proxy->session_alive = SPDY_get_cls_from_session(session);
870 assert(NULL != proxy->session_alive);
872 SPDY_set_cls_to_request(request, proxy);
874 proxy->request = request;
875 proxy->is_with_body_data = more;
876 if(NULL == (proxy->headers = SPDY_name_value_create()))
882 ret = asprintf(&(proxy->url),"%s://%s%s", scheme, glob_opt.http_backend, path);
884 ret = asprintf(&(proxy->url),"%s://%s%s", scheme, host, path);
888 ret = parse_uri(&uri_preg, proxy->url, &uri);
901 ret = asprintf(&(proxy->url),"%s://%s%s", uri->scheme, glob_opt.http_backend, uri->path_and_more);
906 if(NULL == (proxy->url = strdup(path)))
912 PRINT_VERBOSE2("curl will request '%s'", proxy->url);
914 SPDY_name_value_iterate(headers, &iterate_cb, proxy);
916 if(NULL == (proxy->curl_handle = curl_easy_init()))
923 CURL_SETOPT(proxy->curl_handle, CURLOPT_VERBOSE, 1);
927 if(NULL == (proxy->curl_headers = curl_slist_append(proxy->curl_headers, "Expect:")))
929 CURL_SETOPT(proxy->curl_handle, CURLOPT_POST, 1);
930 CURL_SETOPT(proxy->curl_handle, CURLOPT_READFUNCTION, curl_read_cb);
931 CURL_SETOPT(proxy->curl_handle, CURLOPT_READDATA, proxy);
935 CURL_SETOPT(proxy->curl_handle, CURLOPT_TIMEOUT, glob_opt.timeout);
936 CURL_SETOPT(proxy->curl_handle, CURLOPT_URL, proxy->url);
938 CURL_SETOPT(proxy->curl_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
939 CURL_SETOPT(proxy->curl_handle, CURLOPT_WRITEFUNCTION, curl_write_cb);
940 CURL_SETOPT(proxy->curl_handle, CURLOPT_WRITEDATA, proxy);
941 CURL_SETOPT(proxy->curl_handle, CURLOPT_HEADERFUNCTION, curl_header_cb);
942 CURL_SETOPT(proxy->curl_handle, CURLOPT_HEADERDATA, proxy);
943 CURL_SETOPT(proxy->curl_handle, CURLOPT_PRIVATE, proxy);
944 CURL_SETOPT(proxy->curl_handle, CURLOPT_HTTPHEADER, proxy->curl_headers);
945 CURL_SETOPT(proxy->curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);//TODO
946 CURL_SETOPT(proxy->curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
948 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
950 CURL_SETOPT(proxy->curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
952 if(CURLM_OK != (ret = curl_multi_add_handle(multi_handle, proxy->curl_handle)))
989 struct Proxy *proxy;
1164 proxy = (struct Proxy *)curl_private;
1167 proxy->curl_done = true;
1169 //TODO what happens with proxy when the client resets a stream
1175 PRINT_VERBOSE2("bad curl result (%i) for '%s'", msg->data.result, proxy->url);
1176 if(proxy->spdy_done || proxy->spdy_error || (NULL == proxy->response && !*(proxy->session_alive)))
1179 SPDY_name_value_destroy(proxy->headers);
1180 SPDY_destroy_request(proxy->request);
1181 SPDY_destroy_response(proxy->response);
1182 cleanup(proxy);
1184 else if(NULL == proxy->response && *(proxy->session_alive))
1188 SPDY_name_value_destroy(proxy->headers);
1189 proxy->headers = NULL;
1190 if(NULL == (proxy->response = SPDY_build_response(SPDY_HTTP_BAD_GATEWAY,
1197 if(SPDY_YES != SPDY_queue_response(proxy->request,
1198 proxy->response,
1202 proxy))
1206 SPDY_destroy_request(proxy->request);
1207 SPDY_destroy_response(proxy->response);
1208 cleanup(proxy);
1213 proxy->curl_error = true;
1272 " -b, --backend-server If set, the proxy will connect always to it.\n"
1273 " Otherwise the proxy will connect to the URL\n"
1287 " -t, --transparent If set, the proxy will fetch an URL which\n"