本文整理汇总了TypeScript中@angular/common/http/src/request.HttpRequest.clone方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpRequest.clone方法的具体用法?TypeScript HttpRequest.clone怎么用?TypeScript HttpRequest.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common/http/src/request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('serializes parameters as urlencoded', () => {
const params = new HttpParams().append('first', 'value').append('second', 'other');
const withParams = baseReq.clone({body: params});
expect(withParams.serializeBody()).toEqual('first=value&second=other');
expect(withParams.detectContentTypeHeader())
.toEqual('application/x-www-form-urlencoded;charset=UTF-8');
});
示例2: it
it('handles a blank json response', () => {
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
factory.mock.mockFlush(200, 'OK', '');
expect(events.length).toBe(2);
const res = events[1] as HttpResponse<{data: string}>;
expect(res.body).toBeNull();
});
示例3: intercept
intercept(req: HttpRequest<any>, delegate: HttpHandler): Observable<HttpEvent<any>> {
const existing = req.headers.get('Intercepted');
const next = !!existing ? existing + ',' + this.value : this.value;
req = req.clone({setHeaders: {'Intercepted': next}});
return delegate.handle(req).pipe(map(event => {
if (event instanceof HttpResponse) {
const existing = event.headers.get('Intercepted');
const next = !!existing ? existing + ',' + this.value : this.value;
return event.clone({headers: event.headers.set('Intercepted', next)});
}
return event;
}));
}