aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/components/flowtable-columns.js
blob: 74d96216723ea9de14d6c0bfb69be50a0d701707 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
var React = require("react");
var RequestUtils = require("../flow/utils.js").RequestUtils;
var ResponseUtils = require("../flow/utils.js").ResponseUtils;
var utils = require("../utils.js");

var TLSColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-tls " + (this.props.className || "") }></th>;
            }
        }),
        sortKeyFun: function(flow){
            return flow.request.scheme;
        }
    },
    render: function () {
        var flow = this.props.flow;
        var ssl = (flow.request.scheme === "https");
        var classes;
        if (ssl) {
            classes = "col-tls col-tls-https";
        } else {
            classes = "col-tls col-tls-http";
        }
        return <td className={classes}></td>;
    }
});


var IconColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-icon " + (this.props.className || "") }></th>;
            }
        })
    },
    render: function () {
        var flow = this.props.flow;

        var icon;
        if (flow.response) {
            var contentType = ResponseUtils.getContentType(flow.response);

            //TODO: We should assign a type to the flow somewhere else.
            if (flow.response.status_code === 304) {
                icon = "resource-icon-not-modified";
            } else if (300 <= flow.response.status_code && flow.response.status_code < 400) {
                icon = "resource-icon-redirect";
            } else if (contentType && contentType.indexOf("image") >= 0) {
                icon = "resource-icon-image";
            } else if (contentType && contentType.indexOf("javascript") >= 0) {
                icon = "resource-icon-js";
            } else if (contentType && contentType.indexOf("css") >= 0) {
                icon = "resource-icon-css";
            } else if (contentType && contentType.indexOf("html") >= 0) {
                icon = "resource-icon-document";
            }
        }
        if (!icon) {
            icon = "resource-icon-plain";
        }


        icon += " resource-icon";
        return <td className="col-icon">
            <div className={icon}></div>
        </td>;
    }
});

var PathColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-path " + (this.props.className || "") }>Path</th>;
            }
        }),
        sortKeyFun: function(flow){
            return RequestUtils.pretty_url(flow.request);
        }
    },
    render: function () {
        var flow = this.props.flow;
        return <td className="col-path">
            {flow.request.is_replay ? <i className="fa fa-fw fa-repeat pull-right"></i> : null}
            {flow.intercepted ? <i className="fa fa-fw fa-pause pull-right"></i> : null}
            { RequestUtils.pretty_url(flow.request) }
        </td>;
    }
});


var MethodColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-method " + (this.props.className || "") }>Method</th>;
            }
        }),
        sortKeyFun: function(flow){
            return flow.request.method;
        }
    },
    render: function () {
        var flow = this.props.flow;
        return <td className="col-method">{flow.request.method}</td>;
    }
});


var StatusColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-status " + (this.props.className || "") }>Status</th>;
            }
        }),
        sortKeyFun: function(flow){
            return flow.response ? flow.response.status_code : undefined;
        }
    },
    render: function () {
        var flow = this.props.flow;
        var status;
        if (flow.response) {
            status = flow.response.status_code;
        } else {
            status = null;
        }
        return <td className="col-status">{status}</td>;
    }
});


var SizeColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-size " + (this.props.className || "") }>Size</th>;
            }
        }),
        sortKeyFun: function(flow){
            var total = flow.request.contentLength;
            if (flow.response) {
                total += flow.response.contentLength || 0;
            }
            return total;
        }
    },
    render: function () {
        var flow = this.props.flow;

        var total = flow.request.contentLength;
        if (flow.response) {
            total += flow.response.contentLength || 0;
        }
        var size = utils.formatSize(total);
        return <td className="col-size">{size}</td>;
    }
});


var TimeColumn = React.createClass({
    statics: {
        Title: React.createClass({
            render: function(){
                return <th {...this.props} className={"col-time " + (this.props.className || "") }>Time</th>;
            }
        }),
        sortKeyFun: function(flow){
            if(flow.response) {
                return flow.response.timestamp_end - flow.request.timestamp_start;
            }
        }
    },
    render: function () {
        var flow = this.props.flow;
        var time;
        if (flow.response) {
            time = utils.formatTimeDelta(1000 * (flow.response.timestamp_end - flow.request.timestamp_start));
        } else {
            time = "...";
        }
        return <td className="col-time">{time}</td>;
    }
});


var all_columns = [
    TLSColumn,
    IconColumn,
    PathColumn,
    MethodColumn,
    StatusColumn,
    SizeColumn,
    TimeColumn
];

module.exports = all_columns;