Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
Update: Added property to ArcRequest object that is a string represen…
Browse files Browse the repository at this point in the history
…tation of a message sent to server
  • Loading branch information
jarrodek committed Apr 12, 2016
1 parent 4c5ab1f commit 022e4b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app.fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SocketFetch extends ArcEventSource {
* @type {Number}
* @default 80
*/
post: 80,
port: 80,
/**
* A integer representing status code of the response.
*
Expand Down Expand Up @@ -208,6 +208,13 @@ class SocketFetch extends ArcEventSource {
* @type {Number}
*/
chunkSize: undefined,
/**
* Message sent to the remote machine as a string of source message.
* If the request consisted of binnary data it will be presented as a string.
*
* @type {String}
*/
messageSent: undefined,
/**
* Some stats about the connection
*/
Expand Down Expand Up @@ -564,6 +571,7 @@ class SocketFetch extends ArcEventSource {
if (['GET', 'HEADER'].indexOf(opts.method.toUpperCase()) !== -1) {
delete opts.body;
}
opts.messageSent = this._connection.messageSent;
return new ArcRequest(url, opts);
}
/**
Expand Down Expand Up @@ -639,11 +647,12 @@ class SocketFetch extends ArcEventSource {
}
this.generateMessage()
.then((buffer) => {
let message = this.arrayBufferToString(buffer);
if (this.debug) {
let debugMsg = this.arrayBufferToString(buffer);
this.log('Generated message to send\n', debugMsg);
this.log('Generated message to send\n', message);
}
this.log('Sending message.');
this._connection.messageSent = message;
this._connection.stats._messageSending = performance.now();
chrome.sockets.tcp.send(this._connection.socketId, buffer, this.onSend.bind(this));
});
Expand Down Expand Up @@ -906,7 +915,7 @@ class SocketFetch extends ArcEventSource {
this.onResponseReady();
return;
}
var message = this.getCodeMessage(code);
var message = '[chrome socket error]: ' + this.getCodeMessage(code);
this.log('readSocketError:', message, code);
if (this.state !== SocketFetch.DONE && this._mainPromise.reject) {
let error = new Error(message);
Expand Down Expand Up @@ -1141,7 +1150,7 @@ class SocketFetch extends ArcEventSource {
return this._cleanUpRedirect();
})
.then(() => {

this._request.url = location;
this._setupUrlData();
this._createConnection();
Expand Down Expand Up @@ -1202,6 +1211,7 @@ class SocketFetch extends ArcEventSource {
this._connection.host = undefined;
this._connection.port = undefined;
this._response = undefined;
this._connection.messageSent = undefined;
this._connection.stats.startTime = undefined;
this._connection.stats.connect = undefined;
this._connection.stats.send = undefined;
Expand Down
18 changes: 18 additions & 0 deletions app.request.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class ArcRequest {
* @type {Boolean}
*/
this._payloadRequest = undefined;
/**
* A string representation of the message sent to the server.
*
* @type {String}
*/
this._messageSent = undefined;

if (input instanceof ArcRequest ||
input instanceof Request) {
Expand Down Expand Up @@ -117,6 +123,9 @@ class ArcRequest {
if ('timeout' in init) {
this.timeout = init.timeout;
}
if ('messageSent' in init) {
this.messageSent = init.messageSent;
}
}
/**
* Assign initial value from existing {@link ArcRequest} object
Expand All @@ -132,6 +141,7 @@ class ArcRequest {
this._body = input._body;
this._redirect = input._redirect;
this._timeout = input._timeout;
this._messageSent = input._messageSent;
}
/**
* Sets a HTTP method to this {@link ArcRequest} object.
Expand Down Expand Up @@ -234,6 +244,14 @@ class ArcRequest {
get timeout() {
return this._timeout;
}

set messageSent(message) {
this._messageSent = message;
}

get messageSent() {
return this._messageSent;
}
}
window.ArcRequest = ArcRequest;
})();

0 comments on commit 022e4b6

Please sign in to comment.