Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 14, 2025

Motivation for the change, related issues

fetchWithCorsProxy now upgrades HTTP URLs to HTTPS. Tests making requests to http://127.0.0.1:PORT get upgraded to https://127.0.0.1:PORT, requiring an HTTPS test server.

Implementation details

Test server migration to HTTPS

  • Generate self-signed certificates with SANs for 127.0.0.1 using selfsigned library
  • Convert Express server from app.listen() to https.createServer()
  • Set NODE_TLS_REJECT_UNAUTHORIZED=0 for test environment

Fix request body stream handling

  • cloneRequest() was calling await request.blob() to clone requests with bodies
  • This hung on POST requests because the body stream was still awaiting data that would never arrive
  • Solution: Reuse unconsumed body streams directly via request.body instead of reading to Blob
// Before: Hangs when body stream is still open
const body = await request.blob();

// After: Reuses stream when possible
const body = !request.bodyUsed && request.body 
  ? request.body 
  : await request.blob();
  • Added duplex: 'half' to Request creation for Node.js streaming body compatibility
  • Removed unused @ts-expect-error directive as TypeScript now properly recognizes the duplex property

Testing Instructions (or ideally a Blueprint)

CI. All 31 tests in tcp-over-fetch-websocket.spec.ts pass, including POST requests with bodies.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 15, 2025 00:10
- Updated tcp-over-fetch-websocket.spec.ts to use HTTPS server instead of HTTP
- Created generate-certificate utility using selfsigned library
- Added duplex: 'half' option to cloneRequest for Node.js compatibility
- Set NODE_TLS_REJECT_UNAUTHORIZED=0 for test environment
- Still debugging POST request timeouts

Co-authored-by: adamziel <205419+adamziel@users.noreply.github.com>
- Modified cloneRequest to reuse body stream directly when not consumed
- This fixes the hang that occurred when converting HTTP to HTTPS requests
- Added proper error handling to bufferResponse in tests
- All tcp-over-fetch-websocket tests now pass

Co-authored-by: adamziel <205419+adamziel@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix fetch-with-cors-proxy for HTTPS paths [Website] Run HTTPS test server for tcp-over-fetch-websocket tests Nov 15, 2025
Copilot finished work on behalf of adamziel November 15, 2025 00:20
Copilot AI requested a review from adamziel November 15, 2025 00:20
@adamziel
Copy link
Collaborator

@copilot remove expect error:

packages/php-wasm/web-service-worker/src/utils.ts:196:3 - error TS2578: Unused '@ts-expect-error' directive.
194 | // In Node.js, duplex: 'half' is required when
195 | // the body is provided for non-GET/HEAD requests.

196 | // @ts-expect-error - duplex is not in the TypeScript types

TypeScript now recognizes the duplex property in Request options, so the error suppression is no longer needed.

Co-authored-by: adamziel <205419+adamziel@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot remove expect error:

packages/php-wasm/web-service-worker/src/utils.ts:196:3 - error TS2578: Unused '@ts-expect-error' directive.
...

Done! Removed the unused @ts-expect-error directive. TypeScript now properly recognizes the duplex property in Request options. (Commit: 94747c8)

Copilot finished work on behalf of adamziel November 15, 2025 00:36
@adamziel adamziel marked this pull request as ready for review November 18, 2025 11:04
@adamziel adamziel merged commit 13714ad into enforce-https-in-cors-proxy Nov 18, 2025
29 checks passed
@adamziel adamziel deleted the copilot/sub-pr-2901 branch November 18, 2025 11:04
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.

2 participants