Skip to content

Commit 11013da

Browse files
author
Daniel Herzog
committed
Fixed bug where messages were played back in the wrong order; Added error message for when parsing of request data failed;
1 parent 67fcf75 commit 11013da

File tree

4 files changed

+59
-52
lines changed

4 files changed

+59
-52
lines changed

src/network/network_request_crafting_view.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
2626
].join("\r\n");
2727

2828
this._prev_request = this._request_template;
29-
/*
30-
this._prev_response = "No response";
31-
*/
3229
this._prev_url = "";
3330

34-
/*
35-
// todo: will see what do on send, resetting is probably annoying.
3631
this.ondestroy = function()
3732
{
3833
this._prev_url = this._urlfield ? this._urlfield.get_value() : "";
3934
this._prev_request = this._input ? this._input.get_value() : "";
4035
};
41-
*/
4236

4337
this.createView = function(container)
4438
{
@@ -60,7 +54,8 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
6054
// render entries..
6155
container.clearAndRender(templates.network.request_crafter_main(this._prev_url,
6256
this._prev_request,
63-
entries));
57+
entries,
58+
this._error_message));
6459
this._urlfield = new cls.BufferManager(container.querySelector("input"));
6560
this._input = new cls.BufferManager(container.querySelector("textarea"));
6661
this._output = container.querySelector("code");
@@ -86,8 +81,10 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
8681
var requestline = lines.shift();
8782
var reqparts = requestline.match(/(\w*?) (.*) (.*)/);
8883

89-
if (!reqparts || reqparts.length != 4) {
90-
return null; // fixme: tell what's wrong
84+
if (!reqparts || reqparts.length != 4)
85+
{
86+
this._error_message = ui_strings.M_NETWORK_CRAFTER_FAILED_PARSE_REQUEST;
87+
return null;
9188
}
9289

9390
retval.method = reqparts[1];
@@ -149,17 +146,17 @@ cls.RequestCraftingView = function(id, name, container_class, html, default_hand
149146
this._service.remove_request_context(CONTEXT_TYPE_CRAFTER);
150147

151148
this._prev_url = this._urlfield.get_value();
152-
var data = this._input.get_value();
153-
var requestdata = this._parse_request(data);
154-
if (requestdata)
149+
this._prev_request = this._input.get_value();
150+
var parsed_request = this._parse_request(this._prev_request);
151+
if (parsed_request)
155152
{
156153
var ctx = this._service.get_request_context(CONTEXT_TYPE_CRAFTER, true);
157-
var crafter_request_id = ctx.send_request(this._prev_url, requestdata);
154+
this._error_message = null;
155+
var crafter_request_id = ctx.send_request(this._prev_url, parsed_request);
158156
this._crafter_requests.push(crafter_request_id);
159157
}
160158
else
161159
{
162-
// this._prev_response = ui_strings.S_INFO_REQUEST_FAILED;
163160
this.update();
164161
}
165162
}.bind(this);

src/network/network_service.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ cls.NetworkLoggerService = function()
5757
{
5858
// Play back the message queue.
5959
while (this._message_queue.length)
60-
this._replay_message_bound(this._message_queue.shift());
60+
this._playback_message_bound(this._message_queue.shift());
6161

6262
}
6363
}
6464
return false;
6565
};
6666

67-
this._replay_message_bound = function(queued)
67+
this._playback_message_bound = function(queued)
6868
{
6969
var LISTENER = 0;
7070
var MSG = 1;
71-
queued[LISTENER].call(this, queued[LISTENER], queued[MSG]);
71+
queued[LISTENER].call(this, queued[LISTENER], queued[MSG], true);
7272
}.bind(this);
7373

74-
this._on_abouttoloaddocument = function(listener, msg)
74+
this._on_abouttoloaddocument = function(listener, msg, is_playing_back)
7575
{
76-
if (this._queue_message(listener, msg))
76+
if (!is_playing_back && this._queue_message(listener, msg))
7777
return;
7878

7979
var data = new cls.DocumentManager["1.0"].AboutToLoadDocument(msg);
@@ -101,9 +101,9 @@ cls.NetworkLoggerService = function()
101101
};
102102
this._on_abouttoloaddocument_bound = this._on_abouttoloaddocument.bind(this, this._on_abouttoloaddocument_bound);
103103

104-
this._on_urlload = function(listener, msg)
104+
this._on_urlload = function(listener, msg, is_playing_back)
105105
{
106-
if (this._queue_message(listener, msg))
106+
if (!is_playing_back && this._queue_message(listener, msg))
107107
return;
108108

109109
var data = new cls.ResourceManager["1.2"].UrlLoad(msg);
@@ -119,9 +119,9 @@ cls.NetworkLoggerService = function()
119119
};
120120
this._on_urlload_bound = this._on_urlload.bind(this, this._on_urlload);
121121

122-
this._on_urlredirect = function(listener, msg)
122+
this._on_urlredirect = function(listener, msg, is_playing_back)
123123
{
124-
if (this._queue_message(listener, msg))
124+
if (!is_playing_back && this._queue_message(listener, msg))
125125
return;
126126

127127
var data = new cls.ResourceManager["1.0"].UrlRedirect(msg);
@@ -141,9 +141,9 @@ cls.NetworkLoggerService = function()
141141
};
142142
this._on_urlredirect_bound = this._on_urlredirect.bind(this, this._on_urlredirect);
143143

144-
this._on_urlfinished = function(listener, msg)
144+
this._on_urlfinished = function(listener, msg, is_playing_back)
145145
{
146-
if (this._queue_message(listener, msg))
146+
if (!is_playing_back && this._queue_message(listener, msg))
147147
return;
148148

149149
var data = new cls.ResourceManager["1.0"].UrlFinished(msg);
@@ -159,9 +159,9 @@ cls.NetworkLoggerService = function()
159159
};
160160
this._on_urlfinished_bound = this._on_urlfinished.bind(this, this._on_urlfinished);
161161

162-
this._on_response_bound = function(listener, msg)
162+
this._on_response_bound = function(listener, msg, is_playing_back)
163163
{
164-
if (this._queue_message(listener, msg))
164+
if (!is_playing_back && this._queue_message(listener, msg))
165165
return;
166166

167167
var data = new cls.ResourceManager["1.0"].Response(msg);
@@ -173,9 +173,9 @@ cls.NetworkLoggerService = function()
173173
}
174174
this._on_response_bound = this._on_response_bound.bind(this, this._on_response_bound);
175175

176-
this._on_request = function(listener, msg)
176+
this._on_request = function(listener, msg, is_playing_back)
177177
{
178-
if (this._queue_message(listener, msg))
178+
if (!is_playing_back && this._queue_message(listener, msg))
179179
return;
180180

181181
var data = new cls.ResourceManager["1.0"].Request(msg);
@@ -187,9 +187,9 @@ cls.NetworkLoggerService = function()
187187
};
188188
this._on_request_bound = this._on_request.bind(this, this._on_request);
189189

190-
this._on_requestheader = function(listener, msg)
190+
this._on_requestheader = function(listener, msg, is_playing_back)
191191
{
192-
if (this._queue_message(listener, msg))
192+
if (!is_playing_back && this._queue_message(listener, msg))
193193
return;
194194

195195
var data = new cls.ResourceManager["1.0"].RequestHeader(msg);
@@ -201,9 +201,9 @@ cls.NetworkLoggerService = function()
201201
};
202202
this._on_requestheader_bound = this._on_requestheader.bind(this, this._on_requestheader);
203203

204-
this._on_requestfinished = function(listener, msg)
204+
this._on_requestfinished = function(listener, msg, is_playing_back)
205205
{
206-
if (this._queue_message(listener, msg))
206+
if (!is_playing_back && this._queue_message(listener, msg))
207207
return;
208208

209209
var data = new cls.ResourceManager["1.0"].RequestFinished(msg);
@@ -215,9 +215,9 @@ cls.NetworkLoggerService = function()
215215
};
216216
this._on_requestfinished_bound = this._on_requestfinished.bind(this, this._on_requestfinished);
217217

218-
this._on_requestretry = function(listener, msg)
218+
this._on_requestretry = function(listener, msg, is_playing_back)
219219
{
220-
if (this._queue_message(listener, msg))
220+
if (!is_playing_back && this._queue_message(listener, msg))
221221
return;
222222

223223
var data = new cls.ResourceManager["1.0"].RequestRetry(msg);
@@ -229,9 +229,9 @@ cls.NetworkLoggerService = function()
229229
};
230230
this._on_requestretry_bound = this._on_requestretry.bind(this, this._on_requestretry);
231231

232-
this._on_responseheader = function(listener, msg)
232+
this._on_responseheader = function(listener, msg, is_playing_back)
233233
{
234-
if (this._queue_message(listener, msg))
234+
if (!is_playing_back && this._queue_message(listener, msg))
235235
return;
236236

237237
var data = new cls.ResourceManager["1.0"].ResponseHeader(msg);
@@ -243,9 +243,9 @@ cls.NetworkLoggerService = function()
243243
};
244244
this._on_responseheader_bound = this._on_responseheader.bind(this, this._on_responseheader);
245245

246-
this._on_responsefinished = function(listener, msg)
246+
this._on_responsefinished = function(listener, msg, is_playing_back)
247247
{
248-
if (this._queue_message(listener, msg))
248+
if (!is_playing_back && this._queue_message(listener, msg))
249249
return;
250250

251251
var data = new cls.ResourceManager["1.0"].ResponseFinished(msg);
@@ -259,9 +259,9 @@ cls.NetworkLoggerService = function()
259259
};
260260
this._on_responsefinished_bound = this._on_responsefinished.bind(this, this._on_responsefinished);
261261

262-
this._on_urlunload = function(listener, msg)
262+
this._on_urlunload = function(listener, msg, is_playing_back)
263263
{
264-
if (this._queue_message(listener, msg))
264+
if (!is_playing_back && this._queue_message(listener, msg))
265265
return;
266266

267267
var data = new cls.ResourceManager["1.2"].UrlUnload(msg);

src/network/network_templates.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,29 @@ templates.options_override_presets = function(overrides)
7474
].concat(overrides ? [] : ["disabled", "disabled"]);
7575
};
7676

77-
templates.request_crafter_main = function(url, request, entries)
77+
templates.request_crafter_main = function(url, request, entries, error_message)
7878
{
79-
var entry = entries[0]; // todo: will deal with multiple entries later.
8079
var response = ui_strings.M_NETWORK_CRAFTER_SEND;
81-
if (entry && entry.is_finished)
80+
if (error_message)
8281
{
83-
var helpers = window.helpers;
84-
var first_response = entry.requests_responses.filter(helpers.eq("is_response", true))[0];
85-
if (first_response)
82+
response = error_message;
83+
}
84+
else
85+
{
86+
var entry = entries[0]; // todo: will deal with multiple entries later.
87+
if (entry && entry.is_finished)
8688
{
87-
response = first_response.response_headers_raw;
88-
if (first_response.responsebody &&
89-
first_response.responsebody.content &&
90-
first_response.responsebody.content.stringData)
89+
var helpers = window.helpers;
90+
var first_response = entry.requests_responses.filter(helpers.eq("is_response", true))[0];
91+
if (first_response)
9192
{
92-
response += "\n\n" + first_response.responsebody.content.stringData;
93+
response = first_response.response_headers_raw;
94+
if (first_response.responsebody &&
95+
first_response.responsebody.content &&
96+
first_response.responsebody.content.stringData)
97+
{
98+
response += "\n\n" + first_response.responsebody.content.stringData;
99+
}
93100
}
94101
}
95102
}

src/ui-strings/ui_strings-en.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ ui_strings.M_LABEL_UI_LANGUAGE = "User interface language";
141141
/* DESC: Label for send request button in network crafter */
142142
ui_strings.M_NETWORK_CRAFTER_SEND = "Send request";
143143

144+
/* DESC: Error message for when the request could not be parsed */
145+
ui_strings.M_NETWORK_CRAFTER_FAILED_PARSE_REQUEST = "Could not parse request";
146+
144147
/* DESC: Label for request duration */
145148
ui_strings.M_NETWORK_REQUEST_DETAIL_DURATION = "Duration";
146149

0 commit comments

Comments
 (0)