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
// Author: sligocki@google.com (Shawn Ligocki)
19
#ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_DUMP_URL_ASYNC_WRITER_H_
20
#define NET_INSTAWEB_HTTP_PUBLIC_HTTP_DUMP_URL_ASYNC_WRITER_H_
22
#include "net/instaweb/http/public/url_async_fetcher.h"
23
#include "net/instaweb/http/public/http_dump_url_fetcher.h"
24
#include "net/instaweb/util/public/basictypes.h"
25
#include "net/instaweb/util/public/string.h"
26
#include "net/instaweb/util/public/string_util.h"
28
namespace net_instaweb {
35
// HttpDumpWriter checks to see whether the HTTP dump is available on the
36
// filesystem. If not, it fetches it from another fetcher (e.g. one that
37
// uses the network) and writes it to the filesystem so that HttpDumpFetcher
39
class HttpDumpUrlAsyncWriter : public UrlAsyncFetcher {
41
HttpDumpUrlAsyncWriter(const StringPiece& root_dir,
42
UrlAsyncFetcher* base_fetcher,
43
FileSystem* file_system,
45
: dump_fetcher_(root_dir, file_system, timer),
46
base_fetcher_(base_fetcher),
47
file_system_(file_system),
49
root_dir.CopyToString(&root_dir_);
51
virtual ~HttpDumpUrlAsyncWriter();
53
virtual bool SupportsHttps() const { return base_fetcher_->SupportsHttps(); }
55
// This is a synchronous/blocking implementation.
56
virtual void Fetch(const GoogleString& url,
57
MessageHandler* handler,
58
AsyncFetch* base_fetch);
60
// Controls whether we will request and save gzipped content to the
61
// file system. Note that http_dump_url_fetcher will inflate on
62
// read if its caller does not want gzipped output.
63
void set_accept_gzip(bool x) { accept_gzip_ = x; }
65
// Print URLs each time they are fetched.
66
void set_print_urls(bool on) { dump_fetcher_.set_print_urls(on); }
69
// Helper class to manage individual fetchs.
72
HttpDumpUrlFetcher dump_fetcher_;
73
// Used to fetch urls that aren't in the dump yet.
74
UrlAsyncFetcher* base_fetcher_;
75
GoogleString root_dir_; // Root directory of the HTTP dumps.
76
FileSystem* file_system_;
79
DISALLOW_COPY_AND_ASSIGN(HttpDumpUrlAsyncWriter);
82
} // namespace net_instaweb
84
#endif // NET_INSTAWEB_HTTP_PUBLIC_HTTP_DUMP_URL_ASYNC_WRITER_H_