1
// Copyright 2012 Google Inc.
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
// Author: morlovich@google.com (Maksim Orlovich)
17
// This fetcher routes requests to hosts that are not explicitly mentioned in
18
// the DomainLawyer towards our own IP, as extracted from the incoming
21
#ifndef NET_INSTAWEB_SYSTEM_PUBLIC_LOOPBACK_ROUTE_FETCHER_H_
22
#define NET_INSTAWEB_SYSTEM_PUBLIC_LOOPBACK_ROUTE_FETCHER_H_
24
#include "net/instaweb/http/public/url_async_fetcher.h"
25
#include "net/instaweb/util/public/basictypes.h"
26
#include "net/instaweb/util/public/string.h"
28
struct apr_sockaddr_t;
30
namespace net_instaweb {
37
class LoopbackRouteFetcher : public UrlAsyncFetcher {
39
// Does not take ownership of anything. own_port is the port the incoming
40
// request came in on, and own_ip is the same for the IP. If the
41
// backend_fetcher does actual fetching (and is not merely simulating it for
42
// testing purposes) it should be the Serf fetcher, as others may not direct
43
// requests this class produces properly.
44
// (As this fetcher may produce requests that need to connect to some IP
45
// but have a Host: and URL from somewhere else).
46
LoopbackRouteFetcher(const RewriteOptions* options,
47
const GoogleString& own_ip,
49
UrlAsyncFetcher* backend_fetcher);
50
virtual ~LoopbackRouteFetcher();
52
virtual bool SupportsHttps() const {
53
return backend_fetcher_->SupportsHttps();
56
virtual void Fetch(const GoogleString& url,
57
MessageHandler* message_handler,
60
// Returns true if the given address is an IPv4 or IPv6 loopback.
61
static bool IsLoopbackAddr(const apr_sockaddr_t* addr);
64
const RewriteOptions* const options_;
67
UrlAsyncFetcher* const backend_fetcher_;
69
DISALLOW_COPY_AND_ASSIGN(LoopbackRouteFetcher);
72
} // namespace net_instaweb
74
#endif // NET_INSTAWEB_SYSTEM_PUBLIC_LOOPBACK_ROUTE_FETCHER_H_