本文整理汇总了TypeScript中@angular/common/http.HttpHandler.handle方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpHandler.handle方法的具体用法?TypeScript HttpHandler.handle怎么用?TypeScript HttpHandler.handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common/http.HttpHandler
的用法示例。
在下文中一共展示了HttpHandler.handle方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const body = req.body;
if (!body || !body.name ) {
return next.handle(req);
}
// copy the body and trim whitespace from the name property
const newBody = { ...body, name: body.name.trim() };
// clone request and set its body
const newReq = req.clone({ body: newBody });
// send the cloned request to the next handler.
return next.handle(newReq);
}
示例2: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.headers.get('planner-req')) {
const headers = new HttpHeaders({
'Authorization' : `Bearer ${this.auth.getToken()}`,
'Content-Type': `application/json`
});
const authreq = req.clone({
headers: headers
});
return next.handle(authreq);
}
return next.handle(req);
}
示例3: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<any> {
const token = this.tokenService.getToken();
if (token) {
console.log('token: ' + token);
const authReq = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + token) });
console.log('Authorization header: ' + authReq.headers.get('Authorization'));
return next.handle(authReq);
}
return next.handle(req);
}
示例4: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let authRequest: any;
if (this.shared.isLoggedIn()) {
authRequest = req.clone({
setHeaders: {
'Authorization': this.shared.token
}
});
return next.handle(authRequest);
} else {
return next.handle(req);
}
}
示例5: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (this.authService.isLoggedIn) {
req = req.clone({
setHeaders: {
'Authorization': `Bearer ${this.authService.token}`
}
});
return next.handle(req);
}
return next.handle(req);
}
示例6: intercept
intercept(req: HttpRequest<any>,
next: HttpHandler): Observable<HttpEvent<any>> {
//debugger;
const token = localStorage.getItem('token');
if (token && !req.url.includes('maps.googleapis.com')) {
const cloned = req.clone({
headers: req.headers.set('jwt-token', token)
});
return next.handle(cloned);
}
else {
return next.handle(req);
}
}
示例7: intercept
/**
* adds a header with a token
*
*
* @param {HttpRequest<any>} request
* @param {HttpHandler} next
* @returns {Observable<HttpEvent<any>>}
*/
intercept(request: HttpRequest<any>, next: HttpHandler) {
const token = this.auth.getToken();
if(token){
const authReq = request.clone({
headers: request.headers.set('x-auth',token)
});
return next.handle(authReq);
}else{
return next.handle(request);
}
}
示例8: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if(request.method == 'GET') {
return next.handle(request)
} else {
// Add CSRF headers for non GET requests
const newHeaders: {[name: string]: string | string[]; } = {};
for (const key of request.headers.keys()) {
newHeaders[key] = request.headers.getAll(key);
}
newHeaders['x-xsrf-token'] = OrcidCookie.getCookie('XSRF-TOKEN');
let _request = request.clone({headers: new HttpHeaders(newHeaders)});
return next.handle(_request);
}
}
示例9: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!request || !request.url || (/^http/.test(request.url) && !(SERVER_API_URL && request.url.startsWith(SERVER_API_URL)))) {
return next.handle(request);
}
const token = this.localStorage.retrieve('authenticationToken') || this.sessionStorage.retrieve('authenticationToken');
if (!!token) {
request = request.clone({
setHeaders: {
Authorization: 'Bearer ' + token
}
});
}
return next.handle(request);
}
示例10: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.url.startsWith(environment.api)) {
const token = this.oidcSecurityService.getToken();
if (token !== '') {
const tokenValue = 'Bearer ' + token;
return next.handle(req.clone({
setHeaders: {
'Authorization': tokenValue
}
}));
}
}
return next.handle(req);
}