@@ -15,8 +15,7 @@ import 'rxjs/add/operator/share';
15
15
import {
16
16
UserType ,
17
17
AuthData ,
18
- Angular2TokenOptions ,
19
- HttpRequestOptions
18
+ Angular2TokenOptions
20
19
} from './angular2-token.model' ;
21
20
22
21
@Injectable ( )
@@ -196,67 +195,60 @@ export class Angular2TokenService implements CanActivate {
196
195
}
197
196
198
197
// Standard HTTP requests
199
- get ( path : string , requestOptions ?: RequestOptions ) : Observable < Response > {
200
- return this . sendHttpRequest ( {
201
- requestMethod : RequestMethod . Get ,
202
- path : path ,
203
- requestOptions : requestOptions
204
- } ) ;
198
+ get ( path : string ) : Observable < Response > {
199
+ return this . sendHttpRequest ( new RequestOptions ( {
200
+ method : RequestMethod . Get ,
201
+ url : this . _constructApiPath ( ) + path
202
+ } ) ) ;
205
203
}
206
204
207
- post ( path : string , data : any , requestOptions ?: RequestOptions ) : Observable < Response > {
208
- return this . sendHttpRequest ( {
209
- requestMethod : RequestMethod . Post ,
210
- path : path ,
211
- body : data ,
212
- requestOptions : requestOptions
213
- } ) ;
205
+ post ( path : string , data : any ) : Observable < Response > {
206
+ return this . sendHttpRequest ( new RequestOptions ( {
207
+ method : RequestMethod . Post ,
208
+ url : this . _constructApiPath ( ) + path ,
209
+ body : data
210
+ } ) ) ;
214
211
}
215
212
216
- put ( path : string , data : any , requestOptions ?: RequestOptions ) : Observable < Response > {
217
- return this . sendHttpRequest ( {
218
- requestMethod : RequestMethod . Put ,
219
- path : path ,
220
- body : data ,
221
- requestOptions : requestOptions
222
- } ) ;
213
+ put ( path : string , data : any ) : Observable < Response > {
214
+ return this . sendHttpRequest ( new RequestOptions ( {
215
+ method : RequestMethod . Put ,
216
+ url : this . _constructApiPath ( ) + path ,
217
+ body : data
218
+ } ) ) ;
223
219
}
224
220
225
- delete ( path : string , requestOptions ?: RequestOptions ) : Observable < Response > {
226
- return this . sendHttpRequest ( {
227
- requestMethod : RequestMethod . Delete ,
228
- path : path ,
229
- requestOptions : requestOptions
230
- } ) ;
221
+ delete ( path : string ) : Observable < Response > {
222
+ return this . sendHttpRequest ( new RequestOptions ( {
223
+ method : RequestMethod . Delete ,
224
+ url : this . _constructApiPath ( ) + path
225
+ } ) ) ;
231
226
}
232
227
233
- patch ( path : string , data : any , requestOptions ?: RequestOptions ) : Observable < Response > {
234
- return this . sendHttpRequest ( {
235
- requestMethod : RequestMethod . Patch ,
236
- path : path ,
237
- body : data ,
238
- requestOptions : requestOptions
239
- } ) ;
228
+ patch ( path : string , data : any ) : Observable < Response > {
229
+ return this . sendHttpRequest ( new RequestOptions ( {
230
+ method : RequestMethod . Patch ,
231
+ url : this . _constructApiPath ( ) + path ,
232
+ body : data
233
+ } ) ) ;
240
234
}
241
235
242
- head ( path : string , requestOptions ?: RequestOptions ) : Observable < Response > {
243
- return this . sendHttpRequest ( {
244
- requestMethod : RequestMethod . Head ,
245
- path : path ,
246
- requestOptions : requestOptions
247
- } ) ;
236
+ head ( path : string ) : Observable < Response > {
237
+ return this . sendHttpRequest ( new RequestOptions ( {
238
+ method : RequestMethod . Head ,
239
+ url : this . _constructApiPath ( ) + path
240
+ } ) ) ;
248
241
}
249
242
250
- options ( path : string , requestOptions ?: RequestOptions ) : Observable < Response > {
251
- return this . sendHttpRequest ( {
252
- requestMethod : RequestMethod . Options ,
253
- path : path ,
254
- requestOptions : requestOptions
255
- } ) ;
243
+ options ( path : string ) : Observable < Response > {
244
+ return this . sendHttpRequest ( new RequestOptions ( {
245
+ method : RequestMethod . Options ,
246
+ url : this . _constructApiPath ( ) + path
247
+ } ) ) ;
256
248
}
257
249
258
250
// Construct and send Http request
259
- sendHttpRequest ( options : HttpRequestOptions ) : Observable < Response > {
251
+ sendHttpRequest ( requestOptions : RequestOptions ) : Observable < Response > {
260
252
261
253
let headers : Headers ;
262
254
let baseRequestOptions : RequestOptions ;
@@ -266,6 +258,7 @@ export class Angular2TokenService implements CanActivate {
266
258
if ( this . _currentAuthData != null )
267
259
headers = new Headers ( {
268
260
'Content-Type' : 'application/json' , // ToDo: Add to RequestOptions if available
261
+ 'Accept' : 'application/json' ,
269
262
'access-token' : this . _currentAuthData . accessToken ,
270
263
'client' : this . _currentAuthData . client ,
271
264
'expiry' : this . _currentAuthData . expiry ,
@@ -274,22 +267,17 @@ export class Angular2TokenService implements CanActivate {
274
267
} ) ;
275
268
else
276
269
headers = new Headers ( {
277
- 'Content-Type' : 'application/json' // ToDo: Add to RequestOptions if available
270
+ 'Content-Type' : 'application/json' , // ToDo: Add to RequestOptions if available
271
+ 'Accept' : 'application/json'
278
272
} ) ;
279
273
280
274
// Construct Default Request Options
281
275
baseRequestOptions = new RequestOptions ( {
282
- method : options . requestMethod ,
283
- url : this . _constructApiPath ( ) + options . path ,
284
- headers : headers ,
285
- body : options . body
276
+ headers : headers
286
277
} )
287
278
288
279
// Merge standard and custom RequestOptions
289
- if ( options . requestOptions != null )
290
- mergedRequestOptions = baseRequestOptions . merge ( options . requestOptions ) ;
291
- else
292
- mergedRequestOptions = baseRequestOptions ;
280
+ mergedRequestOptions = baseRequestOptions . merge ( requestOptions ) ;
293
281
294
282
let response = this . _http . request ( new Request ( mergedRequestOptions ) ) . share ( ) ;
295
283
0 commit comments