emberjs/data — pull request #1592 by ernie (2013-12-18 21:01:15+00:00)
Title: Honor namespace for RESTAdapter in absolute links.

Apologies if this has been discussed before, but I couldn't find it in the issue tracker.

In the RESTAdapter (1.0.0.beta3):

```javascript
findHasMany: function(store, record, url) {
var id = get(record, 'id'),
type = record.constructor.typeKey;

return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET');
},
```

`urlPrefix`, if a path is provided as the first argument, does one of two things:

1. If the path appears to be absolute, it prefixes the path with the adapter's host.
2. If the path appears to be relative, it prefixes the path with the parent URL provided as the second argument (in this case, the URL for the model containing the association)

Now, `buildURL` has the behavior of honoring the namespace in the URL that is built, which means that id-based relationships (which simply use buildURL's results) will work fine. URLs from a response's links, however, are not prefixed with this namespace.

The latest version of `findHasMany` looks like this:

```javascript
findHasMany: function(store, record, url) {
var host = get(this, 'host'),
id = get(record, 'id'),
type = record.constructor.typeKey;

if (host && url.charAt(0) === '/' && url.charAt(1) !== '/') {
url = host + url;
}

return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET');
},
```

This seems to attempt to duplicate part of the logic in the urlPrefix code already (with an apparent attempt to support protocol-relative URLs as well?).

The attached changes do the following:

1. If an absolute URL is provided by the server, the RESTAdapter will ensure it's set up with the proper host/namespace if needed.
2. If the server returns an already-namespaced absolute URL, RESTAdapter won't double up the prefix.

It should be noted that this, of course, means that an absolute URL will always be namespaced if the adapter says it should. However, this seems to be a small tradeoff since we're already (in master, at least) forcing the host part into the URL. If a server wishes the links to be observed as an absolute URL specifically from its own root, and ignoring any adapter namespace settings, it can always return a full URL, which will bypass urlPrefix's behavior.