feat(http): serialize search parameters from request options
- Extends URLSearchParams API to include operations for combining
different URLSearchParams objects:
These new methods include:
setAll(otherParams): performs `this.set(key, values[0])` for each
key/value-list pair in `otherParams`
appendAll(otherParams): performs `this.append(key, values)` for
each key/value-list pair in `otherParams`
replaceAll(otherParams): for each key/value-list pair in
`otherParams`, replaces current set of values for `key` with
a copy of the list of values.
- RequestOptions do not merge search params automatically (because
there are multiple ways to do this). Instead, they replace any
existing `search` field if `search` is provided. Explicit merging
is required if merging is desirable.
- Some extra test coverage added.
Closes #2417
Closes #3020
This commit is contained in:
committed by
Tobias Bosch
parent
dfa5103b1d
commit
77d3668432
@@ -6,7 +6,8 @@ import {
|
||||
RegExpWrapper,
|
||||
CONST_EXPR,
|
||||
isPresent,
|
||||
isJsObject
|
||||
isJsObject,
|
||||
StringWrapper
|
||||
} from 'angular2/src/facade/lang';
|
||||
|
||||
// TODO(jeffbcross): properly implement body accessors
|
||||
@@ -39,7 +40,19 @@ export class Request {
|
||||
cache: RequestCacheOpts;
|
||||
constructor(requestOptions: RequestOptions) {
|
||||
// TODO: assert that url is present
|
||||
let url = requestOptions.url;
|
||||
this.url = requestOptions.url;
|
||||
if (isPresent(requestOptions.search)) {
|
||||
let search = requestOptions.search.toString();
|
||||
if (search.length > 0) {
|
||||
let prefix = '?';
|
||||
if (StringWrapper.contains(this.url, '?')) {
|
||||
prefix = (this.url[this.url.length - 1] == '&') ? '' : '&';
|
||||
}
|
||||
// TODO: just delete search-query-looking string in url?
|
||||
this.url = url + prefix + search;
|
||||
}
|
||||
}
|
||||
this._body = requestOptions.body;
|
||||
this.method = requestOptions.method;
|
||||
// TODO(jeffbcross): implement behavior
|
||||
|
||||
Reference in New Issue
Block a user