当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript HttpHandler.handle方法代码示例

本文整理汇总了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);
 }
开发者ID:iproduct,项目名称:course-angular,代码行数:12,代码来源:trim-name-interceptor.ts

示例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);
 }
开发者ID:joshuawilson,项目名称:almighty-ui,代码行数:13,代码来源:auth.interceptors.ts

示例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);
    }
开发者ID:ngocdiep,项目名称:nd,代码行数:13,代码来源:default.interceptor.ts

示例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);
        }
    }
开发者ID:alexalvesdesouza,项目名称:front_end_projects,代码行数:14,代码来源:auth.interceptor.ts

示例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);
  }
开发者ID:antonsimonov03,项目名称:AutobyOffer_Landing_Page,代码行数:14,代码来源:token.interceptor.ts

示例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);
     }
 }
开发者ID:softcoder,项目名称:riprunner,代码行数:14,代码来源:auth-interceptor.ts

示例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);

    }

  }
开发者ID:FranklinParker,项目名称:Angular6NodeWithMongoAuthStarter,代码行数:23,代码来源:token.interceptor.ts

示例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);
       }            
   }
开发者ID:ORCID,项目名称:ORCID-Source,代码行数:15,代码来源:ng2_app.ts

示例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);
    }
开发者ID:EugeneGoroschenya,项目名称:jhipster-sample-application,代码行数:15,代码来源:auth.interceptor.ts

示例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);
  }
开发者ID:AtlasOfLivingAustralia,项目名称:seasonal-calendar,代码行数:15,代码来源:token-interceptor.ts


注:本文中的@angular/common/http.HttpHandler.handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。