Artifactspublic-v0

curl

master
ply4 git calls151 ms293 KiB2 cachedprotocol v2
998 lines29 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include <assert.h>
26#include <apr_optional.h>
27#include <apr_optional_hooks.h>
28#include <apr_strings.h>
29#include <apr_cstr.h>
30#include <apr_time.h>
31#include <apr_want.h>
33#include <httpd.h>
34#include <http_protocol.h>
35#include <http_request.h>
36#include <http_log.h>
38#define SECS_PER_HOUR (60 * 60)
39#define SECS_PER_DAY (24 * SECS_PER_HOUR)
41static apr_status_t duration_parse(apr_interval_time_t *ptimeout,
42 const char *value, const char *def_unit)
44 char *endp;
45 apr_int64_t n;
47 n = apr_strtoi64(value, &endp, 10);
48 if(errno) {
49 return errno;
50 }
51 if(!endp || !*endp) {
52 if(!def_unit)
53 def_unit = "s";
54 }
55 else if(endp == value) {
56 return APR_EINVAL;
57 }
58 else {
59 def_unit = endp;
60 }
62 switch(*def_unit) {
63 case 'D':
64 case 'd':
65 *ptimeout = apr_time_from_sec(n * SECS_PER_DAY);
66 break;
67 case 's':
68 case 'S':
69 *ptimeout = (apr_interval_time_t)apr_time_from_sec(n);
70 break;
71 case 'h':
72 case 'H':
73 /* Time is in hours */
74 *ptimeout = (apr_interval_time_t)apr_time_from_sec(n * SECS_PER_HOUR);
75 break;
76 case 'm':
77 case 'M':
78 switch(*(++def_unit)) {
79 /* Time is in milliseconds */
80 case 's':
81 case 'S':
82 *ptimeout = (apr_interval_time_t)n * 1000;
83 break;
84 /* Time is in minutes */
85 case 'i':
86 case 'I':
87 *ptimeout = (apr_interval_time_t)apr_time_from_sec(n * 60);
88 break;
89 default:
90 return APR_EGENERAL;
91 }
92 break;
93 case 'u':
94 case 'U':
95 switch(*(++def_unit)) {
96 /* Time is in microseconds */
97 case 's':
98 case 'S':
99 *ptimeout = (apr_interval_time_t)n;
100 break;
101 default:
102 return APR_EGENERAL;
103 }
104 break;
105 default:
106 return APR_EGENERAL;
107 }
108 return APR_SUCCESS;
111static int status_from_str(const char *s, apr_status_t *pstatus)
113 if(!strcmp("timeout", s)) {
114 *pstatus = APR_TIMEUP;
115 return 1;
116 }
117 else if(!strcmp("reset", s)) {
118 *pstatus = APR_ECONNRESET;
119 return 1;
120 }
121 return 0;
124static int curltest_echo_handler(request_rec *r)
126 conn_rec *c = r->connection;
127 apr_bucket_brigade *bb;
128 apr_bucket *b;
129 apr_status_t rv;
130 char buffer[8192];
131 const char *ct;
132 apr_off_t die_after_len = -1, total_read_len = 0;
133 apr_time_t read_delay = 0;
134 int just_die = 0, die_after_100 = 0;
135 long l;
137 if(strcmp(r->handler, "curltest-echo")) {
138 return DECLINED;
139 }
140 if(r->method_number != M_GET && r->method_number != M_POST) {
141 return DECLINED;
142 }
144 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "echo_handler: processing");
145 if(r->args) {
146 apr_array_header_t *args = NULL;
147 int i;
148 args = apr_cstr_split(r->args, "&", 1, r->pool);
149 for(i = 0; i < args->nelts; ++i) {
150 char *s, *val, *arg = APR_ARRAY_IDX(args, i, char *);
151 s = strchr(arg, '=');
152 if(s) {
153 *s = '\0';
154 val = s + 1;
155 if(!strcmp("die_after", arg)) {
156 die_after_len = (apr_off_t)apr_atoi64(val);
157 continue;
158 }
159 else if(!strcmp("just_die", arg)) {
160 just_die = 1;
161 continue;
162 }
163 else if(!strcmp("die_after_100", arg)) {
164 die_after_100 = 1;
165 continue;
166 }
167 else if(!strcmp("read_delay", arg)) {
168 rv = duration_parse(&read_delay, val, "s");
169 if(APR_SUCCESS == rv) {
170 continue;
171 }
172 }
173 }
174 }
175 }
177 if(just_die) {
178 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
179 "echo_handler: dying right away");
180 /* Generate no HTTP response at all. */
181 ap_remove_output_filter_byhandle(r->output_filters, "HTTP_HEADER");
182 r->connection->keepalive = AP_CONN_CLOSE;
183 return AP_FILTER_ERROR;
184 }
186 r->status = 200;
187 if(die_after_len >= 0) {
188 r->clength = die_after_len + 1;
189 r->chunked = 0;
190 apr_table_set(r->headers_out, "Content-Length",
191 apr_ltoa(r->pool, (long)r->clength));
192 }
193 else {
194 r->clength = -1;
195 r->chunked = 1;
196 apr_table_unset(r->headers_out, "Content-Length");
197 }
198 /* Discourage content-encodings */
199 apr_table_unset(r->headers_out, "Content-Encoding");
200 apr_table_setn(r->subprocess_env, "no-brotli", "1");
201 apr_table_setn(r->subprocess_env, "no-gzip", "1");
203 ct = apr_table_get(r->headers_in, "content-type");
204 ap_set_content_type(r, ct ? ct : "application/octet-stream");
206 if(apr_table_get(r->headers_in, "TE"))
207 apr_table_setn(r->headers_out, "Request-TE",
208 apr_table_get(r->headers_in, "TE"));
210 if(read_delay) {
211 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: read_delay");
212 apr_sleep(read_delay);
213 }
215 bb = apr_brigade_create(r->pool, c->bucket_alloc);
216 /* copy any request body into the response */
217 rv = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK);
218 if(rv)
219 goto cleanup;
220 if(die_after_100) {
221 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
222 "echo_handler: dying after 100-continue");
223 /* Generate no HTTP response at all. */
224 ap_remove_output_filter_byhandle(r->output_filters, "HTTP_HEADER");
225 r->connection->keepalive = AP_CONN_CLOSE;
226 return AP_FILTER_ERROR;
227 }
228 if(ap_should_client_block(r)) {
229 while(0 < (l = ap_get_client_block(r, &buffer[0], sizeof(buffer)))) {
230 total_read_len += l;
231 if(die_after_len >= 0 && total_read_len >= die_after_len) {
232 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
233 "echo_handler: dying after %ld bytes as requested",
234 (long)total_read_len);
235 ap_pass_brigade(r->output_filters, bb);
236 ap_remove_output_filter_byhandle(r->output_filters, "HTTP_HEADER");
237 r->connection->keepalive = AP_CONN_CLOSE;
238 return DONE;
239 }
240 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
241 "echo_handler: copying %ld bytes from request body", l);
242 rv = apr_brigade_write(bb, NULL, NULL, buffer, l);
243 if(APR_SUCCESS != rv)
244 goto cleanup;
245 rv = ap_pass_brigade(r->output_filters, bb);
246 if(APR_SUCCESS != rv)
247 goto cleanup;
248 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
249 "echo_handler: passed %ld bytes from request body", l);
250 }
251 }
252 /* we are done */
253 b = apr_bucket_eos_create(c->bucket_alloc);
254 APR_BRIGADE_INSERT_TAIL(bb, b);
255 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "echo_handler: request read");
257 if(r->trailers_in && !apr_is_empty_table(r->trailers_in)) {
258 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
259 "echo_handler: seeing incoming trailers");
260 apr_table_setn(r->trailers_out, "h2test-trailers-in",
261 apr_itoa(r->pool, 1));
262 }
264 rv = ap_pass_brigade(r->output_filters, bb);
266cleanup:
267 if(rv == APR_SUCCESS ||
268 r->status != HTTP_OK ||
269 c->aborted) {
270 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "echo_handler: done");
271 return OK;
272 }
273 else {
274 /* no way to know what type of error occurred */
275 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "echo_handler failed");
276 return AP_FILTER_ERROR;
277 }
278 return DECLINED;
281static int curltest_tweak_handler(request_rec *r)
283 conn_rec *c = r->connection;
284 apr_bucket_brigade *bb;
285 apr_bucket *b;
286 apr_status_t rv;
287 char buffer[16 * 1024];
288 int i, chunks = 3, error_bucket = 1;
289 size_t chunk_size = sizeof(buffer);
290 const char *request_id = "none";
291 apr_time_t delay = 0, chunk_delay = 0, close_delay = 0;
292 apr_array_header_t *args = NULL;
293 int http_status = 200;
294 apr_status_t error = APR_SUCCESS, body_error = APR_SUCCESS;
295 int close_conn = 0, with_cl = 0;
296 int x_hd_len = 0, x_hd1_len = 0;
298 if(strcmp(r->handler, "curltest-tweak")) {
299 return DECLINED;
300 }
301 if(r->method_number == M_DELETE) {
302 http_status = 204;
303 chunks = 0;
304 }
305 else if(r->method_number != M_GET && r->method_number != M_POST) {
306 return DECLINED;
307 }
309 if(r->args) {
310 args = apr_cstr_split(r->args, "&", 1, r->pool);
311 for(i = 0; i < args->nelts; ++i) {
312 char *s, *val, *arg = APR_ARRAY_IDX(args, i, char *);
313 s = strchr(arg, '=');
314 if(s) {
315 *s = '\0';
316 val = s + 1;
317 if(!strcmp("status", arg)) {
318 http_status = (int)apr_atoi64(val);
319 if(http_status > 0) {
320 continue;
321 }
322 }
323 else if(!strcmp("chunks", arg)) {
324 chunks = (int)apr_atoi64(val);
325 if(chunks >= 0) {
326 continue;
327 }
328 }
329 else if(!strcmp("chunk_size", arg)) {
330 chunk_size = (int)apr_atoi64(val);
331 if(chunk_size > sizeof(buffer)) {
332 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
333 "chunk_size %zu too large", chunk_size);
334 ap_die(HTTP_BAD_REQUEST, r);
335 return OK;
336 }
337 continue;
338 }
339 else if(!strcmp("id", arg)) {
340 /* an id for repeated requests with curl's URL globbing */
341 request_id = val;
342 continue;
343 }
344 else if(!strcmp("error", arg)) {
345 if(status_from_str(val, &error)) {
346 continue;
347 }
348 }
349 else if(!strcmp("error_bucket", arg)) {
350 error_bucket = (int)apr_atoi64(val);
351 if(error_bucket >= 0) {
352 continue;
353 }
354 }
355 else if(!strcmp("body_error", arg)) {
356 if(status_from_str(val, &body_error)) {
357 continue;
358 }
359 }
360 else if(!strcmp("delay", arg)) {
361 rv = duration_parse(&delay, val, "s");
362 if(APR_SUCCESS == rv) {
363 continue;
364 }
365 }
366 else if(!strcmp("chunk_delay", arg)) {
367 rv = duration_parse(&chunk_delay, val, "s");
368 if(APR_SUCCESS == rv) {
369 continue;
370 }
371 }
372 else if(!strcmp("close_delay", arg)) {
373 rv = duration_parse(&close_delay, val, "s");
374 if(APR_SUCCESS == rv) {
375 continue;
376 }
377 }
378 else if(!strcmp("x-hd", arg)) {
379 x_hd_len = (int)apr_atoi64(val);
380 continue;
381 }
382 else if(!strcmp("x-hd1", arg)) {
383 x_hd1_len = (int)apr_atoi64(val);
384 continue;
385 }
386 }
387 else if(!strcmp("close", arg)) {
388 /* we are asked to close the connection */
389 close_conn = 1;
390 continue;
391 }
392 else if(!strcmp("with_cl", arg)) {
393 with_cl = 1;
394 continue;
395 }
396 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "query parameter not "
397 "understood: '%s' in %s", arg, r->args);
398 ap_die(HTTP_BAD_REQUEST, r);
399 return OK;
400 }
401 }
403 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "error_handler: processing "
404 "request, %s", r->args? r->args : "(no args)");
405 r->status = http_status;
406 if(with_cl)
407 r->clength = (apr_off_t)chunks * chunk_size;
408 else
409 r->clength = -1;
410 r->chunked = (r->proto_num >= HTTP_VERSION(1, 1)) && !with_cl;
411 apr_table_setn(r->headers_out, "request-id", request_id);
412 if(r->clength >= 0) {
413 apr_table_set(r->headers_out, "Content-Length",
414 apr_ltoa(r->pool, (long)r->clength));
415 }
416 else
417 apr_table_unset(r->headers_out, "Content-Length");
418 /* Discourage content-encodings */
419 apr_table_unset(r->headers_out, "Content-Encoding");
420 if(x_hd_len > 0) {
421 int hd_len = (16 * 1024);
422 int n = (x_hd_len / hd_len);
423 char *hd_val = apr_palloc(r->pool, hd_len);
424 memset(hd_val, 'X', hd_len);
425 hd_val[hd_len - 1] = 0;
426 for(i = 0; i < n; ++i) {
427 apr_table_setn(r->headers_out,
428 apr_psprintf(r->pool, "X-Header-%d", i), hd_val);
429 }
430 if(x_hd_len % hd_len) {
431 hd_val[(x_hd_len % hd_len)] = 0;
432 apr_table_setn(r->headers_out,
433 apr_psprintf(r->pool, "X-Header-%d", i), hd_val);
434 }
435 }
436 if(x_hd1_len > 0) {
437 char *hd_val = apr_palloc(r->pool, x_hd1_len);
438 memset(hd_val, 'Y', x_hd1_len);
439 hd_val[x_hd1_len - 1] = 0;
440 apr_table_setn(r->headers_out, "X-Mega-Header", hd_val);
441 }
443 apr_table_setn(r->subprocess_env, "no-brotli", "1");
444 apr_table_setn(r->subprocess_env, "no-gzip", "1");
445 ap_set_content_type(r, "application/octet-stream");
446 bb = apr_brigade_create(r->pool, c->bucket_alloc);
448 if(delay) {
449 apr_sleep(delay);
450 }
451 if(error != APR_SUCCESS) {
452 return ap_map_http_request_error(error, HTTP_BAD_REQUEST);
453 }
454 /* flush response */
455 b = apr_bucket_flush_create(c->bucket_alloc);
456 APR_BRIGADE_INSERT_TAIL(bb, b);
457 rv = ap_pass_brigade(r->output_filters, bb);
458 if(APR_SUCCESS != rv)
459 goto cleanup;
461 memset(buffer, 'X', sizeof(buffer));
462 for(i = 0; i < chunks; ++i) {
463 if(chunk_delay) {
464 apr_sleep(chunk_delay);
465 }
466 rv = apr_brigade_write(bb, NULL, NULL, buffer, chunk_size);
467 if(APR_SUCCESS != rv)
468 goto cleanup;
469 rv = ap_pass_brigade(r->output_filters, bb);
470 if(APR_SUCCESS != rv)
471 goto cleanup;
472 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
473 "error_handler: passed %lu bytes as response body",
474 (unsigned long)chunk_size);
475 if(body_error != APR_SUCCESS) {
476 rv = body_error;
477 goto cleanup;
478 }
479 }
480 /* we are done */
481 b = apr_bucket_eos_create(c->bucket_alloc);
482 APR_BRIGADE_INSERT_TAIL(bb, b);
483 rv = ap_pass_brigade(r->output_filters, bb);
484 apr_brigade_cleanup(bb);
485 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r,
486 "error_handler: response passed");
488cleanup:
489 if(close_conn) {
490 if(close_delay) {
491 b = apr_bucket_flush_create(c->bucket_alloc);
492 APR_BRIGADE_INSERT_TAIL(bb, b);
493 rv = ap_pass_brigade(r->output_filters, bb);
494 apr_brigade_cleanup(bb);
495 apr_sleep(close_delay);
496 }
497 r->connection->keepalive = AP_CONN_CLOSE;
498 }
499 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r,
500 "error_handler: request cleanup, r->status=%d, aborted=%u, "
501 "close=%d", r->status, c->aborted, close_conn);
502 if(rv == APR_SUCCESS) {
503 return OK;
504 }
505 if(error_bucket) {
506 http_status = ap_map_http_request_error(rv, HTTP_BAD_REQUEST);
507 b = ap_bucket_error_create(http_status, NULL, r->pool, c->bucket_alloc);
508 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r,
509 "error_handler: passing error bucket, status=%d",
510 http_status);
511 APR_BRIGADE_INSERT_TAIL(bb, b);
512 ap_pass_brigade(r->output_filters, bb);
513 }
514 if(rv == APR_ECONNRESET) {
515 r->connection->aborted = 1;
516 return rv;
517 }
518 return AP_FILTER_ERROR;
521static int curltest_put_handler(request_rec *r)
523 conn_rec *c = r->connection;
524 apr_bucket_brigade *bb;
525 apr_bucket *b;
526 apr_status_t rv;
527 char buffer[128 * 1024];
528 const char *ct;
529 apr_off_t rbody_len = 0;
530 apr_off_t rbody_max_len = -1;
531 const char *s_rbody_len;
532 const char *request_id = "none";
533 apr_time_t read_delay = 0, chunk_delay = 0;
534 apr_array_header_t *args = NULL;
535 long l;
536 int i;
538 if(strcmp(r->handler, "curltest-put")) {
539 return DECLINED;
540 }
541 if(r->method_number != M_PUT) {
542 return DECLINED;
543 }
545 if(r->args) {
546 args = apr_cstr_split(r->args, "&", 1, r->pool);
547 for(i = 0; i < args->nelts; ++i) {
548 char *s, *val, *arg = APR_ARRAY_IDX(args, i, char *);
549 s = strchr(arg, '=');
550 if(s) {
551 *s = '\0';
552 val = s + 1;
553 if(!strcmp("id", arg)) {
554 /* an id for repeated requests with curl's URL globbing */
555 request_id = val;
556 continue;
557 }
558 else if(!strcmp("read_delay", arg)) {
559 rv = duration_parse(&read_delay, val, "s");
560 if(APR_SUCCESS == rv) {
561 continue;
562 }
563 }
564 else if(!strcmp("chunk_delay", arg)) {
565 rv = duration_parse(&chunk_delay, val, "s");
566 if(APR_SUCCESS == rv) {
567 continue;
568 }
569 }
570 else if(!strcmp("max_upload", arg)) {
571 rbody_max_len = (apr_off_t)apr_atoi64(val);
572 continue;
573 }
574 }
575 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "query parameter not "
576 "understood: '%s' in %s", arg, r->args);
577 ap_die(HTTP_BAD_REQUEST, r);
578 return OK;
579 }
580 }
582 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: processing");
583 r->status = 200;
584 r->clength = -1;
585 r->chunked = 1;
586 apr_table_unset(r->headers_out, "Content-Length");
587 /* Discourage content-encodings */
588 apr_table_unset(r->headers_out, "Content-Encoding");
589 apr_table_setn(r->headers_out, "request-id", request_id);
590 apr_table_setn(r->subprocess_env, "no-brotli", "1");
591 apr_table_setn(r->subprocess_env, "no-gzip", "1");
593 ct = apr_table_get(r->headers_in, "content-type");
594 ap_set_content_type(r, ct ? ct : "text/plain");
596 if(read_delay) {
597 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: read_delay");
598 apr_sleep(read_delay);
599 }
600 bb = apr_brigade_create(r->pool, c->bucket_alloc);
601 /* copy any request body into the response */
602 rv = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK);
603 if(rv)
604 goto cleanup;
605 if(ap_should_client_block(r)) {
606 while(0 < (l = ap_get_client_block(r, &buffer[0], sizeof(buffer)))) {
607 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
608 "put_handler: read %ld bytes from request body", l);
609 if(chunk_delay) {
610 apr_sleep(chunk_delay);
611 }
612 rbody_len += l;
613 if((rbody_max_len > 0) && (rbody_len > rbody_max_len)) {
614 r->status = 413;
615 break;
616 }
617 }
618 }
619 /* we are done */
620 s_rbody_len = apr_psprintf(r->pool, "%" APR_OFF_T_FMT, rbody_len);
621 apr_table_setn(r->headers_out, "Received-Length", s_rbody_len);
622 rv = apr_brigade_puts(bb, NULL, NULL, s_rbody_len);
623 if(APR_SUCCESS != rv)
624 goto cleanup;
625 b = apr_bucket_eos_create(c->bucket_alloc);
626 APR_BRIGADE_INSERT_TAIL(bb, b);
627 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "put_handler: request read");
629 rv = ap_pass_brigade(r->output_filters, bb);
631 if(r->status == 413) {
632 apr_sleep(apr_time_from_sec(1));
633 }
635cleanup:
636 if(rv == APR_SUCCESS ||
637 r->status != HTTP_OK ||
638 c->aborted) {
639 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "put_handler: done");
640 return OK;
641 }
642 else {
643 /* no way to know what type of error occurred */
644 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "put_handler failed");
645 return AP_FILTER_ERROR;
646 }
647 return DECLINED;
650static int curltest_1_1_required(request_rec *r)
652 conn_rec *c = r->connection;
653 apr_bucket_brigade *bb;
654 apr_bucket *b;
655 apr_status_t rv;
656 const char *ct;
658 if(strcmp(r->handler, "curltest-1_1-required")) {
659 return DECLINED;
660 }
662 if(HTTP_VERSION_MAJOR(r->proto_num) > 1) {
663 apr_table_setn(r->notes, "ssl-renegotiate-forbidden", "1");
664 ap_die(HTTP_FORBIDDEN, r);
665 return OK;
666 }
668 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "1_1_handler: processing");
669 r->status = 200;
670 r->clength = -1;
671 r->chunked = 1;
672 apr_table_unset(r->headers_out, "Content-Length");
673 /* Discourage content-encodings */
674 apr_table_unset(r->headers_out, "Content-Encoding");
675 apr_table_setn(r->subprocess_env, "no-brotli", "1");
676 apr_table_setn(r->subprocess_env, "no-gzip", "1");
678 ct = apr_table_get(r->headers_in, "content-type");
679 ap_set_content_type(r, ct ? ct : "text/plain");
681 bb = apr_brigade_create(r->pool, c->bucket_alloc);
682 /* flush response */
683 b = apr_bucket_flush_create(c->bucket_alloc);
684 APR_BRIGADE_INSERT_TAIL(bb, b);
685 rv = ap_pass_brigade(r->output_filters, bb);
686 if(APR_SUCCESS != rv)
687 goto cleanup;
689 /* we are done */
690 rv = apr_brigade_printf(bb, NULL, NULL, "well done!");
691 if(APR_SUCCESS != rv)
692 goto cleanup;
693 b = apr_bucket_eos_create(c->bucket_alloc);
694 APR_BRIGADE_INSERT_TAIL(bb, b);
695 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "1_1_handler: request read");
697 rv = ap_pass_brigade(r->output_filters, bb);
699cleanup:
700 if(rv == APR_SUCCESS ||
701 r->status != HTTP_OK ||
702 c->aborted) {
703 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "1_1_handler: done");
704 return OK;
705 }
706 else {
707 /* no way to know what type of error occurred */
708 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "1_1_handler failed");
709 return AP_FILTER_ERROR;
710 }
711 return DECLINED;
714static int brigade_env_var(request_rec *r, apr_bucket_brigade *bb,
715 const char *name)
717 const char *s;
718 s = apr_table_get(r->subprocess_env, name);
719 if(s)
720 return apr_brigade_printf(bb, NULL, NULL, ",\n \"%s\": \"%s\"", name, s);
721 return 0;
724static int curltest_sslinfo_handler(request_rec *r)
726 conn_rec *c = r->connection;
727 apr_bucket_brigade *bb;
728 apr_bucket *b;
729 apr_status_t rv;
730 const char *request_id = NULL;
731 int close_conn = 0;
732 int i;
734 if(strcmp(r->handler, "curltest-sslinfo")) {
735 return DECLINED;
736 }
737 if(r->method_number != M_GET) {
738 return DECLINED;
739 }
741 if(r->args) {
742 apr_array_header_t *args = apr_cstr_split(r->args, "&", 1, r->pool);
743 for(i = 0; i < args->nelts; ++i) {
744 char *s, *val, *arg = APR_ARRAY_IDX(args, i, char *);
745 s = strchr(arg, '=');
746 if(s) {
747 *s = '\0';
748 val = s + 1;
749 if(!strcmp("id", arg)) {
750 /* an id for repeated requests with curl's URL globbing */
751 request_id = val;
752 continue;
753 }
754 }
755 else if(!strcmp("close", arg)) {
756 /* we are asked to close the connection */
757 close_conn = 1;
758 continue;
759 }
760 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "query parameter not "
761 "understood: '%s' in %s", arg, r->args);
762 ap_die(HTTP_BAD_REQUEST, r);
763 return OK;
764 }
765 }
767 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "sslinfo: processing");
768 r->status = 200;
769 r->clength = -1;
770 r->chunked = 1;
771 apr_table_unset(r->headers_out, "Content-Length");
772 /* Discourage content-encodings */
773 apr_table_unset(r->headers_out, "Content-Encoding");
774 if(request_id)
775 apr_table_setn(r->headers_out, "request-id", request_id);
776 apr_table_setn(r->subprocess_env, "no-brotli", "1");
777 apr_table_setn(r->subprocess_env, "no-gzip", "1");
779 ap_set_content_type(r, "application/json");
781 bb = apr_brigade_create(r->pool, c->bucket_alloc);
783 apr_brigade_puts(bb, NULL, NULL, "{\n \"Name\": \"SSL-Information\"");
784 brigade_env_var(r, bb, "HTTPS");
785 brigade_env_var(r, bb, "SSL_PROTOCOL");
786 brigade_env_var(r, bb, "SSL_CIPHER");
787 brigade_env_var(r, bb, "SSL_SESSION_ID");
788 brigade_env_var(r, bb, "SSL_SESSION_RESUMED");
789 brigade_env_var(r, bb, "SSL_SRP_USER");
790 brigade_env_var(r, bb, "SSL_SRP_USERINFO");
791 brigade_env_var(r, bb, "SSL_TLS_SNI");
792 apr_brigade_puts(bb, NULL, NULL, "}\n");
794 /* flush response */
795 b = apr_bucket_flush_create(c->bucket_alloc);
796 APR_BRIGADE_INSERT_TAIL(bb, b);
797 rv = ap_pass_brigade(r->output_filters, bb);
798 if(APR_SUCCESS != rv)
799 goto cleanup;
801 /* we are done */
802 b = apr_bucket_eos_create(c->bucket_alloc);
803 APR_BRIGADE_INSERT_TAIL(bb, b);
804 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "1_1_handler: request read");
806 rv = ap_pass_brigade(r->output_filters, bb);
808cleanup:
809 if(close_conn)
810 r->connection->keepalive = AP_CONN_CLOSE;
811 if(rv == APR_SUCCESS ||
812 r->status != HTTP_OK ||
813 c->aborted) {
814 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "1_1_handler: done");
815 return OK;
816 }
817 else {
818 /* no way to know what type of error occurred */
819 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "1_1_handler failed");
820 return AP_FILTER_ERROR;
821 }
822 return DECLINED;
825struct curltest_limit_rec {
826 int rcount;
827 int rlimit;
828 apr_time_t end;
829 apr_time_t duration_sec;
830 struct apr_thread_mutex_t *lock;
831};
833static struct curltest_limit_rec limitrec = {
834 0, 5, 0, 2, NULL
835};
837static int curltest_limit_handler(request_rec *r)
839 conn_rec *c = r->connection;
840 apr_bucket_brigade *bb;
841 apr_bucket *b;
842 apr_status_t rv;
843 const char *request_id = NULL;
844 int i, denied;
845 apr_time_t now;
847 if(strcmp(r->handler, "curltest-limit")) {
848 return DECLINED;
849 }
850 if(r->method_number != M_GET) {
851 return DECLINED;
852 }
854 if(r->args) {
855 apr_array_header_t *args = apr_cstr_split(r->args, "&", 1, r->pool);
856 for(i = 0; i < args->nelts; ++i) {
857 char *s, *val, *arg = APR_ARRAY_IDX(args, i, char *);
858 s = strchr(arg, '=');
859 if(s) {
860 *s = '\0';
861 val = s + 1;
862 if(!strcmp("id", arg)) {
863 /* an id for repeated requests with curl's URL globbing */
864 request_id = val;
865 continue;
866 }
867 }
868 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "query parameter not "
869 "understood: '%s' in %s", arg, r->args);
870 ap_die(HTTP_BAD_REQUEST, r);
871 return OK;
872 }
873 }
875 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "limit: processing");
877 now = apr_time_now();
878 apr_thread_mutex_lock(limitrec.lock);
879 if(limitrec.end && (now > limitrec.end)) {
880 /* reset limit */
881 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "limit: reset");
882 limitrec.rcount = 0;
883 limitrec.end = 0;
884 }
885 limitrec.rcount += 1;
886 denied = (limitrec.rcount > limitrec.rlimit);
887 if(denied) {
888 /* extend limit duration */
889 limitrec.end = now + apr_time_from_sec(limitrec.duration_sec);
890 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "limit: denied, %d request %s",
891 limitrec.rcount, request_id);
892 }
893 else {
894 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "limit: ok, %d request %s",
895 limitrec.rcount, request_id);
896 }
897 apr_thread_mutex_unlock(limitrec.lock);
899 r->status = denied ? 429 : 200;
900 r->clength = -1;
901 r->chunked = 1;
902 apr_table_unset(r->headers_out, "Content-Length");
903 /* Discourage content-encodings */
904 apr_table_unset(r->headers_out, "Content-Encoding");
905 if(request_id)
906 apr_table_setn(r->headers_out, "request-id", request_id);
907 apr_table_setn(r->subprocess_env, "no-brotli", "1");
908 apr_table_setn(r->subprocess_env, "no-gzip", "1");
910 if(denied) {
911 char *v = apr_psprintf(r->pool, "%ld", limitrec.duration_sec);
912 apr_table_set(r->headers_out, "Retry-After", v);
913 }
915 ap_set_content_type(r, "text/plain");
917 bb = apr_brigade_create(r->pool, c->bucket_alloc);
919 apr_brigade_puts(bb, NULL, NULL, "The resource served with limits.\n");
921 /* flush response */
922 b = apr_bucket_flush_create(c->bucket_alloc);
923 APR_BRIGADE_INSERT_TAIL(bb, b);
924 rv = ap_pass_brigade(r->output_filters, bb);
925 if(APR_SUCCESS != rv)
926 goto cleanup;
928 /* we are done */
929 b = apr_bucket_eos_create(c->bucket_alloc);
930 APR_BRIGADE_INSERT_TAIL(bb, b);
931 rv = ap_pass_brigade(r->output_filters, bb);
933cleanup:
934 if(rv == APR_SUCCESS ||
935 r->status != HTTP_OK ||
936 c->aborted) {
937 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "limit: done");
938 return OK;
939 }
940 else {
941 /* no way to know what type of error occurred */
942 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, rv, r, "limit failed");
943 return AP_FILTER_ERROR;
944 }
945 return DECLINED;
948static int curltest_post_config(apr_pool_t *p, apr_pool_t *plog,
949 apr_pool_t *ptemp, server_rec *s)
951 void *data = NULL;
952 static const char *key = "mod_curltest_init_counter";
954 (void)p;
955 (void)plog;
956 (void)ptemp;
958 apr_pool_userdata_get(&data, key, s->process->pool);
959 if(!data) {
960 /* dry run */
961 apr_pool_userdata_set((const void *)1, key,
962 apr_pool_cleanup_null, s->process->pool);
963 return APR_SUCCESS;
964 }
966 return apr_thread_mutex_create(&limitrec.lock, APR_THREAD_MUTEX_DEFAULT, p);
969static void curltest_hooks(apr_pool_t *pool)
971 ap_log_perror(APLOG_MARK, APLOG_TRACE1, 0, pool, "installing hooks");
973 /* Run once after configuration is set, but before mpm children initialize.
974 */
975 ap_hook_post_config(curltest_post_config, NULL, NULL, APR_HOOK_MIDDLE);
977 /* curl test handlers */
978 ap_hook_handler(curltest_echo_handler, NULL, NULL, APR_HOOK_MIDDLE);
979 ap_hook_handler(curltest_put_handler, NULL, NULL, APR_HOOK_MIDDLE);
980 ap_hook_handler(curltest_tweak_handler, NULL, NULL, APR_HOOK_MIDDLE);
981 ap_hook_handler(curltest_1_1_required, NULL, NULL, APR_HOOK_MIDDLE);
982 ap_hook_handler(curltest_sslinfo_handler, NULL, NULL, APR_HOOK_MIDDLE);
983 ap_hook_handler(curltest_limit_handler, NULL, NULL, APR_HOOK_MIDDLE);
986AP_DECLARE_MODULE(curltest) =
988 STANDARD20_MODULE_STUFF,
989 NULL, /* func to create per-directory config */
990 NULL, /* func to merge per-directory config */
991 NULL, /* func to create per-server config */
992 NULL, /* func to merge per-server config */
993 NULL, /* command handlers */
994 curltest_hooks,
995#ifdef AP_MODULE_FLAG_NONE
996 AP_MODULE_FLAG_ALWAYS_MERGE
997#endif
998};
Diagnostics4 git calls · 151 ms
CallStatusSizeTime0151 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2006.0 KiB146 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=146
git.response.bytes=6094
git.response.cache=MISS
git.response.duration_ms=146
git.fetch.wants=d783af1ab641d70119b521749932fb3b3bff0209
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=6094
git.pkt.payload.max=6073
git.sideband.band1.bytes=6072
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e34af70d328a31
Request
2377a6bb…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format