summaryrefslogtreecommitdiff
path: root/test/new_http_service/http_request.lua
blob: 8cc212e6fdc2e5d5fcae7620a70ce4142681c6db (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

function printf(s,...)
    io.write(s:format(...))
    io.flush()
end

function format_write_file(file, s, ...)
    file:write(s:format(...))
    file:flush()
end

function init()
    ---init something
end

function print_header(header)
    for k, v in pairs(header) do
        if k == "HTTP_OTHER_REGIONS" then
            format_write_file(file, "%s:    ", k)
            for k, v in pairs(header["HTTP_OTHER_REGIONS"]) do
                format_write_file(file, "{%s}   ", v)
            end
            format_write_file(file, "\n")
        else
            format_write_file(file, "%s:    %s\n", k, v)
        end
    end
end

function process()
    printf("\nprint stream: \n")
    stream_info = get_stream_info()
    for k, v in pairs(stream_info) do
        printf("%s: %s\n", k, v)
    end

    printf("\nprint header:\n")
    local regions = {"ALL"}
    header = get_http_request_header(regions)
    for k, v in pairs(header) do
        printf("%s: %s\n", k, v)
    end 

    printf("\nprint body: \n")
    while true do 
        body = get_http_request_body()
        for k, v in pairs(body) do 
            printf("%s: %s\n", k, v)
        end
        if body['data_end'] == true then
            break
        end
    end

    --[[
    file = io.open("./log/lua/http_request.log", "a+")
    format_write_file(file, "lua: call process\n")

    format_write_file(file, "\nprint stream info: \n")
    stream_info = get_stream_info()
    for k, v in pairs(stream_info) do
        format_write_file(file, "%s:  %s\n", k, v)
    end

    format_write_file(file, "\nprint request headers: \n")
    local req_regions = {"HTTP_HOST", "HTTP_REQ_LINE", "HTTP_OTHER_REGIONS"}
    req_header = get_http_request_header(req_regions)
    print_header(req_header)
    

    format_write_file(file, "\nprint request body: \n")
    while true do 
        body = get_http_request_body()
        for k, v in pairs(body) do
            format_write_file(file, "%s:  %s\n", k, v)
        end
        if body['data_end'] == true then
            format_write_file(file, "request body end\n")
            break
        end
        format_write_file(file, "\n");
    end
    format_write_file(file, "\nlua: process end\n")
    io.close(file)
    ]]

end