when test the proxy server, compare the port in parameter of request and

the port from proxy server.
This commit is contained in:
hmm 2014-09-09 10:22:11 +08:00
parent 270c4b8d14
commit 52243ff2f1
4 changed files with 11 additions and 9 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -322,12 +322,11 @@ public class ScriptController extends BaseController {
@RequestMapping("testRecordProxy")
@ResponseBody
public Map<String, Object> testRecordProxy(
@RequestHeader HttpHeaders headers) {
@RequestHeader HttpHeaders headers,@RequestParam String port) {
Map<String, Object> map = new HashMap<String, Object>();
// 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!");

View File

@ -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');