From 52243ff2f176ca6ae62f3ad63b88a8a7c758d549 Mon Sep 17 00:00:00 2001 From: hmm Date: Tue, 9 Sep 2014 10:22:11 +0800 Subject: [PATCH] when test the proxy server, compare the port in parameter of request and the port from proxy server. --- .../bench4q/recorder/httpcapture/HttpRequestHeader.java | 7 ++++--- .../org/bench4q/recorder/httpcapture/RequestHandler.java | 2 +- .../main/java/org/bench4q/web/api/ScriptController.java | 7 +++---- .../main/webapp/script/RecordScript/RecordScriptServer.js | 4 +++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/HttpRequestHeader.java b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/HttpRequestHeader.java index 2210a0b1..e0d5e55f 100644 --- a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/HttpRequestHeader.java +++ b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/HttpRequestHeader.java @@ -198,7 +198,7 @@ public class HttpRequestHeader { return sb.toString(); } - public void buildRequestHeader(HttpURLConnection urlConnection) { + public void buildRequestHeader(HttpURLConnection urlConnection, int port) { if (0 == method.length()) method = "GET"; @@ -241,8 +241,9 @@ public class HttpRequestHeader { urlConnection.addRequestProperty("Authorization", "authorization"); // add flag show the request from proxy - urlConnection.addRequestProperty("FromProxy", - Boolean.toString(fromProxy)); + urlConnection.addRequestProperty("FromProxyPort", + Integer.toString(port)); + if (0 != unrecognized.length()){ String[] unknowHeaders = unrecognized.split(CR); diff --git a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/RequestHandler.java b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/RequestHandler.java index 87b106dc..bb8cd380 100644 --- a/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/RequestHandler.java +++ b/Bench4Q-Recorder/src/main/java/org/bench4q/recorder/httpcapture/RequestHandler.java @@ -111,7 +111,7 @@ public class RequestHandler implements Runnable { return; } - this.header.buildRequestHeader(serverConnection); + this.header.buildRequestHeader(serverConnection,this.clientSocket.getLocalPort()); log.trace("set request header"); byte[] requestBody; if (this.header.contentLength > 0) { diff --git a/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java b/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java index d2d7fbb4..2b062069 100644 --- a/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java +++ b/Bench4Q-Web/src/main/java/org/bench4q/web/api/ScriptController.java @@ -322,12 +322,11 @@ public class ScriptController extends BaseController { @RequestMapping("testRecordProxy") @ResponseBody public Map testRecordProxy( - @RequestHeader HttpHeaders headers) { + @RequestHeader HttpHeaders headers,@RequestParam String port) { Map map = new HashMap(); // is from proxy - boolean isFromProxy = Boolean.parseBoolean(headers - .getFirst("FromProxy")); - if (isFromProxy) { + String proxyPort = headers.getFirst("FromProxyPort"); + if (proxyPort!=null && proxyPort.equals(port)) { success(map); } else { fail(map, "proxy setting error!"); diff --git a/Bench4Q-Web/src/main/webapp/script/RecordScript/RecordScriptServer.js b/Bench4Q-Web/src/main/webapp/script/RecordScript/RecordScriptServer.js index 30b2720e..1b1514c6 100644 --- a/Bench4Q-Web/src/main/webapp/script/RecordScript/RecordScriptServer.js +++ b/Bench4Q-Web/src/main/webapp/script/RecordScript/RecordScriptServer.js @@ -109,7 +109,9 @@ function stopServer() { } function testRecordProxy() { - $.post("testRecordProxy", {}, function(data) { + $.post("testRecordProxy", { + port: server.port + }, function(data) { if (data.success) { $('#mySecondModal').modal('hide'); $('#myThirdModal').modal('show');