robobun
2e8e7a000c
Fix WebSocket to emit error event before close on handshake failure ( #22325 )
...
## Summary
This PR fixes WebSocket to correctly emit an `error` event before the
`close` event when the handshake fails (e.g., 302 redirects, non-101
status codes, missing headers).
Fixes #14338
## Problem
Previously, when a WebSocket connection failed during handshake (like
receiving a 302 redirect or connecting to a non-WebSocket server), Bun
would only emit a `close` event. This behavior differed from the WHATWG
WebSocket specification and other runtimes (browsers, Node.js with `ws`,
Deno) which emit both `error` and `close` events.
## Solution
Modified `WebSocket::didFailWithErrorCode()` in `WebSocket.cpp` to pass
`isConnectionError = true` for all handshake failure error codes,
ensuring an error event is dispatched before the close event when the
connection is in the CONNECTING state.
## Changes
- Updated error handling in `src/bun.js/bindings/webcore/WebSocket.cpp`
to emit error events for handshake failures
- Added comprehensive test coverage in
`test/regression/issue/14338.test.ts`
## Test Coverage
The test file includes:
1. **Negative test**: 302 redirect response - verifies error event is
emitted
2. **Negative test**: Non-WebSocket HTTP server - verifies error event
is emitted
3. **Positive test**: Successful WebSocket connection - verifies NO
error event is emitted
All tests pass with the fix applied.
🤖 Generated with [Claude Code](https://claude.ai/code )
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh >
Co-authored-by: Claude <noreply@anthropic.com >
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com >
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-09-02 03:26:51 -07:00
Jarred Sumner
7b31393d44
Don't run the "Date" header timer every second all the time ( #21850 )
...
### What does this PR do?
Only reschedule the Date header while there are in-flight incoming HTTP
requests.
Update the Date header if, at the time we reschedule it, it is now
stale.
Goal: don't wake up Bun's process on every second when we're idly doing
nothing.
| Metric | this branch | main |
|--------|--------------------------|-------------------|
| **task-clock** | **35.24 msec** 🟢 | **102.79 msec** |
| **context-switches** | 619 🟢 | 1,699 |
| **cpu-migrations** | 11 🟢 | 35 |
| **page-faults** | 2,173 | 2,174 |
| **cpu_atom/instructions** | **109,904,685 (1.76 insn/cycle)** 🟢 |
**67,880,002 (0.55 insn/cycle)** |
| **cpu_core/instructions** | **87,183,124 (1.07 insn/cycle)** 🟢 |
**32,939,500 (0.44 insn/cycle)** |
| **cpu_atom/cycles** | 62,527,125 (1.774 GHz) 🔻 | 122,448,620 (1.191
GHz) |
| **cpu_core/cycles** | 81,651,366 (2.317 GHz) 🟢 | 75,584,111 (0.735
GHz) |
| **cpu_atom/branches** | 9,632,460 (273.338 M/sec) 🔻 | 12,119,616
(117.909 M/sec) |
| **cpu_core/branches** | 17,417,756 (494.259 M/sec) 🟢 | 6,901,859
(67.147 M/sec) |
| **cpu_atom/branch-misses** | 192,013 (1.99%) 🟢 | 1,735,446 (14.32%) |
| **cpu_core/branch-misses** | 473,567 (2.72%) 🟢 | 499,907 (7.24%) |
| **TopdownL1 (cpu_core)** | 31.4% backend_bound<br>11.7%
bad_speculation<br>36.0% frontend_bound 🔻 <br>20.9% retiring<br>34.1%
bad_speculation<br>41.9% retiring<br>0.0% backend_bound<br>24.0%
frontend_bound 🔻 | 21.3% backend_bound<br>9.6% bad_speculation<br>56.2%
frontend_bound<br>12.9% retiring<br>-20.0% bad_speculation<br>55.2%
retiring<br>26.2% backend_bound<br>38.6% frontend_bound |
| **time elapsed** | 1000.0219 s | 1000.0107 s |
| **user time** | — | 0.042667 s |
| **sys time** | — | 0.060309 s |
### How did you verify your code works?
Added a test
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-14 15:39:09 -07:00
Jarred Sumner
b0799da968
Harden Transfer-Encoding ( #21737 )
...
### What does this PR do?
### How did you verify your code works?
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-10 03:52:40 -07:00
Jarred Sumner
93f92658b3
Try mimalloc v3 ( #17378 )
...
(For internal tracking: fixes ENG-19852)
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Kai Tamkun <kai@tamkun.io >
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: taylor.fish <contact@taylor.fish >
2025-07-29 18:07:15 -07:00
robobun
220807f3dc
Add If-None-Match support to StaticRoute with automatic ETag generation ( #21424 )
...
## Summary
Fixes https://github.com/oven-sh/bun/issues/19198
This implements RFC 9110 Section 13.1.2 If-None-Match conditional
request support for static routes in Bun.serve().
**Key Features:**
- Automatic ETag generation for static content based on content hash
- If-None-Match header evaluation with weak entity tag comparison
- 304 Not Modified responses for cache efficiency
- Standards-compliant handling of wildcards (*), multiple ETags, and
weak ETags (W/)
- Method-specific application (GET/HEAD only) with proper 405 responses
for other methods
## Implementation Details
- ETags are generated using `bun.hash()` and formatted as strong ETags
(e.g., "abc123")
- Preserves existing ETag headers from Response objects
- Uses weak comparison semantics as defined in RFC 9110 Section 8.8.3.2
- Handles comma-separated ETag lists and malformed headers gracefully
- Only applies to GET/HEAD requests with 200 status codes
## Files Changed
- `src/bun.js/api/server/StaticRoute.zig` - Core implementation (~100
lines)
- `test/js/bun/http/serve-if-none-match.test.ts` - Comprehensive test
suite (17 tests)
## Test Results
- ✅ All 17 new If-None-Match tests pass
- ✅ All 34 existing static route tests pass (no regressions)
- ✅ Debug build compiles successfully
## Test plan
- [ ] Run existing HTTP server tests to ensure no regressions
- [ ] Test ETag generation for various content types
- [ ] Verify 304 responses reduce bandwidth in real scenarios
- [ ] Test edge cases like malformed If-None-Match headers
🤖 Generated with [Claude Code](https://claude.ai/code )
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh >
Co-authored-by: Claude <noreply@anthropic.com >
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-28 16:22:21 -07:00
Jarred Sumner
2e02d9de28
Use ReadableStream.prototype.* in tests instead of new Response(...).* ( #20937 )
...
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Alistair Smith <hi@alistair.sh >
Co-authored-by: Claude Bot <claude-bot@bun.sh >
Co-authored-by: Claude <noreply@anthropic.com >
2025-07-14 00:47:53 -07:00
Jarred Sumner
d6d7251352
Fixes #14988 ( #20928 )
...
Co-authored-by: Claude Bot <claude-bot@bun.sh >
Co-authored-by: Claude <noreply@anthropic.com >
2025-07-12 18:22:54 -07:00
Jarred Sumner
55a9cccac0
bun.sh -> bun.com ( #20909 )
2025-07-10 00:10:43 -07:00
190n
172aecb02e
[publish images] Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 (v2) ( #20772 )
...
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com >
Co-authored-by: Claude <noreply@anthropic.com >
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Meghan Denny <meghan@bun.sh >
Co-authored-by: Ashcon Partovi <ashcon@partovi.net >
Co-authored-by: pfg <pfg@pfg.pw >
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com >
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com >
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
2025-07-02 12:06:08 -07:00
Ben Grant
ea57037567
Revert "Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 ( #20659 ) [publish images]"
...
This reverts commit 80309e4d59 . It breaks the Windows CI.
2025-07-02 09:40:32 -07:00
Jarred Sumner
80309e4d59
Upgrade self-reported Node.js version from 22.6.0 to 24.3.0 ( #20659 ) [publish images]
...
Co-authored-by: Claude <noreply@anthropic.com >
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Meghan Denny <meghan@bun.sh >
Co-authored-by: Ashcon Partovi <ashcon@partovi.net >
Co-authored-by: pfg <pfg@pfg.pw >
Co-authored-by: pfgithub <6010774+pfgithub@users.noreply.github.com >
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com >
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Ben Grant <ben@bun.sh >
2025-07-02 00:03:05 -07:00
Jarred Sumner
633f4f593d
Ahead-of-time frontend bundling support for HTML imports & bun build ( #20511 )
...
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com >
2025-06-20 19:55:52 -07:00
Ciro Spaciari
631e674842
fix(FileRoute) fix eof handling, fix max size handling, fix onReaderError behavior ( #20317 )
...
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: cirospaciari <6379399+cirospaciari@users.noreply.github.com >
2025-06-11 20:34:52 -07:00
Jarred Sumner
8750f0b884
Add FileRoute for serving files ( #20198 )
...
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com >
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com >
2025-06-10 19:41:21 -07:00
190n
ea05de59b3
Fix #20283 ( #20287 )
2025-06-09 16:50:24 -07:00
Jarred Sumner
c9761d4aa6
Fixes flaky test-http-pipeline-requests-connection-leak.js ( #20248 )
2025-06-07 05:19:11 -07:00
Jarred Sumner
9bee7a64a2
Support method-specific routes for html & static routes ( #19710 )
2025-05-17 00:28:01 -07:00
Jarred Sumner
14b439a115
Fix formatters not running in CI + delete unnecessary files ( #19433 )
2025-05-08 23:22:16 -07:00
Meghan Denny
ec6cb8283e
bun.serve: use getBooleanStrict for tls.requestCert and tls.rejectUnauthorized ( #19293 )
2025-04-28 03:43:49 -07:00
Jarred Sumner
27a580a4d5
Fix test using afterAll inside of a test
2025-04-14 17:25:17 -07:00
Ciro Spaciari
575d2c40a8
fix(server) Fix empty stream response ( #18707 )
2025-04-01 19:08:04 -07:00
pfg
1d655a0232
cookie mistakes ( #18513 )
2025-03-26 20:51:20 -07:00
Jarred Sumner
49ca2c86e7
More robust Bun.Cookie & Bun.CookieMap ( #18359 )
...
Co-authored-by: pfg <pfg@pfg.pw >
2025-03-26 02:51:41 -07:00
Kai Tamkun
60acfb17f0
node:http compatibility (options.lookup) (#18395 )
...
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com >
2025-03-24 23:49:02 -07:00
pfg
8df7064f73
Don't crash when server.fetch() is called on a server without a fetch() handler ( #18151 )
...
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com >
2025-03-24 16:55:34 -07:00
Jarred Sumner
60ae19bded
Revert "Introduce Bun.Cookie & Bun.CookieMap & request.cookies (in BunRequest) ( #18073 )"
...
This reverts commit 9888570456 .
We will add it in Bun v1.2.7
2025-03-21 22:17:28 -07:00
Jarred Sumner
9888570456
Introduce Bun.Cookie & Bun.CookieMap & request.cookies (in BunRequest) ( #18073 )
...
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
Co-authored-by: pfg <pfg@pfg.pw >
2025-03-20 21:29:00 -07:00
pfg
74768449bc
disallow test() within test() ( #18203 )
2025-03-15 21:34:35 -07:00
pfg
d7a047a533
Fix #18131 (global catch-all route does not work with callback handler) ( #18148 )
2025-03-12 21:39:31 -07:00
Ciro Spaciari
01fb872095
fix(serve) fix WS upgrade with routes ( #17805 )
2025-02-28 19:25:55 -08:00
chloe caruso
e7790894d9
elaborate on error "Expected Sink" ( #15234 )
...
Co-authored-by: paperdave <paperdave@users.noreply.github.com >
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com >
2025-02-27 17:08:00 -08:00
Ciro Spaciari
f4937678e4
fix(node:http/Bun.serve) Allow Strict-Transport-Security in http ( #17768 )
2025-02-27 11:27:07 -08:00
Don Isaac
61edc58362
feat(node/net): add SocketAddress ( #17154 )
...
Co-authored-by: DonIsaac <22823424+DonIsaac@users.noreply.github.com >
2025-02-24 11:18:16 -08:00
chloe caruso
3b956757d9
disable async in script tags in dev server ( #17517 )
...
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com >
2025-02-21 11:28:27 -08:00
Jarred Sumner
a3ea521c98
Fix mime type for assets in HTML routes ( #17513 )
...
Co-authored-by: chloe caruso <git@paperclover.net >
2025-02-20 22:30:48 -08:00
Jarred Sumner
527412626a
Make fetch() optional in Bun.serve() when routes are passed ( #17401 )
...
Co-authored-by: Pham Minh Triet <92496972+Nanome203@users.noreply.github.com >
2025-02-17 03:25:07 -08:00
Jarred Sumner
f29e912a91
Add routes to Bun.serve() ( #17357 )
2025-02-16 00:42:05 -08:00
chloe caruso
0b6aa96672
Chloe/hmr4 ( #17353 )
...
Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com >
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com >
2025-02-15 05:45:02 -08:00
Jarred Sumner
b4f34b03d6
Fix disabling HMR, add way to do /api/* and /* in static ( #17333 )
2025-02-14 07:43:21 -08:00
Jarred Sumner
a23c11e381
Support BUN_PUBLIC_* and other env options in HTML imports ( #17227 )
...
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com >
2025-02-10 02:09:48 -08:00
Jarred Sumner
ba8573494a
Add shadcn, tailwind and react detection & templates to bun create. Also: bun install --analyze <files...> ( #17035 )
2025-02-09 09:36:57 -08:00
chloe caruso
f912e0abc4
hot module reloading for HTML import development mode ( #16955 )
2025-02-08 00:31:30 -08:00
Jarred Sumner
7a918d24a7
Fix loading react-jsxdev instead of react-jsx ( #17013 )
...
Co-authored-by: chloe caruso <git@paperclover.net >
2025-02-03 14:10:09 -08:00
Jarred Sumner
1ea14f483c
Introduce bun ./index.html ( #16993 )
2025-02-03 04:06:12 -08:00
Zack Radisic
f6ec0da125
Various CSS fixing and stability stuff ( #16889 )
2025-01-31 03:47:49 -08:00
Jarred Sumner
cd53d32ccf
Fix memory leak in certain cases when long URLs are passed to req.url ( #16787 )
2025-01-26 23:16:35 -08:00
Jarred Sumner
75a95aa5fa
Rewrite the internal Web Stream native bindings to use less memory ( #16349 )
2025-01-26 00:04:39 -08:00
Meghan Denny
af79cebf9e
unflag experimental css and html ( #16561 )
...
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com >
Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com >
2025-01-21 06:44:54 -08:00
Zack Radisic
703b9962c7
CSS tests and bundler plugins in serve ( #16558 )
2025-01-21 01:16:48 -08:00
Zack Radisic
87dedd109a
CSS bundling & general fixes ( #16486 )
2025-01-18 13:26:27 -08:00