http3-package
v1.0.1
Published
A package for handling HTTP/3 with TLS and UDP
Downloads
112
Readme
Here's the final README.md
file you can use for your project:
# HTTP/3 Node.js Package
This package provides an implementation of HTTP/3 over UDP using Node.js. It allows you to create secure, encrypted
communication channels between clients and servers using the latest HTTP/3 protocol.
## Features
- **HTTP/3 over UDP**: Implements the latest HTTP/3 protocol with UDP.
- **TLS Encryption**: Secure communication using TLS.
- **Session Management**: Supports session handling with session IDs.
- **Chunked Messaging**: Efficient handling of large messages by sending them in chunks.
- **Rate Limiting**: Implements rate limiting to control the flow of requests.
## Installation
You can install this package using npm:
```bash
npm install http3-package
Usage
Server Example
const Http3Server = require('http3-package/src/core/http3server');
const server = new Http3Server('127.0.0.1', 4434, 'path/to/server-cert.pem', 'path/to/server-key.pem');
server.setRequestHandler(async (request) => {
console.log('Received request:', request);
// Handle request based on method
let response;
if (request.method === 'GET') {
response = {body: 'Hello, HTTP/3 with UDP! (GET)'};
} else if (request.method === 'POST') {
response = {body: 'Data received and processed! (POST)', data: request.payload};
}
return response;
});
console.log('HTTP/3 server is running');
Client Example
const Http3Client = require('http3-package/src/core/http3client');
const client = new Http3Client('localhost', 4434, 'path/to/client-cert.pem', 'path/to/client-key.pem');
const sendRequest = async () => {
await client.initializeSession();
const method = 'POST';
const path = '/example';
const headers = {
'Content-Type': 'application/json'
};
const body = {
key: 'value'
};
await client.sendHttpRequest(method, path, headers, body);
console.log('HTTP/3 request sent.');
};
sendRequest();
Configuration
Before starting the HTTP/3 server and client, you need to set up the stunnel configurations.
1. Environment Variables
You can set the following environment variables or you will be prompted to enter them during the setup:
SERVER_ACCEPT
: The server's accept address (e.g.,127.0.0.1:5000
).SERVER_CONNECT
: The server's connect address (e.g.,127.0.0.1:4434
).SERVER_CERT
: Path to the server's certificate file (e.g.,path/to/server-cert.pem
).SERVER_KEY
: Path to the server's private key file (e.g.,path/to/server-key.pem
).CLIENT_ACCEPT
: The client's accept address (e.g.,127.0.0.1:5001
).CLIENT_CONNECT
: The client's connect address (e.g.,127.0.0.1:5000
).CLIENT_CERT
: Path to the client's certificate file (e.g.,path/to/client-cert.pem
).CLIENT_KEY
: Path to the client's private key file (e.g.,path/to/client-key.pem
).
2. Running the Setup Script
Run the following command to generate the stunnel configuration files:
node scripts/setupStunnel.js
This script will create the necessary stunnel configuration files based on your environment variables or inputs.
Running the Server and Client
After setting up the stunnel configuration, you can start the server and client as follows:
Starting the Server
node server-example.js
Starting the Client
node client-example.js
Security Considerations
- Ensure that your TLS certificates are securely generated and stored.
- Regularly update your dependencies to ensure that your implementation remains secure.
Contributing
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request.
License
This project is licensed under the MIT License.