Skip to content

Commit

Permalink
fix how we ingest uuid;
Browse files Browse the repository at this point in the history
  • Loading branch information
sofisl committed Feb 15, 2025
1 parent b152c95 commit 887b16d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type * as f from 'node-fetch' with {'resolution-mode': 'import'};
import {PassThrough, Readable, pipeline} from 'stream';
import {getAgent} from './agents';
import {TeenyStatistics} from './TeenyStatistics';
import {randomUUID} from 'crypto';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const streamEvents = require('stream-events');

Expand Down Expand Up @@ -202,7 +203,7 @@ function teenyRequest(reqOpts: Options): Request;
function teenyRequest(reqOpts: Options, callback: RequestCallback): void;
function teenyRequest(
reqOpts: Options,
callback?: RequestCallback
callback?: RequestCallback,
): Request | void {
const {uri, options} = requestToFetchOptions(reqOpts);

Expand All @@ -212,7 +213,7 @@ function teenyRequest(
// TODO: add support for multipart uploads through streaming
throw new Error('Multipart without callback is not implemented.');
}
const boundary: string = globalThis.crypto?.randomUUID();
const boundary: string = randomUUID();
(options.headers as Headers)['Content-Type'] =
`multipart/related; boundary=${boundary}`;
options.body = createMultipartStream(boundary, multipart);
Expand All @@ -236,7 +237,7 @@ function teenyRequest(
},
(err: Error) => {
callback(err, response, body);
}
},
);
return;
}
Expand All @@ -248,13 +249,13 @@ function teenyRequest(
},
err => {
callback(err, response, body);
}
},
);
},
err => {
teenyRequest.stats.requestFinished();
callback(err, null!, null);
}
},
);
return;
}
Expand Down Expand Up @@ -291,7 +292,7 @@ function teenyRequest(
err => {
teenyRequest.stats.requestFinished();
requestStream.emit('error', err);
}
},
);

// fetch doesn't supply the raw HTTP stream, instead it
Expand Down Expand Up @@ -324,7 +325,7 @@ function teenyRequest(
},
err => {
callback(err, response, body);
}
},
);
return;
}
Expand All @@ -337,13 +338,13 @@ function teenyRequest(
},
err => {
callback(err, response, body);
}
},
);
},
err => {
teenyRequest.stats.requestFinished();
callback(err, null!, null);
}
},
);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ describe('teeny', () => {
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(body, '🌍');
scope.done();
}
},
);
});

Expand All @@ -375,7 +375,7 @@ describe('teeny', () => {
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(body, '🌍');
scope.done();
}
},
);
});

Expand Down Expand Up @@ -406,7 +406,7 @@ describe('teeny', () => {
assert.ok(statsStub.requestFinished.calledOnceWithExactly());
scope.done();
done();
}
},
);
});

Expand All @@ -424,7 +424,7 @@ describe('teeny', () => {
assert.ok(statsStub.requestStarting.calledOnceWithExactly());
assert.ok(statsStub.requestFinished.calledOnceWithExactly());
scope.done();
}
},
);
});

Expand All @@ -434,7 +434,7 @@ describe('teeny', () => {
teenyRequest({uri: ''});
},
/Missing uri or url in reqOpts/,
'Did not throw with expected message'
'Did not throw with expected message',
);
});

Expand All @@ -444,7 +444,7 @@ describe('teeny', () => {
teenyRequest({url: ''});
},
/Missing uri or url in reqOpts/,
'Did not throw with expected message'
'Did not throw with expected message',
);
});
});

0 comments on commit 887b16d

Please sign in to comment.