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

fix: duplex only has a getter #149

Merged
merged 1 commit into from
Feb 27, 2024
Merged

fix: duplex only has a getter #149

merged 1 commit into from
Feb 27, 2024

Conversation

wenerme
Copy link
Contributor

@wenerme wenerme commented Feb 24, 2024

No description provided.

@usualoma
Copy link
Member

Hi @wenerme

Thanks for creating the PR! I see what you mean, that is indeed true.

I would like to make some simpler changes to the content, preferably something like the following. Would it be possible to change the content of your PR that way?

diff --git a/src/request.ts b/src/request.ts
index 94201a7..563fde8 100644
--- a/src/request.ts
+++ b/src/request.ts
@@ -13,7 +13,8 @@ export class Request extends GlobalRequest {
     }
     if (options?.body instanceof ReadableStream) {
       // node 18 fetch needs half duplex mode when request body is stream
-      ;(options as any).duplex = 'half'
+      // if already set, do nothing since a Request object was passed to the options or explicitly set by the user.
+      ;(options as any).duplex ??= 'half'
     }
     super(input, options)
   }
diff --git a/test/request.test.ts b/test/request.test.ts
index 004b6a1..b66cba3 100644
--- a/test/request.test.ts
+++ b/test/request.test.ts
@@ -112,5 +112,21 @@ describe('Request', () => {
       expect(req2).toBeInstanceOf(GlobalRequest)
       expect(req2.text()).resolves.toBe('bar')
     })
+
+    it('should skip to set `duplex: "half"` if init option is a Request object', async () => {
+      const stream = new ReadableStream({
+        start(controller) {
+          controller.enqueue(new TextEncoder().encode('bar'))
+          controller.close()
+        },
+      })
+      const req = new Request('http://localhost', {
+        method: 'POST',
+        body: stream,
+      })
+      const req2 = new Request('http://localhost/subapp', req)
+      expect(req2).toBeInstanceOf(GlobalRequest)
+      expect(req2.text()).resolves.toBe('bar')
+    })
   })
 })

@wenerme
Copy link
Contributor Author

wenerme commented Feb 25, 2024

Ok with this, reset the patch.

@alexiglesias93
Copy link

I was just about to open a PR for this, thank you @wenerme! For now I've applied a local patch with these changes and it solved our issues. Looking forward to this PR being merged 🙏

@usualoma
Copy link
Member

@wenerme Thank you! Looks good to me 👍

@yusukebe
Copy link
Member

@wenerme @usualoma

Thanks! Looks good. Merging now.

@yusukebe yusukebe merged commit 6d5f527 into honojs:main Feb 27, 2024
3 checks passed
nicolewhite pushed a commit to autoblocksai/cli that referenced this pull request Mar 20, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@hono/node-server](https://github.com/honojs/node-server) |
[`1.7.0` ->
`1.8.2`](https://renovatebot.com/diffs/npm/@hono%2fnode-server/1.7.0/1.8.2)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@hono%2fnode-server/1.8.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@hono%2fnode-server/1.8.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@hono%2fnode-server/1.7.0/1.8.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@hono%2fnode-server/1.7.0/1.8.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>honojs/node-server (@&#8203;hono/node-server)</summary>

###
[`v1.8.2`](https://github.com/honojs/node-server/releases/tag/v1.8.2)

[Compare
Source](https://github.com/honojs/node-server/compare/v1.8.1...v1.8.2)

#### What's Changed

- fix: duplex only has a getter by
[@&#8203;wenerme](https://github.com/wenerme) in
[honojs/node-server#149

#### New Contributors

- [@&#8203;wenerme](https://github.com/wenerme) made their first
contribution in
[honojs/node-server#149

**Full Changelog**:
honojs/node-server@v1.8.1...v1.8.2

###
[`v1.8.1`](https://github.com/honojs/node-server/releases/tag/v1.8.1)

[Compare
Source](https://github.com/honojs/node-server/compare/v1.8.0...v1.8.1)

This release includes a `feat` change, but it's minor, so release this
as a patch-release.

#### What's Changed

- feat: support keepalive property for Request object by
[@&#8203;usualoma](https://github.com/usualoma) in
[honojs/node-server#148

**Full Changelog**:
honojs/node-server@v1.8.0...v1.8.1

###
[`v1.8.0`](https://github.com/honojs/node-server/releases/tag/v1.8.0)

[Compare
Source](https://github.com/honojs/node-server/compare/v1.7.0...v1.8.0)

#### What's Changed

- feat: bump hono to v3.12.8, add customer err tests for compress middl…
by [@&#8203;ariskemper](https://github.com/ariskemper) in
[honojs/node-server#130
- refactor(test): replace features to be removed in v4 by
[@&#8203;ryuapp](https://github.com/ryuapp) in
[honojs/node-server#136
- Catch when nodejs request is aborted by
[@&#8203;M4RC3L05](https://github.com/M4RC3L05) in
[honojs/node-server#141
- chore: bump hono to v4 by
[@&#8203;yusukebe](https://github.com/yusukebe) in
[honojs/node-server#143
- feat: use internal body if available for returning the response in its
original form as much as possible by
[@&#8203;usualoma](https://github.com/usualoma) in
[honojs/node-server#145

#### New Contributors

- [@&#8203;ariskemper](https://github.com/ariskemper) made their first
contribution in
[honojs/node-server#130
- [@&#8203;ryuapp](https://github.com/ryuapp) made their first
contribution in
[honojs/node-server#136
- [@&#8203;M4RC3L05](https://github.com/M4RC3L05) made their first
contribution in
[honojs/node-server#141

**Full Changelog**:
honojs/node-server@v1.7.0...v1.8.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone
America/Chicago, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/autoblocksai/cli).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNDUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI0NS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants