Skip to content

Commit f67fe34

Browse files
author
Daniel Herzog
committed
Some cleaning up.
1 parent 56db624 commit f67fe34

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

src/network/network_details_templates.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ templates._details_content = function(entry, do_raw)
5656
if (responsecode && responsecode in cls.ResourceUtil.http_status_codes)
5757
responsecode = responsecode + " " + cls.ResourceUtil.http_status_codes[responsecode];
5858

59-
// todo: not really pretty
60-
if (!this["_requests_responses_" + do_raw])
61-
this["_requests_responses_" + do_raw] = this.requests_responses.bind(this, do_raw);
59+
// Bind a template function for raw / not-raw, on demand.
60+
var template_func_name = "_requests_responses_" + do_raw ? "raw" : "not_raw" + "_bound";
61+
if (!this[template_func_name])
62+
this[template_func_name] = this.requests_responses.bind(null, do_raw);
6263

63-
var requests_responses = entry.requests_responses.map(this["_requests_responses_" + do_raw])
64+
var requests_responses = entry.requests_responses.map(this[template_func_name]);
6465

6566
if (do_raw)
6667
{
@@ -105,27 +106,19 @@ templates.did_not_touch_network = function(entry)
105106

106107
templates.requests_responses = function(do_raw, request_response, index, requests_responses)
107108
{
108-
var is_last_of_type = true;
109-
var template_func;
110-
111-
// todo: ugly.
112-
if (request_response instanceof cls.NetworkLoggerRequest)
113-
{
114-
for (var i = index + 1, req_res; req_res = requests_responses[i]; i++)
115-
if (req_res instanceof cls.NetworkLoggerRequest)
116-
is_last_of_type = false;
109+
var template_func = this._request;
110+
if (request_response.is_response)
111+
template_func = this._response;
117112

118-
template_func = this._request;
119-
}
120-
else
113+
var is_last_of_type = true;
114+
for (var i = index + 1, req_res; req_res = requests_responses[i]; i++)
121115
{
122-
for (var i = index + 1, req_res; req_res = requests_responses[i]; i++)
123-
if (req_res instanceof cls.NetworkLoggerResponse)
124-
is_last_of_type = false;
125-
126-
template_func = this._response;
116+
if (request_response.is_response == req_res.is_response)
117+
{
118+
is_last_of_type = false;
119+
break;
120+
}
127121
}
128-
129122
return template_func.call(this, request_response, is_last_of_type, do_raw);
130123
};
131124

@@ -146,11 +139,11 @@ templates._request = function(request, is_last_request, do_raw)
146139
]
147140
};
148141

149-
templates._response = function(response, is_last, do_raw) // todo: is_last_response?
142+
templates._response = function(response, is_last_response, do_raw)
150143
{
151144
return [
152145
this._response_headers(response, do_raw),
153-
this._response_body(response, do_raw, is_last)
146+
this._response_body(response, do_raw, is_last_response)
154147
]
155148
};
156149

@@ -379,7 +372,7 @@ templates._request_body = function(req, do_raw)
379372
};
380373

381374

382-
templates._response_body = function(resp, do_raw, is_last)
375+
templates._response_body = function(resp, do_raw, is_last_response)
383376
{
384377
var ret = [this._wrap_pre("\n")]; // todo: no, then it's (really) empty there shouldn't be a separator either. For images it looks a bit wrong too, since the img elem makes its own space too.
385378

@@ -394,7 +387,7 @@ templates._response_body = function(resp, do_raw, is_last)
394387
{
395388
if (!resp.responsebody)
396389
{
397-
if (is_last && !resp.logger_entry_is_finished)
390+
if (is_last_response && !resp.logger_entry_is_finished)
398391
{
399392
classname = "network_info";
400393
ret.push(ui_strings.S_NETWORK_REQUEST_DETAIL_BODY_UNFINISHED);

src/network/network_service.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,6 @@ cls.NetworkLoggerRequest = function(entry)
925925
this.request_headers = null;
926926
this.request_headers_raw = null;
927927
this.request_type = null;
928-
this.firstline = null;
929928
this.requestbody = null;
930929
this.boundary = "";
931930
this.was_responded = false;
@@ -955,11 +954,9 @@ cls.NetworkLoggerRequestPrototype = function()
955954
break;
956955
}
957956
}
958-
this.firstline = event.raw.split("\n")[0]; // todo: event.raw.split("\r\n")[0];
959957
// The body can be contained in event.raw.
960958
// At the time of the this event, it's possible that more than the header
961959
// has been written to the socket already.
962-
this.raw = event.raw; // todo: debugging only. remove me.
963960
this.request_headers_raw = event.raw.split("\r\n\r\n")[0];
964961
};
965962

@@ -983,9 +980,9 @@ cls.NetworkLoggerResponse = function(entry)
983980
this.responsecode = null;
984981
this.response_headers = null;
985982
this.response_headers_raw = null;
986-
this.firstline = null;
987983
this.responsebody = null;
988-
this.header_tokens = null; // This is set from template code, when it's first needed.
984+
this.header_tokens = null; // This is set from template code, when it's first needed
985+
this.is_response = true; // Simpler for recognizing than dealing with comparing the constructor
989986

990987
// The following are duplicated from the entry to have them available directly on the response
991988
this.logger_entry_type = entry.type;
@@ -1009,7 +1006,6 @@ cls.NetworkLoggerResponsePrototype = function()
10091006
// At the time of the this event, it's possible that more than the header
10101007
// has been read from the socket already.
10111008
this.response_headers_raw = event.raw.split("\r\n\r\n")[0];
1012-
this.firstline = this.response_headers_raw.split("\n")[0]; // todo: this.response_headers_raw.split("\r\n")[0];
10131009
};
10141010

10151011
this._update_event_responsefinished = function(event)

0 commit comments

Comments
 (0)