-# $OpenBSD: Relayd.pm,v 1.6 2013/01/21 20:16:57 bluhm Exp $
+# $OpenBSD: Relayd.pm,v 1.7 2014/05/02 14:10:03 andre Exp $
# Copyright (c) 2010-2012 Alexander Bluhm <bluhm@openbsd.org>
#
open(my $fh, '>', $self->{conffile})
or die ref($self), " conf file $self->{conffile} create failed: $!";
print $fh "log all\n";
+ print $fh "table <table-$test> { $self->{connectaddr} }\n"
+ if defined($self->{table});
my @protocol = @{$self->{protocol}};
my $proto = shift @protocol;
print $fh "\n}\n";
my @relay = @{$self->{relay}};
+ my $connectport = $self->{connectport};
+ my $connectaddr = $self->{connectaddr};
+ my $listenaddr = $self->{listenaddr};
+ my $listenport = $self->{listenport};
print $fh "relay relay-$test {";
print $fh "\n\tprotocol proto-$test"
unless grep { /^protocol / } @relay;
my $withssl = $self->{forwardssl} ? " with ssl" : "";
print $fh "\n\tforward$withssl to $self->{connectaddr} ".
"port $self->{connectport}" unless grep { /^forward / } @relay;
+ my @raux = @relay;
+ @relay = ();
+ foreach my $s (@raux) {
+ $s =~ s/(\$\w+)/$1/eeg;
+ push @relay, $s;
+ }
print $fh map { "\n\t$_" } @relay;
print $fh "\n}\n";
-# $OpenBSD: funcs.pl,v 1.9 2014/04/24 09:05:10 bluhm Exp $
+# $OpenBSD: funcs.pl,v 1.10 2014/05/02 14:10:03 andre Exp $
# Copyright (c) 2010-2013 Alexander Bluhm <bluhm@openbsd.org>
#
use strict;
use warnings;
-no warnings 'experimental::smartmatch';
+#no warnings 'experimental::smartmatch';
use feature 'switch';
use Errno;
use Digest::MD5;
my $vers = $self->{lengths} ? "1.1" : "1.0";
my $method = $self->{method} || "GET";
my %header = %{$self->{header} || {}};
+ my $cookie = $self->{cookie} || "";
foreach my $len (@lengths) {
# encode the requested length or chunks into the url
my $path = ref($len) eq 'ARRAY' ? join("/", @$len) : $len;
+ # overwrite path with custom path
+ if (defined($self->{path})) {
+ $path = $self->{path};
+ }
my @request = ("$method /$path HTTP/$vers");
push @request, "Host: foo.bar" unless defined $header{Host};
push @request, "Content-Length: $len"
if $vers eq "1.1" && $method eq "PUT" &&
!defined $header{'Content-Length'};
push @request, "$_: $header{$_}" foreach sort keys %header;
+ push @request, "Cookie: $cookie"
+ if $cookie ne "";
push @request, "";
print STDERR map { ">>> $_\n" } @request;
print map { "$_\r\n" } @request;
chomp;
print STDERR "<<< $_\n";
m{^HTTP/$vers 200 OK$}
- or die ref($self), " http response not ok";
+ or die ref($self), " http response not ok"
+ unless $self->{httpnok};
while (<STDIN>) {
chomp;
print STDERR "<<< $_\n";
sub http_server {
my $self = shift;
+ my %header = %{$self->{header} || {}};
+ my $cookie = $self->{cookie} || "";
my($method, $url, $vers);
do {
$1 == $len or die ref($self),
" bad content length $1";
}
+ if ($cookie eq "" &&
+ /^Cookie: (.*)/) {
+ $cookie = $1;
+ }
}
}
# XXX reading to EOF does not work with relayd
if $method eq "PUT";
my @response = ("HTTP/$vers 200 OK");
+ $len = defined($len) ? $len : scalar(split /|/,$url);
if (ref($len) eq 'ARRAY') {
push @response, "Transfer-Encoding: chunked"
if $vers eq "1.1";
push @response, "Content-Length: $len"
if $vers eq "1.1" && $method eq "GET";
}
+ push @response, "$_: $header{$_} " foreach sort keys %header;
+ push @response, "Set-Cookie: $cookie"
+ if $cookie ne "";
push @response, "";
+
print STDERR map { ">>> $_\n" } @response;
print map { "$_\r\n" } @response;