You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+
## Project Overview
6
+
7
+
@fastify/reply-from is a Fastify plugin that forwards HTTP requests to another server, supporting HTTP/1.1, HTTP/2, and various client configurations including undici, Node.js http/https agents, and unix sockets.
8
+
9
+
## Common Commands
10
+
11
+
### Testing
12
+
-`npm test` - Run all tests (unit + TypeScript)
13
+
-`npm run test:unit` - Run unit tests with tap
14
+
-`npm run test:typescript` - Run TypeScript definition tests with tsd
15
+
16
+
### Code Quality
17
+
-`npm run lint` - Run standard linter with snazzy formatter
18
+
-`npm run lint:fix` - Auto-fix linting issues
19
+
20
+
### Development
21
+
- Tests are located in `test/` directory with `.test.js` extension
22
+
- Test coverage thresholds: 96% lines, 96% statements, 96% branches, 97% functions (configured in `.taprc`)
23
+
- Uses `tap` as the test framework
24
+
- Pre-commit hooks run lint and test automatically
25
+
26
+
## Architecture
27
+
28
+
### Core Files
29
+
-`index.js` - Main plugin entry point with `reply.from()` decorator
30
+
-`lib/request.js` - HTTP client abstraction supporting HTTP/1.1, HTTP/2, and undici
31
+
-`lib/utils.js` - Header manipulation and URL building utilities
32
+
-`lib/errors.js` - Custom error classes for different failure scenarios
33
+
34
+
### Key Components
35
+
36
+
#### Request Handling (`index.js`)
37
+
- Decorates Fastify reply with `from(source, opts)` method
38
+
- Handles request/response transformation via configurable hooks
39
+
- Implements retry logic with exponential backoff for failed requests
40
+
- Supports URL caching to optimize performance (configurable via `cacheURLs` option)
41
+
42
+
#### HTTP Client Layer (`lib/request.js`)
43
+
-**HTTP/1.1**: Uses Node.js `http`/`https` modules with custom agents
44
+
-**HTTP/2**: Uses Node.js `http2` module with session management
45
+
-**Undici**: High-performance HTTP client with connection pooling
46
+
-**Unix Sockets**: Supports `unix+http:` and `unix+https:` protocols
47
+
- Automatic protocol selection based on configuration
48
+
49
+
#### Utilities (`lib/utils.js`)
50
+
-`filterPseudoHeaders()` - Removes HTTP/2 pseudo-headers for HTTP/1.1 compatibility
51
+
-`stripHttp1ConnectionHeaders()` - Removes connection-specific headers for HTTP/2
52
+
-`copyHeaders()` - Safely copies headers to Fastify reply
53
+
-`buildURL()` - Constructs target URLs with base URL validation
54
+
55
+
### Plugin Options
56
+
-`base` - Base URL for all forwarded requests (required for HTTP/2)
57
+
-`undici` - Enable/configure undici client (boolean or options object)
58
+
-`http`/`http2` - Configure Node.js HTTP clients
59
+
-`retryMethods` - HTTP methods to retry on socket errors (default: GET, HEAD, OPTIONS, TRACE)
60
+
-`retriesCount` - Number of retries for socket hangup errors
61
+
-`maxRetriesOn503` - Retry limit for 503 Service Unavailable responses
62
+
63
+
### Request/Response Hooks
64
+
-`onResponse(request, reply, res)` - Transform response before sending
0 commit comments