Skip to content

Commit d93d4d0

Browse files
author
Daniel Herzog
committed
For now, reverting back to old behavior of Request Crafter, showing the first response, not the last one; Fixed some todos; Fixed some naming
1 parent 2d07cff commit d93d4d0

File tree

6 files changed

+57
-20
lines changed

6 files changed

+57
-20
lines changed

src/client-en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ window.load_screen_timeout = window.setTimeout(function()
522522
<script src="./resource-manager/documentmanager.1.0.events.onabouttoloaddocument.js"/>
523523
<script src="./resource-manager/resourcemanager.1.2.events.onurlunload.js"/>
524524
<script src="./resource-manager/resourcemanager.1.2.responses.getresource.js"/>
525+
<script src="./resource-manager/resourcemanager.1.3.responses.createrequest.js"/>
525526

526527

527528
<script src="./network/network_service.js"/>

src/network/network_request_crafting_view.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,16 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
144144

145145
this._handle_send_request_bound = function()
146146
{
147+
var CONTEXT_TYPE_CRAFTER = this._service.CONTEXT_TYPE_CRAFTER;
148+
// todo: the old contexts will probably be kept for comparing previous requests.
149+
this._service.remove_request_context(CONTEXT_TYPE_CRAFTER);
150+
147151
this._prev_url = this._urlfield.get_value();
148152
var data = this._input.get_value();
149153
var requestdata = this._parse_request(data);
150154
if (requestdata)
151155
{
152-
var ctx = this._service.get_request_context(this._service.CONTEXT_TYPE_CRAFTER, true);
156+
var ctx = this._service.get_request_context(CONTEXT_TYPE_CRAFTER, true);
153157
var crafter_request_id = ctx.send_request(this._prev_url, requestdata);
154158
this._crafter_requests.push(crafter_request_id);
155159
}
@@ -190,7 +194,7 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
190194
eh.change["request-crafter-url-change"] = this._handle_url_change_bound;
191195
eh.keyup["request-crafter-url-change"] = this._handle_url_change_bound;
192196

193-
this._service.addListener("context-established", this._on_context_established_bound);
197+
this._service.addListener("context-added", this._on_context_established_bound);
194198

195199
// for onchange and buffermanager eh.click["request-crafter-send"] = this._handle_send_request_bound;
196200

src/network/network_service.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
cls.NetworkLoggerService = function()
44
{
5-
this.CONTEXT_TYPE_LOGGER = this.MAIN_CONTEXT_TYPE = "network-logger";
5+
this.CONTEXT_TYPE_LOGGER = this.CONTEXT_TYPE_MAIN = "network-logger";
66
this.CONTEXT_TYPE_CRAFTER = "request-crafter";
77

88
this._get_matching_context = function(res_id)
@@ -20,19 +20,18 @@ cls.NetworkLoggerService = function()
2020
var ctx = this.contexts[type];
2121
if (!ctx && force)
2222
{
23-
var is_main_context = type === this.MAIN_CONTEXT_TYPE;
23+
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
2424
ctx = this.contexts[type] = new cls.RequestContext(this, is_main_context);
25-
this.post("context-established", {"context_type": type});
25+
this.post("context-added", {"context_type": type});
2626
}
2727
return ctx;
2828
};
2929

30-
this.clear_request_context = function(type)
30+
this.remove_request_context = function(type)
3131
{
32-
// Todo: Maybe this should be called with the context gotten from get_request_context instead.
33-
var type = this.CONTEXT_TYPE_LOGGER;
32+
type = (type || this.CONTEXT_TYPE_MAIN);
3433
this.contexts[type] = null;
35-
this.post("context-cleared");
34+
this.post("context-removed", {"context_type": type});
3635
};
3736

3837
this._queue_message = function(listener, msg)
@@ -107,9 +106,9 @@ cls.NetworkLoggerService = function()
107106
if (!ctx)
108107
{
109108
var type = this.CONTEXT_TYPE_LOGGER;
110-
var is_main_context = type === this.MAIN_CONTEXT_TYPE;
109+
var is_main_context = type === this.CONTEXT_TYPE_MAIN;
111110
ctx = this.contexts[type] = new cls.RequestContext(this, is_main_context);
112-
this.post("context-established", {"context_type": type});
111+
this.post("context-added", {"context_type": type});
113112
}
114113
ctx.update("urlload", data);
115114
};
@@ -310,7 +309,7 @@ cls.NetworkLoggerService = function()
310309
this._doc_service = window.services["document-manager"];
311310
this._doc_service.addListener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
312311

313-
messages.addListener("debug-context-selected", this.clear_request_context.bind(this, this.CONTEXT_TYPE_LOGGER));
312+
messages.addListener("debug-context-selected", this.remove_request_context.bind(this, null));
314313
messages.addListener("setting-changed", this._on_setting_changed_bound);
315314

316315
this._message_queue = [];
@@ -742,9 +741,8 @@ cls.RequestContextPrototype = function()
742741
this.is_waiting_for_create_request = false;
743742
if (status == 0)
744743
{
745-
var RESOURCEID = 0;
746-
// todo: use the message class instead
747-
this.allocated_res_ids[msg[RESOURCEID]] = id;
744+
var data = new cls.ResourceManager["1.3"].ResourceID(msg);
745+
this.allocated_res_ids[data.resourceID] = id;
748746
}
749747
else
750748
{

src/network/network_templates.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,23 @@ templates.options_override_presets = function(overrides)
7676

7777
templates.request_crafter_main = function(url, request, entries)
7878
{
79-
var entry = entries.last; // todo: will deal with multiple entries later.
79+
var entry = entries[0]; // todo: will deal with multiple entries later.
80+
var response = ui_strings.M_NETWORK_CRAFTER_SEND;
81+
if (entry && entry.is_finished)
82+
{
83+
var helpers = window.helpers;
84+
var first_response = entry.requests_responses.filter(helpers.eq("is_response", true))[0];
85+
if (first_response)
86+
{
87+
response = first_response.response_headers_raw;
88+
if (first_response.responsebody &&
89+
first_response.responsebody.content &&
90+
first_response.responsebody.content.stringData)
91+
{
92+
response += "\n\n" + first_response.responsebody.content.stringData;
93+
}
94+
}
95+
}
8096
return (
8197
["div",
8298
["div",
@@ -102,7 +118,7 @@ templates.request_crafter_main = function(url, request, entries)
102118
],
103119
["h2", ui_strings.S_NETWORK_REQUEST_DETAIL_RESPONSE_TITLE],
104120
["p",
105-
["textarea", (entry && entry.is_finished) ? entry.current_response.response_headers_raw : ui_strings.M_NETWORK_CRAFTER_SEND]
121+
["textarea", response]
106122
],
107123
"class", "padding request-crafter"
108124
]

src/network/network_view.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
517517

518518
this._on_clear_log_bound = function(evt, target)
519519
{
520-
this._service.clear_request_context(this._service.CONTEXT_TYPE_LOGGER);
520+
this._service.remove_request_context();
521521
this.needs_instant_update = true;
522522
}.bind(this);
523523

@@ -663,6 +663,14 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
663663
}
664664
}.bind(this);
665665

666+
this._on_context_removed_bound = function(message)
667+
{
668+
if (message.context_type === this._service.CONTEXT_TYPE_LOGGER)
669+
{
670+
this.update();
671+
}
672+
}.bind(this);
673+
666674
this._init = function(id, name, container_class, html, default_handler)
667675
{
668676
var eh = window.eventHandlers;
@@ -688,8 +696,8 @@ cls.NetworkLogView = function(id, name, container_class, html, default_handler,
688696

689697
eh.click["close-incomplete-warning"] = this._on_close_incomplete_warning_bound;
690698

691-
this._service.addListener("context-established", this._on_context_established_bound);
692-
this._service.addListener("context-cleared", this.update.bind(this));
699+
this._service.addListener("context-added", this._on_context_established_bound);
700+
this._service.addListener("context-removed", this._on_context_removed_bound);
693701
this._service.addListener("resource-update", this.update.bind(this));
694702

695703
ActionHandlerInterface.apply(this);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Autogenerated by hob
2+
window.cls || (window.cls = {});
3+
cls.ResourceManager || (cls.ResourceManager = {});
4+
cls.ResourceManager["1.3"] || (cls.ResourceManager["1.3"] = {});
5+
6+
cls.ResourceManager["1.3"].ResourceID = function(arr)
7+
{
8+
this.resourceID = arr[0];
9+
};
10+

0 commit comments

Comments
 (0)