import _ from "lodash" var defaultPorts = { "http": 80, "https": 443 }; export var MessageUtils = { getContentType: function (message) { var ct = this.get_first_header(message, /^Content-Type$/i); if(ct){ return ct.split(";")[0].trim(); } }, get_first_header: function (message, regex) { //FIXME: Cache Invalidation. if (!message._headerLookups) Object.defineProperty(message, "_headerLookups", { value: {}, configurable: false, enumerable: false, writable: false }); if (!(regex in message._headerLookups)) { var header; for (var i = 0; i < message.headers.length; i++) { if (!!message.headers[i][0].match(regex)) { header = message.headers[i]; break; } } message._headerLookups[regex] = header ? header[1] : undefined; } return message._headerLookups[regex]; }, match_header: function (message, regex) { var headers = message.headers; var i = headers.length; while (i--) { if (regex.test(headers[i].join(" "))) { return headers[i]; } } return false; }, getContentURL: function (flow, message, view) { if (message === flow.request) { message = "request"; } else if (message === flow.response) { message = "response"; } return `./flows/${flow.id}/${message}/` + (view ? `content/${view}.json` : 'content.data'); } }; export var RequestUtils = _.extend(MessageUtils, { pretty_url: function (request) { var port = ""; if (defaultPorts[request.scheme] !== request.port) { port = ":" + request.port; } return request.scheme + "://" + request.pretty_host + port + request.path; } }); export var ResponseUtils = _.extend(MessageUtils, {}); var parseUrl_regex = /^(?:(https?):\/\/)?([^\/:]+)?(?::(\d+))?(\/.*)?$/i; export var parseUrl = function (url) { //there are many correct ways to parse a URL, //however, a mitmproxy user may also wish to generate a not-so-correct URL. ;-) var parts = parseUrl_regex.exec(url); if(!parts){ return false; } var scheme = parts[1], host = parts[2], port = parseInt(parts[3]), path = parts[4]; if (scheme) { port = port || defaultPorts[scheme]; } var ret = {}; if (scheme) { ret.scheme = scheme; } if (host) { ret.host = host; } if (port) { ret.port = port; } if (path) { ret.path = path; } return ret; }; var isValidHttpVersion_regex = /^HTTP\/\d+(\.\d+)*$/i; export var isValidHttpVersion = function (httpVersion) { return isValidHttpVersion_regex.test(httpVersion); }; pnr/tree/3rdparty/imgui?id=68ca923bfefde24fa2b7cbc8c6f9817f1d93e1e5'>imgui/examples/example_glfw_opengl3/main.cpp
blob: f9b9b643eecdab72f09a3b28941db659f52f654a (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