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

Method toByteArray

src/main/java/core/packetproxy/http/Http.java:400–454  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

398 }
399
400 public byte[] toByteArray() throws Exception {
401 byte[] result = null;
402 byte[] newLine = new String("\r\n").getBytes();
403 String statusLine = header.getStatusline();
404
405 if (flag_request) {
406
407 // String query = (getQuery() != null && getQuery().length() > 0) ?
408 // "?"+URLEncoder.encode(getQuery(),"utf-8") : "";
409 String query = (getQueryAsString() != null && getQueryAsString().length() > 0)
410 ? "?" + getQueryAsString()
411 : "";
412 if (this.isProxy() && this.flag_disable_proxy_format_url == false) {
413
414 String proxyPort = (getServerPort() > 0) ? ":" + String.valueOf(getServerPort()) : "";
415 statusLine = String.format("%s http://%s%s%s%s %s", this.method, getServerName(), proxyPort, getPath(),
416 query, this.version);
417 } else {
418
419 statusLine = String.format("%s %s%s %s", this.method, this.path, query, this.version);
420 }
421 }
422
423 result = ArrayUtils.addAll(result, statusLine.getBytes());
424 result = ArrayUtils.addAll(result, newLine);
425 if (!flag_request && this.statusCode != null && this.statusCode.equals("100")) {
426
427 // 100 Continueの場合は、Content-Lengthがいらないのですぐに返す
428 result = ArrayUtils.addAll(result, newLine);
429 return result;
430 }
431 result = ArrayUtils.addAll(result, header.toByteArray());
432
433 if (body.length == 0 && flag_request && this.getHost() != null && (this.getHost().equals("dpoint.jp")
434 || this.getHost().equals("id.smt.docomo.ne.jp") || this.getHost().equals("cfg.smt.docomo.ne.jp"))) {
435
436 // 特定サイトでは Content-Length: 0をつけるとうまく動かないので例外処理する
437 } else if (this.flag_disable_content_length) {
438
439 // content-lengthがいらないと明示的に指定したケース
440 } else if (this.flag_dont_touch_content_length) {
441
442 // content-lengthを触らないと明示的に指定したケース
443 } else {
444
445 // Content-Typeがないパターンでも必ずContent-Lengthはつけるべき
446 // if (header.containsKey("Content-Type")) {
447 result = ArrayUtils.addAll(result, String.format("Content-Length: %d", body.length).getBytes());
448 result = ArrayUtils.addAll(result, newLine);
449 // }
450 }
451
452 result = ArrayUtils.addAll(result, newLine);
453 return ArrayUtils.addAll(result, body);
454 }
455
456 public HttpHeader getOriginalHeader() {
457 return originalHeader;

Callers 15

onServerChunkSendMethod · 0.95
onClientChunkSendMethod · 0.95
onChunkReceivedMethod · 0.95
decodeClientRequestMethod · 0.95
encodeClientRequestMethod · 0.95
decodeServerResponseMethod · 0.95
encodeServerResponseMethod · 0.95
decodeServerResponseMethod · 0.95
encodeServerResponseMethod · 0.95
decodeClientRequestMethod · 0.95
encodeClientRequestMethod · 0.95
decodeFromFramesMethod · 0.95

Calls 12

getQueryAsStringMethod · 0.95
isProxyMethod · 0.95
getServerPortMethod · 0.95
getServerNameMethod · 0.95
getPathMethod · 0.95
getHostMethod · 0.95
getStatuslineMethod · 0.80
lengthMethod · 0.80
getBytesMethod · 0.65
formatMethod · 0.45
addAllMethod · 0.45
equalsMethod · 0.45

Tested by 15

testVarint150Method · 0.36
testStringMethod · 0.36
testLongMethod · 0.36
testVarintMinusMethod · 0.36
testComplexUnorderedMethod · 0.36
testComplexMethod · 0.36
testManyFieldMethod · 0.36
testEncodeDecodeBytesMethod · 0.36
constructorHttpTest2Method · 0.36
smokeMethod · 0.36