feat: Implement SecureReq class for enhanced HTTPS requests#4
Merged
piquark6046 merged 15 commits intomainfrom Apr 3, 2026
Merged
feat: Implement SecureReq class for enhanced HTTPS requests#4piquark6046 merged 15 commits intomainfrom
piquark6046 merged 15 commits intomainfrom
Conversation
Member
piquark6046
commented
Apr 3, 2026
- Add request-helpers.ts for utility functions to determine expected response types and handle errors.
- Introduce request-schema.ts to define and validate HTTPS request options using Zod.
- Create secure-req.ts to implement the SecureReq class, supporting HTTP/1.1 and HTTP/2 protocols with compression negotiation.
- Update type.ts to include new types for HTTP methods, protocols, and request options.
- Enhance utils.ts with functions for handling streams, headers, and payloads.
- Add comprehensive tests for SecureReq, covering protocol negotiation, response decoding, and streaming uploads/downloads.
- Implement a test server in support/server.ts to facilitate testing of various response types and encodings.
- Create TLS certificate generation in support/tls.ts for secure testing.
- Add request-helpers.ts for utility functions to determine expected response types and handle errors. - Introduce request-schema.ts to define and validate HTTPS request options using Zod. - Create secure-req.ts to implement the SecureReq class, supporting HTTP/1.1 and HTTP/2 protocols with compression negotiation. - Update type.ts to include new types for HTTP methods, protocols, and request options. - Enhance utils.ts with functions for handling streams, headers, and payloads. - Add comprehensive tests for SecureReq, covering protocol negotiation, response decoding, and streaming uploads/downloads. - Implement a test server in support/server.ts to facilitate testing of various response types and encodings. - Create TLS certificate generation in support/tls.ts for secure testing.
There was a problem hiding this comment.
Pull request overview
This PR replaces the previous function-based HTTPS helpers with a new SecureReq class that adds per-origin protocol/compression negotiation, streaming request/response support, and a local TLS-backed test server to validate HTTP/1.1 ↔ HTTP/2 behavior.
Changes:
- Introduces
SecureReqwith HTTP/1.1 + HTTP/2 transports, response decompression, streaming payloads, and origin capability caching. - Adds request option validation (Zod) plus new shared constants/types/utilities to support protocol/compression negotiation and streaming.
- Replaces external-network tests with a local HTTP/2 (allowHTTP1) TLS test server, including on-the-fly certificate generation.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
sources/secure-req.ts |
Implements SecureReq request flow, HTTP/2 session caching, response decoding, and origin capability tracking. |
sources/utils.ts |
Adds stream/header helpers, payload normalization, compression parsing, and decoding stream creation. |
sources/type.ts |
Expands public types for protocols, methods, payloads, and richer response metadata. |
sources/request-schema.ts |
Adds Zod validation for request options (including streaming payload support). |
sources/request-helpers.ts |
Adds helpers for response type inference and error normalization. |
sources/constants.ts |
Centralizes default TLS/header/compression settings and header filtering sets. |
sources/index.ts |
Switches public API surface to export SecureReq, GlobalSecureReq, and updated types. |
tests/support/tls.ts |
Generates ephemeral TLS cert/key via OpenSSL for local HTTPS testing. |
tests/support/server.ts |
Adds local HTTP/2 secure test server (HTTP/1.1 allowed) with compression + streaming endpoints. |
tests/index.test.ts |
Replaces external HTTP tests with comprehensive SecureReq tests against the local server. |
README.md |
Updates docs to reflect the class-based API, negotiation behavior, compression, and streaming. |
eslint.config.js |
Updates naming-convention rule to include class methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ance origin capability caching
- Added AutomaticHTTP2ProbeMethods to constants for GET and HEAD methods. - Introduced HTTP2NegotiationError class for better error handling during HTTP/2 negotiations. - Implemented IsAutomaticHTTP2ProbeMethod function to check if a method is suitable for automatic HTTP/2 probing. - Updated SecureReq class to handle automatic fallback to HTTP/1.1 upon HTTP/2 negotiation failure. - Enhanced Request method to support auto-detection of response body types. - Improved RequestOptionsSchema to include new TLS options and compression settings. - Added tests for new features, including automatic HTTP/2 negotiation and response parsing. - Refactored server setup to support HTTP/1.1 only test cases.
…ing to TestServer
…ocket for requests
…cancellation, and protocol negotiation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.