mirror of
https://github.com/bitwarden/browser
synced 2026-01-07 02:53:28 +00:00
native fetch with proxy support on node api
This commit is contained in:
@@ -897,6 +897,10 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
request.headers.set('Cache-Control', 'no-cache');
|
||||
request.headers.set('Pragma', 'no-cache');
|
||||
}
|
||||
return this.nativeFetch(request);
|
||||
}
|
||||
|
||||
nativeFetch(request: Request): Promise<Response> {
|
||||
return fetch(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export class AuditService implements AuditServiceAbstraction {
|
||||
const hashStart = hash.substr(0, 5);
|
||||
const hashEnding = hash.substr(5);
|
||||
|
||||
const response = await fetch(PwnedPasswordsApi + hashStart);
|
||||
const response = await this.apiService.nativeFetch(new Request(PwnedPasswordsApi + hashStart));
|
||||
const leakedHashes = await response.text();
|
||||
const match = leakedHashes.split(/\r?\n/).find((v) => {
|
||||
return v.split(':')[0] === hashEnding;
|
||||
|
||||
@@ -794,7 +794,8 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
|
||||
private async shareAttachmentWithServer(attachmentView: AttachmentView, cipherId: string,
|
||||
organizationId: string): Promise<any> {
|
||||
const attachmentResponse = await fetch(new Request(attachmentView.url, { cache: 'no-cache' }));
|
||||
const attachmentResponse = await this.apiService.nativeFetch(
|
||||
new Request(attachmentView.url, { cache: 'no-cache' }));
|
||||
if (attachmentResponse.status !== 200) {
|
||||
throw Error('Failed to download attachment: ' + attachmentResponse.status.toString());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as FormData from 'form-data';
|
||||
import * as HttpsProxyAgent from 'https-proxy-agent';
|
||||
import * as fe from 'node-fetch';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
@@ -17,4 +18,12 @@ export class NodeApiService extends ApiService {
|
||||
logoutCallback: (expired: boolean) => Promise<void>) {
|
||||
super(tokenService, platformUtilsService, logoutCallback);
|
||||
}
|
||||
|
||||
nativeFetch(request: Request): Promise<Response> {
|
||||
const proxy = process.env.http_proxy || process.env.https_proxy;
|
||||
if (proxy) {
|
||||
(request as any).agent = new HttpsProxyAgent(proxy);
|
||||
}
|
||||
return fetch(request);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user