test proxy supports CONNECT
[platform/upstream/curl.git] / tests / httpserver.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 #***************************************************************************
23
24 BEGIN {
25     @INC=(@INC, $ENV{'srcdir'}, '.');
26 }
27
28 use strict;
29 use warnings;
30
31 use serverhelp qw(
32     server_pidfilename
33     server_logfilename
34     );
35
36 my $verbose = 0;     # set to 1 for debugging
37 my $port = 8990;     # just a default
38 my $ipvnum = 4;      # default IP version of http server
39 my $idnum = 1;       # dafault http server instance number
40 my $proto = 'http';  # protocol the http server speaks
41 my $pidfile;         # http server pid file
42 my $logfile;         # http server log file
43 my $connect;         # IP to connect to on CONNECT
44 my $srcdir;
45 my $fork;
46 my $gopher = 0;
47
48 my $flags  = "";
49 my $path   = '.';
50 my $logdir = $path .'/log';
51
52 while(@ARGV) {
53     if($ARGV[0] eq '--pidfile') {
54         if($ARGV[1]) {
55             $pidfile = $ARGV[1];
56             shift @ARGV;
57         }
58     }
59     elsif($ARGV[0] eq '--logfile') {
60         if($ARGV[1]) {
61             $logfile = $ARGV[1];
62             shift @ARGV;
63         }
64     }
65     elsif($ARGV[0] eq '--srcdir') {
66         if($ARGV[1]) {
67             $srcdir = $ARGV[1];
68             shift @ARGV;
69         }
70     }
71     elsif($ARGV[0] eq '--ipv4') {
72         $ipvnum = 4;
73     }
74     elsif($ARGV[0] eq '--ipv6') {
75         $ipvnum = 6;
76     }
77     elsif($ARGV[0] eq '--gopher') {
78         $gopher = 1;
79     }
80     elsif($ARGV[0] eq '--port') {
81         if($ARGV[1] =~ /^(\d+)$/) {
82             $port = $1;
83             shift @ARGV;
84         }
85     }
86     elsif($ARGV[0] eq '--connect') {
87         if($ARGV[1]) {
88             $connect = $ARGV[1];
89             shift @ARGV;
90         }
91     }
92     elsif($ARGV[0] eq '--id') {
93         if($ARGV[1] =~ /^(\d+)$/) {
94             $idnum = $1 if($1 > 0);
95             shift @ARGV;
96         }
97     }
98     elsif($ARGV[0] eq '--verbose') {
99         $verbose = 1;
100     }
101     elsif($ARGV[0] eq '--fork') {
102         $fork = $ARGV[0];
103     }
104     else {
105         print STDERR "\nWarning: httpserver.pl unknown parameter: $ARGV[0]\n";
106     }
107     shift @ARGV;
108 }
109
110 if(!$srcdir) {
111     $srcdir = $ENV{'srcdir'} || '.';
112 }
113 if(!$pidfile) {
114     $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
115 }
116 if(!$logfile) {
117     $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
118 }
119
120 $flags .= "--gopher " if($gopher);
121 $flags .= "--fork " if(defined($fork));
122 $flags .= "--connect $connect " if($connect);
123 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
124 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
125
126 if($verbose) {
127     print STDERR "RUN: server/sws $flags\n";
128 }
129
130 exec("server/sws $flags");