@@ -15,8 +15,7 @@ import 'rxjs/add/operator/share';
1515import {
1616 UserType ,
1717 AuthData ,
18- Angular2TokenOptions ,
19- HttpRequestOptions
18+ Angular2TokenOptions
2019} from './angular2-token.model' ;
2120
2221@Injectable ( )
@@ -196,67 +195,60 @@ export class Angular2TokenService implements CanActivate {
196195 }
197196
198197 // 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+ } ) ) ;
205203 }
206204
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+ } ) ) ;
214211 }
215212
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+ } ) ) ;
223219 }
224220
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+ } ) ) ;
231226 }
232227
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+ } ) ) ;
240234 }
241235
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+ } ) ) ;
248241 }
249242
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+ } ) ) ;
256248 }
257249
258250 // Construct and send Http request
259- sendHttpRequest ( options : HttpRequestOptions ) : Observable < Response > {
251+ sendHttpRequest ( requestOptions : RequestOptions ) : Observable < Response > {
260252
261253 let headers : Headers ;
262254 let baseRequestOptions : RequestOptions ;
@@ -266,6 +258,7 @@ export class Angular2TokenService implements CanActivate {
266258 if ( this . _currentAuthData != null )
267259 headers = new Headers ( {
268260 'Content-Type' : 'application/json' , // ToDo: Add to RequestOptions if available
261+ 'Accept' : 'application/json' ,
269262 'access-token' : this . _currentAuthData . accessToken ,
270263 'client' : this . _currentAuthData . client ,
271264 'expiry' : this . _currentAuthData . expiry ,
@@ -274,22 +267,17 @@ export class Angular2TokenService implements CanActivate {
274267 } ) ;
275268 else
276269 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'
278272 } ) ;
279273
280274 // Construct Default Request Options
281275 baseRequestOptions = new RequestOptions ( {
282- method : options . requestMethod ,
283- url : this . _constructApiPath ( ) + options . path ,
284- headers : headers ,
285- body : options . body
276+ headers : headers
286277 } )
287278
288279 // 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 ) ;
293281
294282 let response = this . _http . request ( new Request ( mergedRequestOptions ) ) . share ( ) ;
295283
0 commit comments