Opened 9 years ago

Closed 8 years ago

#17323 closed defect (wontfix)

dojo/request/xhr methods ignore returnDeferred argument

Reported by: Stefan Bird Owned by: Bryan Forbes
Priority: undecided Milestone: tbd
Component: IO Version: 1.9.1
Keywords: Cc:
Blocked By: Blocking:


dojo/request/util.addCommonMethods() only passes on the first two arguments to the provider function, meaning that the returnDeferred argument isn't available when calling xhr.get()/ etc. This argument is important as it's the only way to access the headers sent back by the server. This issue can be fixed by changing the function to

exports.addCommonMethods = function addCommonMethods(provider, methods){
        array.forEach(methods||['GET', 'POST', 'PUT', 'DELETE'], function(method){
                provider[(method === 'DELETE' ? 'DEL' : method).toLowerCase()] = function(url, options){
                        arguments[1] = lang.delegate(options, {method: method});
                        return provider.apply(this, arguments);

Change History (2)

comment:1 Changed 9 years ago by bill

Component: GeneralIO
Owner: set to Bryan Forbes

comment:2 Changed 8 years ago by Bryan Forbes

Resolution: wontfix
Status: newclosed

The returnDeferred argument is only there for the backwards compatible APIs like dojo/_base/xhr. To get response headers using dojo/request, use the response property of the returned promise:

request.get('some/url').response.then(function (response) {
    if (response.getHeader('Some-Header') === 'foo') {
Note: See TracTickets for help on using tickets.