Skip to content

Commit 6dbba27

Browse files
author
Daniel Herzog
committed
Refactoring and a bunch of fixes around DFL-3292: Inconsistent results for response body of redirects in Network Logger
1 parent 5324d4e commit 6dbba27

File tree

5 files changed

+138
-139
lines changed

5 files changed

+138
-139
lines changed

src/network/network_details_templates.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ templates._request = function(request, is_last_request, do_raw)
130130
// That can't be determined only by looking at RequestRetry events, because a
131131
// request with for example a 401 Authorization Required response should still
132132
// be shown.
133-
if (!is_last_request && !request.was_responded)
133+
if (!is_last_request && !request.was_responded_to)
134134
return [];
135135

136136
return [
@@ -377,9 +377,10 @@ templates._response_body = function(resp, do_raw, is_last_response)
377377
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.
378378

379379
var classname = "";
380-
if ((resp.saw_responsefinished && resp.body_unavailable) ||
380+
if ((resp.saw_responsefinished && resp.no_used_mimetype) ||
381381
!resp.responsebody && resp.is_unloaded)
382382
{
383+
// Enable content-tracking.
383384
classname = "network_info";
384385
ret.push(ui_strings.S_NETWORK_REQUEST_DETAIL_NO_RESPONSE_BODY);
385386
}
@@ -389,13 +390,16 @@ templates._response_body = function(resp, do_raw, is_last_response)
389390
{
390391
if (is_last_response && !resp.logger_entry_is_finished)
391392
{
393+
// Unfinished.
392394
classname = "network_info";
393395
ret.push(ui_strings.S_NETWORK_REQUEST_DETAIL_BODY_UNFINISHED);
394396
}
395-
// else we're in the middle of getting it via GetResource, or there is in fact no responsebody.
397+
// else
398+
// We're in the middle of getting it via GetResource, or there is in fact no responsebody.
396399
}
397400
else
398401
{
402+
// Attempt to display the responsebody.
399403
if (["script", "markup", "css", "text"].contains(resp.logger_entry_type))
400404
{
401405
ret.push(

src/network/network_service.js

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ cls.NetworkLoggerService = function(view)
241241

242242
if (status)
243243
{
244-
// the object passed to _current_context represents empty event_data. will set body_unavailable.
244+
// the object passed to _current_context represents empty event_data. will set no_used_mimetype.
245245
this._current_context.update("responsebody", {resourceID: entry.resource_id});
246246
}
247247
else
@@ -578,6 +578,8 @@ cls.NetworkLoggerEntry = function(id, resource_id, document_id, context_starttim
578578
this.events = [];
579579
this.event_sequence = [];
580580
this.called_get_body = false;
581+
this.current_response = null;
582+
this.current_request = null;
581583
};
582584

583585
cls.NetworkLoggerEntryPrototype = function()
@@ -773,8 +775,8 @@ cls.NetworkLoggerEntryPrototype = function()
773775
this._update_event_urlunload = function(event)
774776
{
775777
this.is_unloaded = true;
776-
if (this._current_response)
777-
this._current_response._update_event_urlunload(event);
778+
if (this.current_response)
779+
this.current_response._update_event_urlunload(event);
778780
};
779781

780782
this._update_event_urlfinished = function(event)
@@ -785,8 +787,8 @@ cls.NetworkLoggerEntryPrototype = function()
785787
this.size = event.contentLength;
786788
this.is_finished = true;
787789
// Responses keep duplicates of the finished state. It's only relevant on the last one though.
788-
if (this._current_response)
789-
this._current_response._update_event_urlfinished(event);
790+
if (this.current_response)
791+
this.current_response._update_event_urlfinished(event);
790792

791793
this._guess_response_type();
792794
this._humanize_url();
@@ -795,31 +797,31 @@ cls.NetworkLoggerEntryPrototype = function()
795797
this._update_event_request = function(event)
796798
{
797799
this.last_method = event.method;
798-
this._current_request = new cls.NetworkLoggerRequest(this);
799-
this.requests_responses.push(this._current_request);
800-
this._current_request._update_event_request(event);
800+
this.current_request = new cls.NetworkLoggerRequest(this);
801+
this.requests_responses.push(this.current_request);
802+
this.current_request._update_event_request(event);
801803
};
802804

803805
this._update_event_requestheader = function(event)
804806
{
805-
if (!this._current_request)
807+
if (!this.current_request)
806808
{
807809
// This means we didn't see a request before that, CORE-47076
808-
this._current_request = new cls.NetworkLoggerRequest(this);
809-
this.requests_responses.push(this._current_request);
810+
this.current_request = new cls.NetworkLoggerRequest(this);
811+
this.requests_responses.push(this.current_request);
810812
}
811-
this._current_request._update_event_requestheader(event);
813+
this.current_request._update_event_requestheader(event);
812814
};
813815

814816
this._update_event_requestfinished = function(event)
815817
{
816-
if (!this._current_request)
818+
if (!this.current_request)
817819
{
818820
// There should always be a request by now, but keep the data anyway.
819-
this._current_request = new cls.NetworkLoggerRequest(this);
820-
this.requests_responses.push(this._current_request);
821+
this.current_request = new cls.NetworkLoggerRequest(this);
822+
this.requests_responses.push(this.current_request);
821823
}
822-
this._current_request._update_event_requestfinished(event);
824+
this.current_request._update_event_requestfinished(event);
823825
};
824826

825827
this._update_event_requestretry = function(event)
@@ -831,38 +833,38 @@ cls.NetworkLoggerEntryPrototype = function()
831833

832834
this._update_event_response = function(event)
833835
{
834-
if (this._current_request)
836+
if (this.current_request)
835837
{
836-
this._current_request.was_responded = true;
838+
this.current_request.was_responded_to = true;
837839
}
838840
this.last_responsecode = event.responseCode;
839841
this.error_in_last_response = /^[45]/.test(this.last_responsecode);
840-
this._current_response = new cls.NetworkLoggerResponse(this);
841-
this.requests_responses.push(this._current_response);
842-
this._current_response._update_event_response(event);
842+
this.current_response = new cls.NetworkLoggerResponse(this);
843+
this.requests_responses.push(this.current_response);
844+
this.current_response._update_event_response(event);
843845
};
844846

845847
this._update_event_responseheader = function(event)
846848
{
847849
// Sometimes we see no "response" event before we see responseheader,
848850
// therefore have to init NetworkLoggerResponse here. See CORE-43935.
849-
if (!this._current_response)
851+
if (!this.current_response)
850852
{
851-
if (this._current_request)
853+
if (this.current_request)
852854
{
853-
this._current_request.was_responded = true;
855+
this.current_request.was_responded_to = true;
854856
}
855-
this._current_response = new cls.NetworkLoggerResponse(this);
856-
this.requests_responses.push(this._current_response);
857+
this.current_response = new cls.NetworkLoggerResponse(this);
858+
this.requests_responses.push(this.current_response);
857859
}
858-
this._current_response._update_event_responseheader(event);
860+
this.current_response._update_event_responseheader(event);
859861
// todo: should _guess_response_type here? if there was a Content-Type response-header, pick it from there.
860862
};
861863

862864
this._update_event_responsefinished = function(event)
863865
{
864-
if (this._current_response)
865-
this._current_response._update_event_responsefinished(event);
866+
if (this.current_response)
867+
this.current_response._update_event_responsefinished(event);
866868

867869
if (event.data && event.data.mimeType)
868870
this.mime = event.data && event.data.mimeType;
@@ -872,13 +874,13 @@ cls.NetworkLoggerEntryPrototype = function()
872874

873875
this._update_event_responsebody = function(event)
874876
{
875-
if (!this._current_response)
877+
if (!this.current_response)
876878
{
877879
// This should mean there wasn't a request, but it was fetched over GetResource.
878-
this._current_response = new cls.NetworkLoggerResponse(this);
879-
this.requests_responses.push(this._current_response);
880+
this.current_response = new cls.NetworkLoggerResponse(this);
881+
this.requests_responses.push(this.current_response);
880882
}
881-
this._current_response._update_event_responsebody(event);
883+
this.current_response._update_event_responsebody(event);
882884
};
883885

884886
this._update_event_urlredirect = function(event)
@@ -900,8 +902,8 @@ cls.NetworkLoggerEntryPrototype = function()
900902
else
901903
this.type = cls.ResourceUtil.mime_to_type(this.mime);
902904

903-
if (this._current_response)
904-
this._current_response._update_mime_and_type(this.mime, this.type);
905+
if (this.current_response)
906+
this.current_response._update_mime_and_type(this.mime, this.type);
905907
};
906908

907909
this._humanize_url = function()
@@ -959,16 +961,6 @@ cls.NetworkLoggerEntryPrototype = function()
959961
this.events.push(evt);
960962
};
961963

962-
this.__defineGetter__("current_response_has_responsebody", function()
963-
{
964-
return Boolean(this._current_response && this._current_response.responsebody);
965-
});
966-
967-
this.__defineGetter__("current_response_saw_responsefinished", function()
968-
{
969-
return Boolean(this._current_response && this._current_response.saw_responsefinished);
970-
});
971-
972964
this.__defineGetter__("duration", function()
973965
{
974966
return (this.events.length && this.endtime - this.starttime) || 0;
@@ -983,7 +975,7 @@ cls.NetworkLoggerEntryPrototype = function()
983975

984976
this.__defineGetter__("touched_network", function()
985977
{
986-
return Boolean(this._current_request);
978+
return Boolean(this.current_request);
987979
});
988980

989981
// todo: add empty setters.
@@ -1002,7 +994,7 @@ cls.NetworkLoggerRequest = function(entry)
1002994
this.request_type = null;
1003995
this.requestbody = null;
1004996
this.boundary = "";
1005-
this.was_responded = false;
997+
this.was_responded_to = false;
1006998
// Set from template code, when first needed:
1007999
this.header_tokens = null;
10081000
// Belongs here, unused though:
@@ -1059,6 +1051,7 @@ cls.NetworkLoggerResponse = function(entry)
10591051
this.header_tokens = null; // This is set from template code, when it's first needed
10601052
this.is_response = true; // Simpler for recognizing than dealing with comparing the constructor
10611053
this.saw_responsefinished = false;
1054+
this.no_used_mimetype = false;
10621055

10631056
// The following are duplicated from the entry to have them available directly on the response
10641057
this.logger_entry_type = entry.type;
@@ -1090,20 +1083,17 @@ cls.NetworkLoggerResponsePrototype = function()
10901083
if (event.data && event.data.content)
10911084
{
10921085
// event.data is of type ResourceData here.
1093-
// todo: this does not set body_unavailable = true when there is no mimeType. does that make sense?
1086+
// From here, no_used_mimetype is not set to true when there is no mimeType.
1087+
// A later call to get_resource will set it from _update_event_responsebody.
10941088
this.responsebody = event.data;
10951089
}
10961090
};
10971091

10981092
this._update_event_responsebody = function(event)
10991093
{
1100-
// "The used mime type. This may be different from the mime type advertised in the HTTP headers."
1101-
// Todo: So this can mean that there was no response, this is better represented through "!saw_responsefinished" though,
1102-
// or that it was somehow invalid? Not so sure.
1103-
if (!event.mimeType) { this.body_unavailable = true; }
1104-
// event is of type ResourceData here.
1094+
// event.mimeType is the used mime type here.
1095+
if (!event.mimeType) { this.no_used_mimetype = true; }
11051096
this.responsebody = event;
1106-
// todo: check how to distinguish body_unavailable and empty body.
11071097
};
11081098

11091099
this._update_event_urlunload = function(event)

src/network/network_templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ templates.request_crafter_main = function(url, loading, request, response)
100100
templates.incomplete_warning = function(context, index, all_contexts)
101101
{
102102
if (context.incomplete_warn_discarded ||
103-
context.saw_main_document_abouttoloaddocument)
103+
context.saw_main_document)
104104
{
105105
return [];
106106
}

src/network/network_view.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,18 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler)
183183
var entry = ctx.get_entry_from_filtered(this._selected);
184184
if (entry)
185185
{
186-
// todo: it would be good if we knew if the whole context is finished. Better only to get_body then, less potential to disturb.
187-
if (!entry.current_response_has_responsebody &&
188-
!entry.called_get_body &&
189-
entry.is_finished &&
190-
entry.current_response_saw_responsefinished)
186+
// Decide to try to fetch the body, for when content-tracking is off or it's a cached request.
187+
if (
188+
entry.is_finished &&
189+
!entry.called_get_body &&
190+
(!entry.current_response || !entry.current_response.responsebody) &&
191+
// When we have a response, but didn't see responsefinished, it means there's really no
192+
// responsebody. Don't attempt to fetch it.
193+
(!entry.current_response || entry.current_response.saw_responsefinished)
194+
)
195+
{
191196
this._service.get_body(entry.id, this.update_bound);
192-
197+
}
193198
template = [template, this._render_details_view(entry)];
194199
}
195200
}

0 commit comments

Comments
 (0)