Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions conf/fastproxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ allow-header=Host
allow-header=If-Modified-Since
allow-header=Last-Modified
allow-header=Location
allow-header=Origin
allow-header=Pragma
allow-header=Accept
allow-header=Accept-Charset
Expand All @@ -32,6 +33,10 @@ allow-header=Cookie
allow-header=Set-Cookie
allow-header=X-Yandex-Antivirus
allow-header=X-Requested-With
allow-header=X-GWT-Permutation
allow-header=X-GWT-Module-Base
receive-timeout=999999
connect-timeout=4
log-channel=proxy
log-channel=resolver
name-server=127.0.0.1
60 changes: 57 additions & 3 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
fastproxy (0.4.9) precise; urgency=low

* allow Origin header

-- Denis Puchkin <[email protected]> Mon, 27 Jul 2015 20:06:24 +0300

fastproxy (0.4.8) precise; urgency=low

* tocuh version

-- Denis Puchkin <[email protected]> Tue, 31 Mar 2015 10:45:46 +0300

fastproxy (0.4.7) precise; urgency=low

* new fastproxy config

-- Denis Puchkin <[email protected]> Fri, 10 Oct 2014 12:44:46 +0400

fastproxy (0.4.6) precise; urgency=low

* build fix

-- Denis Puchkin <[email protected]> Wed, 24 Sep 2014 12:31:15 +0400

fastproxy (0.4.5) precise; urgency=low

* new default config

-- Denis Puchkin <[email protected]> Wed, 24 Sep 2014 12:24:46 +0400

fastproxy (0.4.4) precise; urgency=low

* disable recursive dns

-- Denis Puchkin <[email protected]> Wed, 10 Sep 2014 13:00:20 +0400

fastproxy (0.4.3) precise; urgency=low

* test

-- Denis Puchkin <[email protected]> Wed, 18 Jun 2014 18:05:35 +0400

fastproxy (0.4.2) precise; urgency=low

* upstart: added kill timeout to speedup stopping

-- Nikolay Bryskin <[email protected]> Tue, 13 Nov 2012 01:33:20 +0400

fastproxy (0.4.1) precise; urgency=low

* resolv and connect timeouts raised to 4 sec

-- Nikolay Bryskin <[email protected]> Thu, 08 Nov 2012 21:18:22 +0400

fastproxy (0.4) precise; urgency=low

* Zabbix script fix: handle fastproxy restarts
Expand Down Expand Up @@ -87,7 +141,7 @@ fastproxy (0.2.16) natty; urgency=low

fastproxy (0.2.15) lucid; urgency=low

* allowed header X-Yandex-Antivirus
* allowed header X-Yandex-Antivirus

-- Nikolay Bryskin <[email protected]> Mon, 27 Jun 2011 15:52:29 +0400

Expand Down Expand Up @@ -182,7 +236,7 @@ fastproxy (0.2.2) lucid; urgency=low
* zbx_fastproxy.py: return 0 for non-existent statistics values (to avoid
backtraces in zabbix-agent logs)
* zbx_fastproxy.py: return 0 for non-existent statistics sockets
* zbx_fastproxy.py: aggregation support (only `sum' for now using `*')
* zbx_fastproxy.py: aggregation support (only `sum' for now using `*')

-- Nikolay Bryskin <[email protected]> Thu, 24 Feb 2011 03:21:16 +0300

Expand All @@ -202,7 +256,7 @@ fastproxy (0.2ubuntu1) lucid; urgency=low

fastproxy (0.1ubuntu1) lucid; urgency=low

* Fixed Ubuntu packaging scripts
* Fixed Ubuntu packaging scripts

-- Nikolay Bryskin <[email protected]> Sat, 29 Jan 2011 21:12:25 +0300

Expand Down
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Source: fastproxy
Section: misc
Priority: extra
Maintainer: Nikolay Bryskin <[email protected]>
Build-Depends: debhelper (>= 7.0.50~), libboost1.43-all-dev, python (>= 2.6), libunbound-dev
Build-Depends: debhelper (>= 7.0.50~), libudns-dev, libboost1.43-all-dev, python (>= 2.6)
Standards-Version: 3.9.1
Homepage: http://git.yandex.ru/nbryskin/fastproxy.git

Package: fastproxy
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, python (>= 2.6), libunbound2
Depends: ${shlibs:Depends}, ${misc:Depends}, python (>= 2.6)
Description: Fast and reliable HTTP proxy server, no caching
Fastproxy is simple, fast and reliable event-based HTTP proxy server
with built-in stub DNS resolver. Written mostly in C++ and have
Expand Down
1 change: 1 addition & 0 deletions debian/upstart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ stop on stopping network or fastproxy-all-stop
respawn
respawn limit 10 5
limit nofile 65536 65536
kill timeout 1
instance $ARGS
script
CONF_ARGS="`sed -e 's/^/ --/' /etc/fastproxy.conf | tr -d '\n'`"
Expand Down
2 changes: 1 addition & 1 deletion src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void channel::input_timeouted(const error_code& ec)

void channel::splice_from_input()
{
error_code ec(0, boost::system::generic_category());
error_code ec(0, boost::system::generic_category);
std::size_t avail = input.available(ec);
if (ec)
return finish(ec);
Expand Down
2 changes: 1 addition & 1 deletion src/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class channel : public boost::noncopyable
int pipe[2];
long pipe_size;
session& parent_session;
static const std::size_t size_of_operation = sizeof(asio::detail::reactive_null_buffers_op<handler_t*>);
static const std::size_t size_of_operation = sizeof(asio::detail::null_buffers_op<handler_t*>);
handler_t input_handler;
char space_for_input_op[size_of_operation];
handler_t output_handler;
Expand Down
51 changes: 6 additions & 45 deletions src/fastproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,18 @@ void fastproxy::parse_config(int argc, char* argv[])
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("resolve-library", po::value<std::string>()->default_value("unbound"), "DNS library to use for resolve ('udns', 'unbound')")

("ingoing-http", po::value<endpoint_vec>()->required(), "http listening addresses")
("ingoing-stat", po::value<std::string>()->required(), "statistics listening socket")

("outgoing-http", po::value<ip::tcp::endpoint>()->default_value(ip::tcp::endpoint()), "outgoing address for HTTP requests")
("outgoing-ns", po::value<ip::udp::endpoint>()->default_value(ip::udp::endpoint()), "outgoing address for NS lookup")

("name-server", po::value<ip::udp::endpoint>()->required(), "name server address")
("log-level", po::value<int>()->default_value(2), "logging level")
("log-channel", po::value<string_vec>(), "logging channel")

("receive-timeout", po::value<time_duration::sec_type>()->default_value(3600), "timeout for receive operations (in seconds)")
("connect-timeout", po::value<time_duration::sec_type>()->default_value(3), "timeout for connect operation (in seconds)")
("resolve-timeout", po::value<time_duration::sec_type>()->default_value(3), "time out for resolve operation for 'unbound' (in seconds)")

("udns-name-server", po::value<ip::udp::endpoint>(), "name server address for 'udns' library")

("allow-header", po::value<string_vec>()->default_value(string_vec(), "any"), "allowed header for requests")
("rename-header", po::value<string_vec>()->default_value(string_vec(), ""), "header rename rule (<original name>:<new name>), only allowed headers are supported")

("stat-socket-user", po::value<std::string>()->default_value(getpwuid(getuid())->pw_name), "user for statistics socket")
("stat-socket-group", po::value<std::string>()->default_value(getgrgid(getgid())->gr_name), "group for statistics socket")

("stop-after-init", po::value<bool>()->default_value(false), "raise SIGSTOP after initialization (Upstart support)")
("error-page-dir", po::value<std::string>()->default_value("/etc/fastproxy/errors"), "directory where error pages are located");

Expand All @@ -86,25 +75,9 @@ void fastproxy::parse_config(int argc, char* argv[])
exit(1);
}

std::string resolve_library = vm["resolve-library"].as<std::string>();
if (resolve_library == "udns")
{
if (vm.count("udns-name-server") == 0)
{
throw boost::program_options::required_option("udns-name-server");
}
}
else if (resolve_library == "unbound")
{
// No specific options yet
}
else
{
throw boost::program_options::invalid_option_value(resolve_library);
}
po::notify(vm);
}
catch (const boost::program_options::error& exc)
catch (const boost::program_options::required_option& exc)
{
std::cout << desc << std::endl;
throw;
Expand Down Expand Up @@ -204,31 +177,19 @@ void fastproxy::init_statistics()

void fastproxy::init_proxy()
{
bool use_unbound_resolve = (vm["resolve-library"].as<std::string>() == "unbound");

ip::udp::endpoint name_server;

if (!use_unbound_resolve)
{
name_server = vm["udns-name-server"].as<ip::udp::endpoint>();
}

p.reset(new proxy(io, vm["ingoing-http"].as<endpoint_vec>(),
vm["outgoing-http"].as<ip::tcp::endpoint>(),
vm["outgoing-ns"].as<ip::udp::endpoint>(),
name_server,
vm["name-server"].as<ip::udp::endpoint>(),
boost::posix_time::seconds(vm["receive-timeout"].as<time_duration::sec_type>()),
boost::posix_time::seconds(vm["connect-timeout"].as<time_duration::sec_type>()),
boost::posix_time::seconds(vm["resolve-timeout"].as<time_duration::sec_type>()),
vm["allow-header"].as<string_vec>(),
vm["rename-header"].as<string_vec>(),
vm["error-page-dir"].as<std::string>(),
use_unbound_resolve));
vm["error-page-dir"].as<std::string>()));
}

void fastproxy::init_resolver()
void fastproxy::init_resolver()
{
resolver::init();
resolver::init();
}

template<class stream_type, class protocol>
Expand Down
2 changes: 1 addition & 1 deletion src/fastproxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class fastproxy

private:
void parse_config(int argc, char* argv[]);
void init_logging();
void init_logging();
void init_resolver();
void init_signals();
void init_statistics();
Expand Down
40 changes: 9 additions & 31 deletions src/headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#ifndef HEADERS_HPP_
#define HEADERS_HPP_

#include <map>
#include <set>
#include <functional>
#include <cstring>
#include <string.h>

class lstring
{
Expand All @@ -34,16 +33,9 @@ class lstring
{
}

// Checks if header line is empty, i.e. has 0-length or contains just new line characters
bool empty() const
operator bool () const
{
switch (size())
{
case 0: return true;
case 1: return ((begin[0] == '\r') || (begin[0] == '\n'));
case 2: return (begin[1] == '\n');
default: return false;
}
return size() != 0;
}

std::size_t size() const
Expand All @@ -53,27 +45,13 @@ class lstring

friend bool operator < (const lstring& lhs, const lstring& rhs)
{
const char* l = lhs.begin;
const char* r = rhs.begin;

for (; l != lhs.end && r != rhs.end; l++, r++)
for (const char *l = lhs.begin, *r = rhs.begin; l != lhs.end && r != rhs.end; l++, r++)
{
char lc = tolower(*l);
char rc = tolower(*r);

if (lc == rc)
continue;
if (tolower(*l) < tolower(*r))
return true;

return (lc < rc);
}

// It might be the case when 'allowed' header name is a prefix of another header
// name. We don't want to allow headers by prefix but rather by exact match. So
// the next character has to be checked and headers are equal if it is ':'.
// The only case we have to check, in all other cases condition result is 'false'
if (lhs.size() < rhs.size())
{
return rhs.begin[lhs.size()] != ':';
if (tolower(*l) > tolower(*r))
break;
}

return false;
Expand All @@ -83,6 +61,6 @@ class lstring
const char* end;
};

typedef std::map<lstring, lstring> headers_type;
typedef std::set<lstring> headers_type;

#endif /* HEADERS_HPP_ */
Loading