summaryrefslogtreecommitdiff
path: root/ngx_stream_lua-0.0.16/util/fix-cosocket-tests.pl
blob: 4c53fd84e1f179fa837211f2ee0b2b3d0a9369a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env perl

use strict;
use warnings;

my ($port_var, $section, $tokens_stmt, $seen_closing, $uri);
while (<>) {
    if (/^--- (\w+)/) {
        $section = $1;
        undef $port_var;
        undef $tokens_stmt;
        undef $seen_closing;
        undef $seen_closing;
        undef $uri;
        print;
        next;
    }
    if (/^\s*set \$port (\$TEST_NGINX_\w+|\d+);/) {
        $port_var = $1;
        next;
    }
    if (defined $section && $section eq 'stream_server_config') {
        if (/^\s*\#?set\s+\$\w+\s+\S+/) {
            next;
        }
        if (/^\s*server_tokens .*/) {
            $tokens_stmt = $_;
            next;
        }
        if (/^\s*lua_socket_buffer_size/) {
            s/^\s*/    /;
            print;
            next;
        }
        if (/^(.*)\bngx\.var\.port\b(.*)/) {
            if (!defined $port_var) {
                die "No port variable defined";
            }
            print "${1}$port_var$2\n";
            next;
        }
        if (!$uri && m{\bGET (/\S+) }) {
            $uri = $1;
        }
        if (!$seen_closing && /^    \}/) {
            $seen_closing = 1;
            print;
            print "\n--- config\n";
            if (defined $tokens_stmt) {
                print $tokens_stmt;
            }
            if (!defined $uri) {
                next;
                #die "No uri found";
            }
            print "    location = $uri {";
            next;
        }
    }

    print;
}