angular/angular.js — pull request #2725 by prajwalkman (2013-05-21 07:33:02+00:00)
Title: feat($http) Add support for custom event hooks (progress, etc)

In response to https://github.com/angular/angular.js/issues/1934
This is far from complete, I just wanted to open a preliminary implementation so we can discuss implementation details.
I'm neither an expert at Angular, nor in the HTTP protocol itself.

The current implementation of `$http` doesn't allow us to attach event handlers for anything except success and failure. There are a large number of well supported (and maybe non standard) events for XHR that are very useful, the most popular being the progress events.

This PR implements the feature by extending the `config` object passed to `$http` to add a `hooks` keyword, which maps events to event handler.
Example:
```javascript
var configObject = {
method: 'GET',
url: '/specs.html',
cache: $templateCache,
hooks: {
progress: function(data) {
return $scope.progress = data;
}
}
};
$http(configObject).success(successHandler);
```

To add event handlers for upload events, nest the key mapping under a `upload` key:
```javascript
hooks: {
upload: {
progress: uploadProgressHandler;
}
}
```

Please suggest/discuss improvements to the syntax and/or implementation errors.
I believe the code in the PR currently works, but I haven't thoroughly tested it.