Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from probot:master #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
116c721
chore(deps): update dependency @octokit/tsconfig to v3 (#289)
renovate[bot] Feb 17, 2024
2091507
build(deps-dev): bump vite from 5.0.12 to 5.2.8 (#294)
dependabot[bot] May 1, 2024
c824a13
chore(deps): update vitest monorepo to v2 (major) (#298)
renovate[bot] Jul 8, 2024
2c386bc
fix: add proper `Content-Type` header to fix incorrect JSON formattin…
dasundev Jul 22, 2024
a4277b1
ci: Test on Node 22 (#296)
AaronDewes Jul 22, 2024
62ea3bb
build(deps): lock file maintenance (#288)
renovate[bot] Jul 22, 2024
d8aee60
build(deps): lock file maintenance (#301)
renovate[bot] Jul 30, 2024
9f49ea7
build(deps): lock file maintenance (#302)
renovate[bot] Aug 6, 2024
e1df3f7
build(deps): lock file maintenance (#303)
renovate[bot] Aug 13, 2024
50bb037
fix: delete the `Host` eader (#300)
wolfy1339 Aug 15, 2024
7f31743
build(deps): lock file maintenance (#305)
renovate[bot] Aug 20, 2024
e0b6f51
build(deps): lock file maintenance (#308)
renovate[bot] Aug 27, 2024
b24fe99
build(deps): lock file maintenance (#309)
renovate[bot] Sep 3, 2024
7c73c5b
build(deps): lock file maintenance (#310)
renovate[bot] Sep 10, 2024
2c6dee2
build(deps): lock file maintenance (#311)
renovate[bot] Sep 17, 2024
de556c9
build(deps): lock file maintenance (#314)
renovate[bot] Sep 24, 2024
d2d72cb
chore(deps): update dependency fastify to v5 (#312)
renovate[bot] Sep 24, 2024
917468c
build(deps): lock file maintenance (#322)
renovate[bot] Oct 1, 2024
cc2cf2f
build(deps): lock file maintenance (#323)
renovate[bot] Oct 8, 2024
85c8747
build(deps): lock file maintenance (#326)
renovate[bot] Oct 15, 2024
ac6d677
fix: add proxy support for `EventSource` (#317)
wolfy1339 Oct 17, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
- 18
- 20
- 21
- 22
os:
- ubuntu-latest
- macos-latest
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,32 @@ const events = smee.start()
// Stop forwarding events
events.close()
```

#### Proxy

By default, the Smee client does not make use of the standard proxy server environment variables. To add support for proxy servers you will need to provide an https client that supports them such as [`undici.EnvHttpProxyAgent()`](https://undici.nodejs.org/#/docs/api/EnvHttpProxyAgent).

Afterwards, you will be able to use the standard proxy server environment variables.

For example, this would use a `EnvHttpProxyAgent` to make requests through a proxy server:

```js
const { EnvHttpProxyAgent, fetch: undiciFetch } = require("undici");
const SmeeClient = require('smee-client');

const myFetch = (url, options) => {
return undiciFetch(url, {
...options,
dispatcher: new EnvHTTPProxyAgent()
})
};

const smee = new SmeeClient({
source: 'https://smee.io/abc123',
target: 'http://localhost:3000/events',
logger: console,
fetch: myFetch
});

const events = smee.start();
```
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ class Client {
headers[key] = data[key];
});

// Don't forward the host header. As it causes issues with some servers
// See https://github.com/probot/smee-client/issues/295
// See https://github.com/probot/smee-client/issues/187
delete headers["host"];
headers["content-length"] = Buffer.byteLength(body);
headers["content-type"] = "application/json";
Comment on lines +68 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace delete with undefined assignment for better performance.

Using the delete operator can impact performance. Consider setting the header to undefined instead.

-    delete headers["host"];
+    headers["host"] = undefined;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Don't forward the host header. As it causes issues with some servers
// See https://github.com/probot/smee-client/issues/295
// See https://github.com/probot/smee-client/issues/187
delete headers["host"];
headers["content-length"] = Buffer.byteLength(body);
headers["content-type"] = "application/json";
// Don't forward the host header. As it causes issues with some servers
// See https://github.com/probot/smee-client/issues/295
// See https://github.com/probot/smee-client/issues/187
headers["host"] = undefined;
headers["content-length"] = Buffer.byteLength(body);
headers["content-type"] = "application/json";
Tools
Biome

[error] 71-71: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


try {
const response = await this.fetch(url.format(target), {
Expand All @@ -90,7 +95,9 @@ class Client {
}

start() {
const events = new EventSource(this.source);
const events = new EventSource(this.source, {
proxy: process.env.HTTP_PROXY || process.env.HTTPS_PROXY,
});

// Reconnect immediately
(events as any).reconnectInterval = 0; // This isn't a valid property of EventSource
Expand Down
Loading