Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Storing/retrieving the method/URL of the previous request. #2399

Open
wants to merge 4 commits into from

3 participants

@arian
Owner

:+1:

@ibolmo ibolmo commented on the diff
Source/Request/Request.js
@@ -196,7 +209,7 @@ var Request = this.Request = new Class({
xhr.onprogress = this.progress.bind(this);
}
- xhr.open(method.toUpperCase(), url, this.options.async, this.options.user, this.options.password);
+ xhr.open(upperMethod, url, this.options.async, this.options.user, this.options.password);
@ibolmo Owner
ibolmo added a note
this.method = method.toUpperCase();
this.url = url;

// ...

xhr.open(this.method, url, // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ibolmo ibolmo commented on the diff
Docs/Request/Request.md
@@ -248,6 +248,46 @@ Returns the given response header or null if not found.
alert(this.getHeader('Date')); // alerts the server date (for example, 'Thu, 26 Feb 2009 20:26:06 GMT')
}});
+Request Method: getUrl {#Request:getUrl}
@ibolmo Owner
ibolmo added a note

Instead of getUrl it should be getURL since it's Uniform Resource Locator

...

Then again I haven't checked other methods with acronyms for usage. @arian do you recall?

@arian Owner
arian added a note

agreed, will check if we do this consistently.

@arian Owner
arian added a note

we do with String.uniqueID, DOMEvent, Fx.CSS, .. , but not really with [...].hexToRgb. So I would say we usually do this.

@ibolmo Owner
ibolmo added a note

Thanks @arian for the research. @chrispitt just update the PR, and fix the small optimization and LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ibolmo
Owner

Sorry I just thought of a little UX problem:

var request = new Request({ url: '#' });
request.getURL(); // null <-- oops!
@assertchris

The docs clearly state that those methods return data from the last request, not from option state.

@arian
Owner

I think it should return what's passed in xhr.open.

@arian
Owner

but looking at the code that happens.. (except with GET data stuff)

@ibolmo ibolmo modified the milestone: 1.6, 1.5
@ibolmo ibolmo added the enhancement label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
40 Docs/Request/Request.md
@@ -248,6 +248,46 @@ Returns the given response header or null if not found.
alert(this.getHeader('Date')); // alerts the server date (for example, 'Thu, 26 Feb 2009 20:26:06 GMT')
}});
+Request Method: getUrl {#Request:getUrl}
@ibolmo Owner
ibolmo added a note

Instead of getUrl it should be getURL since it's Uniform Resource Locator

...

Then again I haven't checked other methods with acronyms for usage. @arian do you recall?

@arian Owner
arian added a note

agreed, will check if we do this consistently.

@arian Owner
arian added a note

we do with String.uniqueID, DOMEvent, Fx.CSS, .. , but not really with [...].hexToRgb. So I would say we usually do this.

@ibolmo Owner
ibolmo added a note

Thanks @arian for the research. @chrispitt just update the PR, and fix the small optimization and LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+--------------------------------------
+
+Returns the last URL requested.
+
+### Syntax:
+
+ myRequest.getUrl();
+
+### Returns:
+
+* (*string*) The value last URL requested.
+* (*null*) `null` if no request has yet been made.
+
+### Example:
+
+ var myRequest = new Request({url: 'getData.php', method: 'get', onSuccess: function(responseText, responseXML){
+ alert(this.getUrl()); // alerts 'getData.php'
+ }});
+
+Request Method: getMethod {#Request:getMethod}
+--------------------------------------
+
+Returns the method used in the last request.
+
+### Syntax:
+
+ myRequest.getMethod();
+
+### Returns:
+
+* (*string*) The method used in the last request.
+* (*null*) `null` if no request has yet been made.
+
+### Example:
+
+ var myRequest = new Request({url: 'getData.php', method: 'get', onSuccess: function(responseText, responseXML){
+ alert(this.getMethod()); // alerts 'GET'
+ }});
+
Request Method: send {#Request:send}
----------------------------
View
15 Source/Request/Request.js
@@ -134,6 +134,14 @@ var Request = this.Request = new Class({
}.bind(this));
},
+ getUrl: function(){
+ return this.url;
+ },
+
+ getMethod: function(){
+ return this.method;
+ },
+
check: function(){
if (!this.running) return true;
switch (this.options.link){
@@ -166,6 +174,11 @@ var Request = this.Request = new Class({
data = (data) ? format + '&' + data : format;
}
+ var upperMethod = method.toUpperCase();
+
+ this.method = upperMethod;
+ this.url = url;
+
if (this.options.emulation && !['get', 'post'].contains(method)){
var _method = '_method=' + method;
data = (data) ? _method + '&' + data : _method;
@@ -196,7 +209,7 @@ var Request = this.Request = new Class({
xhr.onprogress = this.progress.bind(this);
}
- xhr.open(method.toUpperCase(), url, this.options.async, this.options.user, this.options.password);
+ xhr.open(upperMethod, url, this.options.async, this.options.user, this.options.password);
@ibolmo Owner
ibolmo added a note
this.method = method.toUpperCase();
this.url = url;

// ...

xhr.open(this.method, url, // ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if (this.options.user && 'withCredentials' in xhr) xhr.withCredentials = true;
xhr.onreadystatechange = this.onStateChange.bind(this);
View
35 Specs/1.3client/Request/Request.js
@@ -136,5 +136,40 @@ describe('Request', function(){
});
+ it('should store last method and url of request on send', function(){
+
+ var firstUrl = '../Helpers/request.php?first',
+ firstMethod = 'GET',
+
+ secondUrl = '../Helpers/request.php?second',
+ secondMethod = 'POST',
+
+ request = new Request({
+ url: firstUrl,
+ method: firstMethod,
+ data: {
+ '__response': 'hello world'
+ }
+ }),
+
+ fake = this.requests[0];
+
+ request.send();
+ fake.respond(200, {'Content-Type': 'text/plain'});
+
+ expect(request.url).toBe(firstUrl);
+ expect(request.method).toBe(firstMethod);
+
+ request.setOptions({
+ url: secondUrl,
+ method: secondMethod
+ }).send();
+ fake.respond(200, {'Content-Type': 'text/plain'});
+
+ expect(request.getUrl()).toBe(secondUrl);
+ expect(request.getMethod()).toBe(secondMethod);
+
+ });
+
});
Something went wrong with that request. Please try again.