MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / parseHttpDelimiter

Method parseHttpDelimiter

src/main/java/core/packetproxy/http/Http.java:128–217  ·  view source on GitHub ↗
(byte[] data)

Source from the content-addressed store, hash-verified

126
127 // TODO header系作業をHttpHeaderに分離
128 public static int parseHttpDelimiter(byte[] data) throws Exception {
129 int header_size = HttpHeader.calcHeaderSize(data);
130 if (header_size == -1) {
131
132 return -1;
133 }
134
135 byte[] header = ArrayUtils.subarray(data, 0, header_size);
136 String header_str = new String(header, "UTF-8");
137
138 Matcher continue_matcher = CONTINUE_PATTERN.matcher(header_str);
139 if (continue_matcher.find()) {
140
141 header_size = continue_matcher.end();
142 return header_size;
143 }
144
145 Matcher plain_matcher = PLAIN_PATTERN.matcher(header_str);
146 int content_length;
147 if (plain_matcher.find()) {
148
149 content_length = Integer.parseInt(plain_matcher.group(1));
150 } else {
151
152 content_length = 0;
153 }
154
155 Matcher matcher = CHUNKED_PATTERN.matcher(header_str);
156 if (matcher.find()) {
157
158 byte[] body = ArrayUtils.subarray(data, header_size, data.length);
159 byte[] finishFlag = "0\r\n\r\n".getBytes();
160 if (body.length < finishFlag.length) {
161
162 return -1;
163 }
164 if (Arrays.compare(finishFlag, 0, finishFlag.length, body, body.length - finishFlag.length,
165 body.length) != 0) {
166
167 return -1;
168 }
169 body = getChankedHttpBody(body);
170 if (body == null)
171 return -1;
172 } else if (content_length == 0) {
173
174 if (GZIP_PATTERN.matcher(header_str).find()) {
175
176 try {
177
178 byte[] body = ArrayUtils.subarray(data, header_size, data.length);
179 gunzip(body);
180 } catch (Exception e1) {
181
182 return -1;
183 }
184 } else if (ZSTD_PATTERN.matcher(header_str).find()) {
185

Callers 6

onPacketReceivedMethod · 0.95
checkDelimiterMethod · 0.95
checkDelimiterMethod · 0.95
checkRequestDelimiterMethod · 0.95

Calls 8

calcHeaderSizeMethod · 0.95
getChankedHttpBodyMethod · 0.95
gunzipMethod · 0.95
zstd_decompressMethod · 0.95
br_decompressMethod · 0.95
compareMethod · 0.80
getBytesMethod · 0.65
findMethod · 0.45

Tested by

no test coverage detected