metaproxy  1.21.0
Private Member Functions | Private Attributes | Friends | List of all members
metaproxy_1::filter::HTTPClient::Rep Class Reference
Collaboration diagram for metaproxy_1::filter::HTTPClient::Rep:
Collaboration graph

Private Member Functions

void proxy (mp::Package &package)
 
 Rep ()
 

Private Attributes

std::string proxy_host
 
std::string default_host
 
int max_redirects
 
bool x_forwarded_for
 
bool bind_host
 

Friends

class HTTPClient
 

Detailed Description

Definition at line 48 of file filter_http_client.cpp.

Constructor & Destructor Documentation

◆ Rep()

mp::filter::HTTPClient::Rep::Rep ( )
private

Member Function Documentation

◆ proxy()

void mp::filter::HTTPClient::Rep::proxy ( mp::Package &  package)
private

Definition at line 76 of file filter_http_client.cpp.

77 {
78  Z_GDU *req_gdu = package.request().get();
79  if (req_gdu && req_gdu->which == Z_GDU_HTTP_Request)
80  {
81  Z_HTTP_Request *hreq = req_gdu->u.HTTP_Request;
82  Z_GDU *res_gdu = 0;
83  mp::odr o;
84  yaz_url_t yaz_url = yaz_url_create();
85  const char *http_proxy =
86  z_HTTP_header_remove(&hreq->headers, "X-Metaproxy-Proxy");
87 
88  if (!http_proxy)
89  http_proxy = proxy_host.c_str();
90 
91  if (*http_proxy)
92  yaz_url_set_proxy(yaz_url, http_proxy);
93 
94  yaz_url_set_max_redirects(yaz_url, max_redirects);
95 
96  if (x_forwarded_for)
97  {
98  std::string peer_name2 = package.origin().get_address();
99  const char *peer_name1 =
100  z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For");
101  std::string pcomb;
102  if (peer_name1)
103  {
104  pcomb.append(peer_name1);
105  pcomb.append(", ");
106  }
107  pcomb.append(peer_name2);
108  z_HTTP_header_set(o, &hreq->headers, "X-Forwarded-For",
109  pcomb.c_str());
110  }
111  std::string uri;
112  if (hreq->path[0] == '/')
113  {
114  if (default_host.length())
115  uri = default_host + hreq->path;
116  }
117  else
118  uri = hreq->path;
119 
120  if (bind_host)
121  {
122  std::string host = package.origin().get_bind_address();
123  uri.append(" ");
124  uri.append(host);
125  }
126  if (!uri.length())
127  {
128  res_gdu = o.create_HTTP_Response_details(
129  package.session(),
130  hreq, 404,
131  "http_client: no target URI specified");
132  }
133  else
134  {
135  Z_HTTP_Response * http_response =
136  yaz_url_exec(yaz_url, uri.c_str(), hreq->method,
137  hreq->headers, hreq->content_buf,
138  hreq->content_len);
139  if (http_response)
140  {
141  res_gdu = o.create_HTTP_Response(package.session(), hreq, 200);
142  z_HTTP_header_remove(&http_response->headers, "Transfer-Encoding");
143  res_gdu->u.HTTP_Response = http_response;
144  }
145  else
146  {
147  res_gdu = o.create_HTTP_Response_details(
148  package.session(),
149  hreq, 502, yaz_url_get_error(yaz_url));
150  }
151  }
152  package.response() = res_gdu;
153  yaz_url_destroy(yaz_url);
154  }
155  else
156  package.move();
157 }

Friends And Related Function Documentation

◆ HTTPClient

friend class HTTPClient
friend

Definition at line 49 of file filter_http_client.cpp.

Member Data Documentation

◆ bind_host

bool metaproxy_1::filter::HTTPClient::Rep::bind_host
private

Definition at line 55 of file filter_http_client.cpp.

◆ default_host

std::string metaproxy_1::filter::HTTPClient::Rep::default_host
private

Definition at line 52 of file filter_http_client.cpp.

◆ max_redirects

int metaproxy_1::filter::HTTPClient::Rep::max_redirects
private

Definition at line 53 of file filter_http_client.cpp.

◆ proxy_host

std::string metaproxy_1::filter::HTTPClient::Rep::proxy_host
private

Definition at line 51 of file filter_http_client.cpp.

◆ x_forwarded_for

bool metaproxy_1::filter::HTTPClient::Rep::x_forwarded_for
private

Definition at line 54 of file filter_http_client.cpp.


The documentation for this class was generated from the following file: