diff options
Diffstat (limited to 'web/attachments/296709-check_http.patch')
-rw-r--r-- | web/attachments/296709-check_http.patch | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/web/attachments/296709-check_http.patch b/web/attachments/296709-check_http.patch new file mode 100644 index 0000000..04d83f1 --- /dev/null +++ b/web/attachments/296709-check_http.patch | |||
@@ -0,0 +1,158 @@ | |||
1 | Index: check_http.c | ||
2 | =================================================================== | ||
3 | --- check_http.c (revision 2059) | ||
4 | +++ check_http.c (working copy) | ||
5 | @@ -187,6 +187,7 @@ | ||
6 | {"nohtml", no_argument, 0, 'n'}, | ||
7 | {"ssl", no_argument, 0, 'S'}, | ||
8 | {"post", required_argument, 0, 'P'}, | ||
9 | + {"method", required_argument, 0, 'j'}, | ||
10 | {"IP-address", required_argument, 0, 'I'}, | ||
11 | {"url", required_argument, 0, 'u'}, | ||
12 | {"port", required_argument, 0, 'p'}, | ||
13 | @@ -228,7 +229,7 @@ | ||
14 | } | ||
15 | |||
16 | while (1) { | ||
17 | - c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); | ||
18 | + c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); | ||
19 | if (c == -1 || c == EOF) | ||
20 | break; | ||
21 | |||
22 | @@ -344,11 +345,19 @@ | ||
23 | strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1); | ||
24 | user_auth[MAX_INPUT_BUFFER - 1] = 0; | ||
25 | break; | ||
26 | - case 'P': /* HTTP POST data in URL encoded format */ | ||
27 | - if (http_method || http_post_data) break; | ||
28 | + case 'P': /* HTTP POST data in URL encoded format; only sets data when method already set*/ | ||
29 | + if (http_post_data) break; | ||
30 | + if (http_method) | ||
31 | + { | ||
32 | + http_post_data = strdup (optarg); | ||
33 | + break; | ||
34 | + } | ||
35 | http_method = strdup("POST"); | ||
36 | http_post_data = strdup (optarg); | ||
37 | break; | ||
38 | + case 'j': /* SET HTTP METHOD */ | ||
39 | + http_method = strdup (optarg); | ||
40 | + break; | ||
41 | case 's': /* string or substring */ | ||
42 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); | ||
43 | string_expect[MAX_INPUT_BUFFER - 1] = 0; | ||
44 | @@ -817,7 +826,7 @@ | ||
45 | asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); | ||
46 | } | ||
47 | |||
48 | - /* either send http POST data */ | ||
49 | + /* either send http POST data (any data, not only POST)*/ | ||
50 | if (http_post_data) { | ||
51 | if (http_content_type) { | ||
52 | asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); | ||
53 | @@ -1312,7 +1321,9 @@ | ||
54 | printf (" %s\n", "-u, --url=PATH"); | ||
55 | printf (" %s\n", _("URL to GET or POST (default: /)")); | ||
56 | printf (" %s\n", "-P, --post=STRING"); | ||
57 | - printf (" %s\n", _("URL encoded http POST data")); | ||
58 | + printf (" %s\n", _("URL encoded http POST data. When used with -j only sets data.")); | ||
59 | + printf (" %s\n", "-j, --method=STRING (ex. OPTIONS, TRACE, PUT, DELETE)"); | ||
60 | + printf (" %s\n", _("Set HTTP method.")); | ||
61 | printf (" %s\n", "-N, --no-body"); | ||
62 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); | ||
63 | printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)")); | ||
64 | @@ -1396,5 +1407,5 @@ | ||
65 | printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n"); | ||
66 | printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n"); | ||
67 | printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n"); | ||
68 | - printf (" [-k string] [-S] [-C <age>] [-T <content-type>]\n"); | ||
69 | + printf (" [-k string] [-S] [-C <age>] [-T <content-type>] [-j string]\n"); | ||
70 | } | ||
71 | Index: tests/check_http.t | ||
72 | =================================================================== | ||
73 | --- tests/check_http.t (revision 2059) | ||
74 | +++ tests/check_http.t (working copy) | ||
75 | @@ -33,9 +33,7 @@ | ||
76 | print "Please contact me at: <URL:", $d->url, ">\n"; | ||
77 | while (my $c = $d->accept ) { | ||
78 | while (my $r = $c->get_request) { | ||
79 | - if ($r->method eq "GET" and $r->url->path eq "/xyzzy") { | ||
80 | - $c->send_file_response("/etc/passwd"); | ||
81 | - } elsif ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | ||
82 | + if ($r->method eq "GET" and $r->url->path =~ m^/statuscode/(\d+)^) { | ||
83 | $c->send_basic_header($1); | ||
84 | $c->send_crlf; | ||
85 | } elsif ($r->method eq "GET" and $r->url->path =~ m^/file/(.*)^) { | ||
86 | @@ -46,8 +44,15 @@ | ||
87 | $c->send_basic_header; | ||
88 | $c->send_crlf; | ||
89 | sleep 1; | ||
90 | - $c->send_response("slow"); | ||
91 | + } elsif ($r->url->path eq "/method") { | ||
92 | + if ($r->method eq "DELETE") { | ||
93 | + $c->send_error(RC_METHOD_NOT_ALLOWED); | ||
94 | + } elsif ($r->method eq "foo") { | ||
95 | + $c->send_error(RC_NOT_IMPLEMENTED); | ||
96 | } else { | ||
97 | + $c->send_status_line(200, $r->method); | ||
98 | + } | ||
99 | + } else { | ||
100 | $c->send_error(RC_FORBIDDEN); | ||
101 | } | ||
102 | $c->close; | ||
103 | @@ -63,7 +68,7 @@ | ||
104 | } | ||
105 | |||
106 | if (-x "./check_http") { | ||
107 | - plan tests => 19; | ||
108 | + plan tests => 33; | ||
109 | } else { | ||
110 | plan skip_all => "No check_http compiled"; | ||
111 | } | ||
112 | @@ -84,7 +89,7 @@ | ||
113 | |||
114 | $result = NPTest->testCmd( "$command -u /slow" ); | ||
115 | is( $result->return_code, 0, "/file/root"); | ||
116 | -like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 177 bytes in ([\d\.]+) seconds/', "Output correct" ); | ||
117 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 OK - 89 bytes in ([\d\.]+) seconds/', "Output correct" ); | ||
118 | $result->output =~ /in ([\d\.]+) seconds/; | ||
119 | cmp_ok( $1, ">", 1, "Time is > 1 second" ); | ||
120 | |||
121 | @@ -119,3 +124,37 @@ | ||
122 | is( $result->return_code, 2, $cmd); | ||
123 | like( $result->output, '/^HTTP CRITICAL - Invalid HTTP response received from host on port (\d+): HTTP/1.1 203 Non-Authoritative Information/', "Output correct: ".$result->output ); | ||
124 | |||
125 | +$cmd = "$command -j HEAD -u /method"; | ||
126 | +$result = NPTest->testCmd( $cmd ); | ||
127 | +is( $result->return_code, 0, $cmd); | ||
128 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 HEAD - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
129 | + | ||
130 | +$cmd = "$command -j POST -u /method"; | ||
131 | +$result = NPTest->testCmd( $cmd ); | ||
132 | +is( $result->return_code, 0, $cmd); | ||
133 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
134 | + | ||
135 | +$cmd = "$command -j GET -u /method"; | ||
136 | +$result = NPTest->testCmd( $cmd ); | ||
137 | +is( $result->return_code, 0, $cmd); | ||
138 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
139 | + | ||
140 | +$cmd = "$command -u /method"; | ||
141 | +$result = NPTest->testCmd( $cmd ); | ||
142 | +is( $result->return_code, 0, $cmd); | ||
143 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 GET - 18 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
144 | + | ||
145 | +$cmd = "$command -P foo -u /method"; | ||
146 | +$result = NPTest->testCmd( $cmd ); | ||
147 | +is( $result->return_code, 0, $cmd); | ||
148 | +like( $result->output, '/^HTTP OK HTTP/1.1 200 POST - 19 bytes in ([\d\.]+) seconds/', "Output correct: ".$result->output ); | ||
149 | + | ||
150 | +$cmd = "$command -j DELETE -u /method"; | ||
151 | +$result = NPTest->testCmd( $cmd ); | ||
152 | +is( $result->return_code, 1, $cmd); | ||
153 | +like( $result->output, '/^HTTP WARNING: HTTP/1.1 405 Method Not Allowed/', "Output correct: ".$result->output ); | ||
154 | + | ||
155 | +$cmd = "$command -j foo -u /method"; | ||
156 | +$result = NPTest->testCmd( $cmd ); | ||
157 | +is( $result->return_code, 2, $cmd); | ||
158 | +like( $result->output, '/^HTTP CRITICAL: HTTP/1.1 501 Not Implemented/', "Output correct: ".$result->output ); | ||