Skip to content

Commit d748999

Browse files
committed
docs: add CLAUDE.md for Claude Code guidance
1 parent 8c078b5 commit d748999

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

CLAUDE.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
urllib is a Node.js HTTP client library built on top of [undici](https://undici.nodejs.org/). It provides features like basic/digest authentication, redirections, timeout handling, gzip/brotli compression, file uploads, and HTTP/2 support.
8+
9+
## Common Commands
10+
11+
```bash
12+
# Install dependencies (uses pnpm)
13+
pnpm install
14+
15+
# Run all tests
16+
pnpm test
17+
18+
# Run a single test file
19+
pnpm test test/options.timeout.test.ts
20+
21+
# Run tests matching a pattern
22+
pnpm test -t "should timeout"
23+
24+
# Run tests with debug output
25+
NODE_DEBUG=urllib:* pnpm test
26+
27+
# Lint code
28+
pnpm run lint
29+
30+
# Format code
31+
pnpm run fmt
32+
33+
# Type check
34+
pnpm run typecheck
35+
36+
# Build the project (outputs to dist/)
37+
pnpm run build
38+
39+
# Run benchmarks
40+
pnpm run bench
41+
42+
# Run coverage
43+
pnpm run cov
44+
```
45+
46+
## Architecture
47+
48+
### Source Structure (`src/`)
49+
50+
- **index.ts** - Main entry point, exports `request()` and `curl()` functions with singleton HttpClient instances (cached by configuration: allowH2, rejectUnauthorized, socketPath)
51+
- **HttpClient.ts** - Core class that wraps undici's request API. Handles request building, response processing, retries, redirects, digest auth, compression, timeouts, and diagnostics channel publishing
52+
- **HttpAgent.ts** - Custom undici Agent with DNS lookup interception and SSRF protection via `checkAddress` callback
53+
- **Request.ts** - TypeScript types for request options
54+
- **Response.ts** - TypeScript types for response objects including timing info
55+
- **fetch.ts** - Fetch API compatibility layer using HttpClient internally
56+
- **FormData.ts** - FormData wrapper for multipart uploads
57+
- **HttpClientError.ts** - Custom error classes (HttpClientConnectTimeoutError, HttpClientRequestTimeoutError)
58+
- **diagnosticsChannel.ts** - Node.js diagnostics_channel integration for request/response tracing
59+
60+
### Build System
61+
62+
Uses [tshy](https://github.com/isaacs/tshy) to build dual ESM/CommonJS output:
63+
64+
- ESM output: `dist/esm/`
65+
- CommonJS output: `dist/commonjs/`
66+
67+
The package exports both formats via conditional exports in package.json.
68+
69+
### Testing
70+
71+
Tests use Vitest with:
72+
73+
- Test files in `test/*.test.ts`
74+
- Test fixtures in `test/fixtures/`
75+
- Local HTTP server created in tests via `test/fixtures/server.ts`
76+
- 60 second default timeout per test
77+
78+
## Key Implementation Details
79+
80+
- Default timeout is 5000ms for both headers and body
81+
- Automatic retry on socket errors (configurable via `socketErrorRetry`)
82+
- Request/response events published via `diagnostics_channel` (`urllib:request`, `urllib:response`)
83+
- Streaming requests disable retry/redirect functionality
84+
- User-Agent header: `node-urllib/{version} Node.js/{version} ({platform}; {arch})`

0 commit comments

Comments
 (0)