Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/node/src/transports/base/http-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import http, { IncomingHttpHeaders } from 'http';
import https from 'https';
import { URL } from 'url';

export type HTTPModuleRequestOptions = http.RequestOptions | https.RequestOptions | string | URL;

/**
* Cut version of http.IncomingMessage.
* Some transports work in a special Javascript environment where http.IncomingMessage is not available.
*/
export interface HTTPModuleRequestIncomingMessage {
headers: IncomingHttpHeaders;
statusCode?: number;
on(event: 'data' | 'end', listener: () => void): void;
setEncoding(encoding: string): void;
}

/**
* Cut version of http.ClientRequest.
* Some transports work in a special Javascript environment where http.IncomingMessage is not available.
*/
export interface HTTPModuleClientRequest {
end(chunk: string): void;
on(event: 'error', listener: () => void): void;
}

/**
* Internal used interface for typescript.
* @hidden
*/
export interface HTTPModule {
/**
* Request wrapper
* @param options These are {@see TransportOptions}
* @param callback Callback when request is finished
*/
request(
options: HTTPModuleRequestOptions,
callback?: (res: HTTPModuleRequestIncomingMessage) => void,
): HTTPModuleClientRequest;

// This is the type for nodejs versions that handle the URL argument
// (v10.9.0+), but we do not use it just yet because we support older node
// versions:

// request(
// url: string | URL,
// options: http.RequestOptions | https.RequestOptions,
// callback?: (res: http.IncomingMessage) => void,
// ): http.ClientRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,8 @@ import * as http from 'http';
import * as https from 'https';
import { URL } from 'url';

import { SDK_NAME } from '../version';

/**
* Internal used interface for typescript.
* @hidden
*/
export interface HTTPModule {
/**
* Request wrapper
* @param options These are {@see TransportOptions}
* @param callback Callback when request is finished
*/
request(
options: http.RequestOptions | https.RequestOptions | string | URL,
callback?: (res: http.IncomingMessage) => void,
): http.ClientRequest;

// This is the type for nodejs versions that handle the URL argument
// (v10.9.0+), but we do not use it just yet because we support older node
// versions:

// request(
// url: string | URL,
// options: http.RequestOptions | https.RequestOptions,
// callback?: (res: http.IncomingMessage) => void,
// ): http.ClientRequest;
}
import { SDK_NAME } from '../../version';
import { HTTPModule } from './http-module';

export type URLParts = Pick<URL, 'hostname' | 'pathname' | 'port' | 'protocol'>;
export type UrlParser = (url: string) => URLParts;
Expand Down Expand Up @@ -231,7 +206,7 @@ export abstract class BaseTransport implements Transport {
throw new SentryError('No module available');
}
const options = this._getRequestOptions(this.urlParser(sentryReq.url));
const req = this.module.request(options, (res: http.IncomingMessage) => {
const req = this.module.request(options, res => {
const statusCode = res.statusCode || 500;
const status = Status.fromHttpCode(statusCode);

Expand Down