2
* Copyright 2010 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
// Authors: jmarantz@google.com (Joshua Marantz)
18
// vchudnov@google.com (Victor Chudnovsky)
20
#ifndef NET_INSTAWEB_HTTP_PUBLIC_EXTERNAL_URL_FETCHER_H_
21
#define NET_INSTAWEB_HTTP_PUBLIC_EXTERNAL_URL_FETCHER_H_
23
#include "net/instaweb/util/public/basictypes.h"
24
#include "net/instaweb/util/public/string.h"
25
#include "net/instaweb/util/public/string_util.h"
26
#include "net/instaweb/http/public/url_async_fetcher.h"
28
namespace net_instaweb {
34
// Runs an external command ('wget' by default, or 'curl') via popen
35
// for blocking URL fetches.
37
// TODO(vchudnov): Incorporate NetcatUrlFetcher functionality into
39
class ExternalUrlFetcher : public UrlAsyncFetcher {
41
ExternalUrlFetcher() {}
42
virtual ~ExternalUrlFetcher() {}
44
// TODO(sligocki): Allow protocol version number (e.g. HTTP/1.1)
45
// and request type (e.g. GET, POST, etc.) to be specified.
46
virtual void Fetch(const GoogleString& url,
47
MessageHandler* message_handler,
50
// Default user agent to use.
51
static const char kDefaultUserAgent[];
53
// Sets the path to "binary" when fetching using "how".
54
void set_binary(const GoogleString& binary);
58
// Appends to escaped_headers one header line for each Name, Value
59
// pair in request_headers.
60
virtual void AppendHeaders(const RequestHeaders& request_headers,
61
StringVector* escaped_headers);
66
virtual const char* GetFetchLabel() = 0;
68
// Returns the external command to run in order to fetch a URL. The
69
// URL and the vector of header lines must be already escaped in
70
// escaped_url and escaped_headers, respectively. In addition to the
71
// specified headers, the User-Agent is also explicitly set to the
72
// value of user_agent, unless the latter is NULL.
73
virtual GoogleString ConstructFetchCommand(
74
const GoogleString& escaped_url,
75
const char* user_agent,
76
const StringVector& escaped_headers) = 0;
78
DISALLOW_COPY_AND_ASSIGN(ExternalUrlFetcher);
81
} // namespace net_instaweb
83
#endif // NET_INSTAWEB_HTTP_PUBLIC_EXTERNAL_URL_FETCHER_H_