Skip to content

feat: Implement SecureReq class for enhanced HTTPS requests#4

Merged
piquark6046 merged 15 commits intomainfrom
upd/2.0.0
Apr 3, 2026
Merged

feat: Implement SecureReq class for enhanced HTTPS requests#4
piquark6046 merged 15 commits intomainfrom
upd/2.0.0

Conversation

@piquark6046
Copy link
Copy Markdown
Member

  • 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.
@piquark6046 piquark6046 marked this pull request as ready for review April 3, 2026 13:20
Copilot AI review requested due to automatic review settings April 3, 2026 13:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SecureReq with 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.

- 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.
@piquark6046 piquark6046 merged commit 95088c5 into main Apr 3, 2026
13 checks passed
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