housekeeping: we updated the binaries, so we don't need to keep these copies

This commit is contained in:
Jeff Kaufman
2013-04-04 09:24:12 -04:00
parent ff20aa5998
commit aad3f2c0ea
6 changed files with 5 additions and 327 deletions
+2 -2
View File
@@ -138,8 +138,8 @@ if [ $ngx_found = yes ]; then
$ps_src/ngx_message_handler.cc \
$ps_src/pthread_shared_mem.cc \
$ps_src/ngx_request_context.cc \
$ps_src/add_headers_fetcher.cc \
$ps_src/loopback_route_fetcher.cc \
$mod_pagespeed_dir/net/instaweb/apache/add_headers_fetcher.cc \
$mod_pagespeed_dir/net/instaweb/apache/loopback_route_fetcher.cc \
$mod_pagespeed_dir/net/instaweb/apache/serf_url_async_fetcher.cc"
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES $ngx_addon_name"
CORE_LIBS="$CORE_LIBS $pagespeed_libs"
-43
View File
@@ -1,43 +0,0 @@
// Copyright 2012 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: jefftk@google.com (Jeff Kaufman)
#include "add_headers_fetcher.h"
#include "net/instaweb/http/public/async_fetch.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/http/public/request_headers.h"
namespace net_instaweb {
AddHeadersFetcher::AddHeadersFetcher(const RewriteOptions* options,
UrlAsyncFetcher* backend_fetcher)
: options_(options), backend_fetcher_(backend_fetcher) {
}
AddHeadersFetcher::~AddHeadersFetcher() {}
void AddHeadersFetcher::Fetch(const GoogleString& original_url,
MessageHandler* message_handler,
AsyncFetch* fetch) {
RequestHeaders* request_headers = fetch->request_headers();
for (int i = 0, n = options_->num_custom_fetch_headers(); i < n; ++i) {
const RewriteOptions::NameValue* nv = options_->custom_fetch_header(i);
request_headers->Replace(nv->name, nv->value);
}
backend_fetcher_->Fetch(original_url, message_handler, fetch);
}
} // namespace net_instaweb
-57
View File
@@ -1,57 +0,0 @@
// Copyright 2012 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: jefftk@google.com (Jeff Kaufman)
// This class is a simple wrapper around another fetcher that adds headers to
// requests based on settings in the rewrite options before passing them on to
// the backend fetcher.
#ifndef NET_INSTAWEB_APACHE_ADD_HEADERS_FETCHER_H_
#define NET_INSTAWEB_APACHE_ADD_HEADERS_FETCHER_H_
#include "net/instaweb/http/public/url_async_fetcher.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/string.h"
namespace net_instaweb {
class AsyncFetch;
class RewriteOptions;
class MessageHandler;
class AddHeadersFetcher : public UrlAsyncFetcher {
public:
AddHeadersFetcher(const RewriteOptions* options,
UrlAsyncFetcher* backend_fetcher);
virtual ~AddHeadersFetcher();
virtual bool SupportsHttps() const {
return backend_fetcher_->SupportsHttps();
}
virtual void Fetch(const GoogleString& url,
MessageHandler* message_handler,
AsyncFetch* callback);
private:
const RewriteOptions* const options_;
UrlAsyncFetcher* const backend_fetcher_;
DISALLOW_COPY_AND_ASSIGN(AddHeadersFetcher);
};
} // namespace net_instaweb
#endif // NET_INSTAWEB_APACHE_ADD_HEADERS_FETCHER_H_
-145
View File
@@ -1,145 +0,0 @@
// Copyright 2012 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: morlovich@google.com (Maksim Orlovich)
#include "loopback_route_fetcher.h"
#include "base/logging.h"
#include "net/instaweb/http/public/async_fetch.h"
#include "net/instaweb/http/public/meta_data.h"
#include "net/instaweb/http/public/request_headers.h"
#include "net/instaweb/http/public/url_async_fetcher.h"
#include "net/instaweb/rewriter/public/domain_lawyer.h"
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include "net/instaweb/util/public/google_url.h"
#include "net/instaweb/util/public/string.h"
#include "net/instaweb/util/public/string_util.h"
#include "apr_network_io.h"
namespace net_instaweb {
class MessageHandler;
LoopbackRouteFetcher::LoopbackRouteFetcher(
const RewriteOptions* options,
const GoogleString& own_ip,
int own_port,
UrlAsyncFetcher* backend_fetcher)
: options_(options),
own_ip_(own_ip),
own_port_(own_port),
backend_fetcher_(backend_fetcher) {
if (own_ip_.empty()) {
own_ip_ = "127.0.0.1";
}
}
LoopbackRouteFetcher::~LoopbackRouteFetcher() {
}
void LoopbackRouteFetcher::Fetch(const GoogleString& original_url,
MessageHandler* message_handler,
AsyncFetch* fetch) {
GoogleString url = original_url;
GoogleUrl parsed_url(original_url);
if (!parsed_url.is_valid()) {
// Fail immediately in case we can't parse the URL, rather than risk
// getting weird handling due to inconsistencies in parsing between us
// and backend_fetcher_.
LOG(WARNING) << "Can't parse URL:" << original_url;
fetch->Done(false);
return;
}
RequestHeaders* request_headers = fetch->request_headers();
// Check to see if the URL we hand to the backend has an origin we were never
// explicitly told of, and if so just talk to loopback.
// Note that in case of an origin mapping the parsed_url will contain the
// fetch host, not the original host, so the domain_lawyer will know about it
// and the if body will not run.
if (!options_->domain_lawyer()->IsOriginKnown(parsed_url)) {
// If there is no host header, make sure to add one, since we are about
// to munge the URL.
if (request_headers->Lookup1(HttpAttributes::kHost) == NULL) {
request_headers->Replace(HttpAttributes::kHost, parsed_url.HostAndPort());
}
GoogleUrl base;
StringPiece scheme = parsed_url.Scheme();
if ((own_port_ == 80 && scheme == "http") ||
(own_port_ == 443 && scheme == "https")) {
base.Reset(StrCat(scheme, "://", own_ip_, "/"));
} else {
base.Reset(
StrCat(scheme, "://", own_ip_, ":", IntegerToString(own_port_), "/"));
}
GoogleString rel;
parsed_url.PathAndLeaf().CopyToString(&rel);
parsed_url.Reset(base, rel);
parsed_url.Spec().CopyToString(&url);
// Note that we end up with host: containing the actual URL's host, but
// the URL containing just our IP. This is technically wrong, but the
// Serf fetcher will interpret it in the way we want it to --- it will
// connect to our IP, pass only the path portion to the host, and
// keep the host: header matching what's in the request_headers.
}
backend_fetcher_->Fetch(url, message_handler, fetch);
}
bool LoopbackRouteFetcher::IsLoopbackAddr(const apr_sockaddr_t* addr) {
if (addr->family == APR_INET) {
// 127.0.0.0/8 is the IPv4 loopback.
// Note: is network byte order, so we can do char-wide indexing into it
// consistently (but not look at the whole thing).
const char* ipbytes = reinterpret_cast<const char*>(
&addr->sa.sin.sin_addr.s_addr);
return (ipbytes[0] == 127);
} else if (addr->family == APR_INET6) {
const in6_addr& addr_v6 = addr->sa.sin6.sin6_addr;
// There are a couple of ways we can see loopbacks in IPv6: as the
// proper IPv6 loopback, ::1, or as "IPv4-compatible IPv6 address"
// of the IPv4 loopback, ::FFFF:127.x.y.z.
// Regardless, the first 10 bytes ought to be 0.
for (int b = 0; b < 10; ++b) {
if (addr_v6.s6_addr[b] != 0) {
return false;
}
}
// If first 10 are OK, check the last 6 bytes for the 2 options.
return (addr_v6.s6_addr[10] == 0xFF &&
addr_v6.s6_addr[11] == 0xFF &&
addr_v6.s6_addr[12] == 127) ||
(addr_v6.s6_addr[10] == 0 &&
addr_v6.s6_addr[11] == 0 &&
addr_v6.s6_addr[12] == 0 &&
addr_v6.s6_addr[13] == 0 &&
addr_v6.s6_addr[14] == 0 &&
addr_v6.s6_addr[15] == 1);
} else {
return false;
}
}
} // namespace net_instaweb
-74
View File
@@ -1,74 +0,0 @@
// Copyright 2012 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: morlovich@google.com (Maksim Orlovich)
//
// This fetcher routes requests to hosts that are not explicitly mentioned in
// the DomainLawyer towards our own IP, as extracted from the incoming
// connection.
#ifndef NET_INSTAWEB_APACHE_LOOPBACK_ROUTE_FETCHER_H_
#define NET_INSTAWEB_APACHE_LOOPBACK_ROUTE_FETCHER_H_
#include "net/instaweb/http/public/url_async_fetcher.h"
#include "net/instaweb/util/public/basictypes.h"
#include "net/instaweb/util/public/string.h"
struct apr_sockaddr_t;
namespace net_instaweb {
class AsyncFetch;
class RewriteOptions;
class MessageHandler;
// See file comment.
class LoopbackRouteFetcher : public UrlAsyncFetcher {
public:
// Does not take ownership of anything. own_port is the port the incoming
// request came in on, and own_ip is the same for the IP. If the
// backend_fetcher does actual fetching (and is not merely simulating it for
// testing purposes) it should be the Serf fetcher, as others may not direct
// requests this class produces properly.
// (As this fetcher may produce requests that need to connect to some IP
// but have a Host: and URL from somewhere else).
LoopbackRouteFetcher(const RewriteOptions* options,
const GoogleString& own_ip,
int own_port,
UrlAsyncFetcher* backend_fetcher);
virtual ~LoopbackRouteFetcher();
virtual bool SupportsHttps() const {
return backend_fetcher_->SupportsHttps();
}
virtual void Fetch(const GoogleString& url,
MessageHandler* message_handler,
AsyncFetch* fetch);
// Returns true if the given address is an IPv4 or IPv6 loopback.
static bool IsLoopbackAddr(const apr_sockaddr_t* addr);
private:
const RewriteOptions* const options_;
GoogleString own_ip_;
int own_port_;
UrlAsyncFetcher* const backend_fetcher_;
DISALLOW_COPY_AND_ASSIGN(LoopbackRouteFetcher);
};
} // namespace net_instaweb
#endif // NET_INSTAWEB_APACHE_LOOPBACK_ROUTE_FETCHER_H_
+3 -6
View File
@@ -21,14 +21,11 @@
#include "ngx_request_context.h"
#include "ngx_rewrite_options.h"
#include "ngx_rewrite_driver_factory.h"
// TODO(oschaaf): next time we update the binaries, we can drop our own
// versions of add_headers_fetcher and loopback_route_fetcher
#include "add_headers_fetcher.h"
#include "loopback_route_fetcher.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/apache/add_headers_fetcher.h"
#include "net/instaweb/apache/loopback_route_fetcher.h"
#include "net/instaweb/rewriter/public/rewrite_driver.h"
#include "net/instaweb/rewriter/public/rewrite_stats.h"
#include "net/instaweb/system/public/system_caches.h"
#include "net/instaweb/util/public/shared_mem_statistics.h"
#include "net/instaweb/util/public/split_statistics.h"
#include "net/instaweb/util/public/statistics.h"