THRIFT-6203: Replace deprecated url.parse and fs.exists in the Node.js library - #3821
THRIFT-6203: Replace deprecated url.parse and fs.exists in the Node.js library#3821slachiewicz wants to merge 1 commit into
Conversation
ae17a95 to
a42ea0d
Compare
3b960da to
466b138
Compare
466b138 to
7aab2fd
Compare
Code reviewFound 1 issue:
thrift/lib/nodejs/lib/thrift/web_server.js Lines 373 to 375 in 7aab2fd thrift/lib/nodejs/lib/thrift/web_server.js Lines 667 to 675 in 7aab2fd One suggestion, below the bar for the list above but verified:
thrift/lib/nodejs/lib/thrift/web_server.js Lines 450 to 460 in 7aab2fd 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
|
Follow-up to the review above: master now refuses a WebSocket upgrade when no service is configured, an empty 🤖 Generated with Claude Code |
7aab2fd to
70cae7b
Compare
|
Branch rewritten (70cae7b): rebased on current master, which carries the upgrade-listener fix from 31f5897, so point 1 needs nothing here as you said. The suggestion is taken: both Verified: This comment was created with AI assistance. |
…b_server
Client: nodejs
- Replace url.parse() (DEP0169) with the WHATWG URL class in web_server.js.
Only the pathname is used, so the base is a fixed http://localhost: built
from the Host header, a value that is not a valid authority made new URL
throw and turned into a 400 that url.parse never produced.
- Replace fs.exists() (DEP0006) with fs.stat() in web_server.js, dropping
the redundant statSync
- Default options.services to {} in createWebServer so a static-only server
does not fail with a TypeError on its first POST. The WebSocket upgrade
listener already refuses an empty services object since 31f5897.
- Add HTTP static file serving and URL handling test in web_server_ws.test.js
- Name Buffer.from(string) in the thrift_4987_xhr_protocol.test.mjs comment,
left over from the Buffer() replacement in THRIFT-5224
Note: the require("constants") (DEP0063) replacements in server.js and
connection.js from the original revision were dropped on rebase because
upstream ec1066a already removed that code and now leaves TLS defaults
to Node.
Co-Authored-By: Gemini 3.8 Flash <noreply@google.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
70cae7b to
dd8cfb8
Compare
JIRA: THRIFT-6203
Client: nodejs
The library called two APIs Node has deprecated, so an application embedding it printed
DEP0169andDEP0006on every supported runtime:url.parse()andfs.exists()inweb_server.js. They become the WHATWGURLclass andfs.stat().Note: this revision originally also replaced
require("constants")(DEP0063) inserver.jsandconnection.js, but that was dropped on rebase because upstreamec1066ab4already removed that code and now leaves the TLS defaults to Node.Two behaviour changes come with that and are worth reviewing on their own terms.
A malformed request target now gets a 400.
url.parse()accepts one and returns a partly-parsed path;new URL()throws.processPostandprocessGetcatch it and answer400 Bad Requestrather than letting the exception reach the request handler. Only the pathname is used, so the base is a fixedhttp://localhost: built from theHostheader, a value that is not a valid authority (example.com:abc, an unbracketed IPv6 address) madenew URL()throw and produced a 400 thaturl.parse()never did.options.servicesdefaults to{}. A server serving only static files has no reason to pass it, andcreateWebServerread it without a default. The registration loop does not catch that, becausefor...inoverundefinedis a no-op rather than an error, so the first POST failed instead:The WebSocket upgrade listener is unaffected: since
31f5897cbon master it refuses an emptyservicesobject with a 403, andweb_server_ws.test.jscovers that case.The
fs.exists()replacement also drops a redundantfs.statSync()that ran immediately after the async check.Also carried here: the comment in
thrift_4987_xhr_protocol.test.mjsnow namesBuffer.from(string), the wording left over from theBuffer()replacement in #3819.Verified:
node -e "for (var u in undefined) {}"is a no-op, while indexingundefinedthrows theTypeErrorabove — the failure could only surface on a request, not at construction.The new cases in
web_server_ws.test.jscover static file serving, a 404, and a request routed to an unregistered service.This change was created with AI assistance.