Skip to content

Commit

Permalink
show hostname in transparent mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Aug 14, 2012
1 parent 397e518 commit 84fe7b3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 64 deletions.
127 changes: 68 additions & 59 deletions gui/js/HoneyProxy/models/Request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,71 @@
Request = function(flow){
this._flow = flow;
};
Request.prototype = {
get _attr() {
return "request";
},
get path() {
return this.data.path;
},
get host() {
return this.data.host;
},
get port() {
return this.data.port;
},
get method() {
return this.data.method;
},
get scheme() {
return this.data.scheme;
},
get hasFormData() {
if(!this.hasContent)
return false;
var requestContentType = this.getHeader(/Content-Type/i);
return !!requestContentType.match(/^application\/x-www-form-urlencoded\s*(;.*)?$/i);
},
get hasPayload() {
return this.hasContent && (!this.hasFormData);
},
getFormData: function(callback){
if(this._flow.has("formDataParsed"))
callback(this._flow.get("formDataParsed"));
else
this.getContent((function(data){
var formData = HoneyProxy.parseParameters(data)
this._flow.set("formDataParsed",formData);
callback(formData);
}).bind(this));
return this;
},
_processName: function(){
var params = this.path.split("?");
var path = params.shift().split("/");
var filename = path.pop();
this._flow.set("filename", filename==="" ? "/" : filename );
this._flow.set("fullpath", this.scheme + "://" + this.host + ":" + this.port + path.join("/") + "/" );
},
get filename() {
if(!this._flow.has("filename"))
this._processName();
return this._flow.get("filename");
},
get fullPath() {
if(!this._flow.has("fullpath"))
this._processName();
return this._flow.get("fullpath");
}
};
//depends on https://github.com/documentcloud/underscore/pull/694
_.extend(Request.prototype,HoneyProxy.sharedFlowProperties);
(function(){

const isIP = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/;
Request.prototype = {
get _attr() {
return "request";
},
get path() {
return this.data.path;
},
get host() {
if(isIP.test(this.data.host))
{
return this.getHeader(/^Host$/i);
}
return this.data.host;
},
get port() {
return this.data.port;
},
get method() {
return this.data.method;
},
get scheme() {
return this.data.scheme;
},
get hasFormData() {
if(!this.hasContent)
return false;
var requestContentType = this.getHeader(/Content-Type/i);
return !!requestContentType.match(/^application\/x-www-form-urlencoded\s*(;.*)?$/i);
},
get hasPayload() {
return this.hasContent && (!this.hasFormData);
},
getFormData: function(callback){
if(this._flow.has("formDataParsed"))
callback(this._flow.get("formDataParsed"));
else
this.getContent((function(data){
var formData = HoneyProxy.parseParameters(data)
this._flow.set("formDataParsed",formData);
callback(formData);
}).bind(this));
return this;
},
_processName: function(){
var params = this.path.split("?");
var path = params.shift().split("/");
var filename = path.pop();
this._flow.set("filename", filename==="" ? "/" : filename );
this._flow.set("fullpath", this.scheme + "://" + this.host + ":" + this.port + path.join("/") + "/" );
},
get filename() {
if(!this._flow.has("filename"))
this._processName();
return this._flow.get("filename");
},
get fullPath() {
if(!this._flow.has("fullpath"))
this._processName();
return this._flow.get("fullpath");
}
};
//depends on https://github.com/documentcloud/underscore/pull/694
_.extend(Request.prototype,HoneyProxy.sharedFlowProperties);

})();
16 changes: 11 additions & 5 deletions gui/js/HoneyProxy/models/sharedFlowProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ HoneyProxy.sharedFlowProperties = {
return this._flow.get(attr);
},
getHeader: function(regex){
//TODO: Caching
var header = _.find(this.headers, function(header){
return !!header[0].match(regex);
});
return header ? header[1] : undefined;
var attr = this._attr + "CachedHeaderLookups";
if(!this._flow.has(attr))
this._flow.set(attr,{});
if(!(regex in this._flow.get(attr))) {
var header = _.find(this.headers, function(header){
return !!header[0].match(regex);
});
this._flow.get(attr)[regex] = header ? header[1] : undefined;
}
return this._flow.get(attr)[regex];

},
get headers() {
return this.data.headers;
Expand Down

0 comments on commit 84fe7b3

Please sign in to comment.