Parse business identity
Ví dụ invoice ID; không coi request path là OS path.
Product knowledge · Advanced · Filesystem boundary
Dùng static mount cho public assets, SPA fallback cho navigation và confined file response cho download đã được application authorize. Ba surface này chia sẻ delivery engine nhưng không chia sẻ trust policy.
Trang này hướng dẫn tải xuống: server → client. sendfile là một cách gửi tệp đã có trong response. Muốn nhận tệp client → server, dùng các bài tải lên. Xem cách tải tiếp tệp lớn.
01 · Three file surfaces
| Surface | Ai chọn file | Dùng cho |
|---|---|---|
| Static mount | Deployment/app declaration grant một public root. | JS, CSS, images, fonts và public built assets. |
| SPA fallback | Route policy trả index cho navigation path chưa match. | Client-side routes; không thay API 404. |
| File response | Application handler authorize rồi chọn relative file trong authority. | Private report, invoice hoặc user-owned download. |
Core sở hữu resolution, validators, ranges, pressure và delivery. Application sở hữu authorization/business mapping. Deployment sở hữu asset bytes, publication và replacement.
02 · Route precedence
GET /api/orders/7 → explicit API route
GET /assets/app.js → static mount
GET /app/customer/7 → SPA index fallback
GET /api/missing → API 404/refusal, not SPA HTMLGiữ API namespace rõ. Fallback chỉ dành cho navigation đã chọn; không nuốt typo, authorization failure hoặc missing API rồi trả HTML 200.
03 · Public static root
04 · SPA fallback
Navigation path thuộc frontend scope và cần index để client router tiếp quản.
API path, file request, method không phù hợp hoặc request không chấp nhận HTML.
Index và hashed assets có lifecycle/cache policy khác nhau; deployment chọn versioning.
Fallback không bypass handler authorization hoặc biến private file thành public asset.
05 · Authorized file response
Ví dụ invoice ID; không coi request path là OS path.
Application quyết định principal có quyền đọc object.
Map object sang relative path/application file reference đã confined.
Core validate, account và deliver; handler không đọc whole file thành byte array nếu không cần.
Không làm: nối ?path=/etc/passwd, filename hoặc decoded capture trực tiếp vào filesystem root.
06 · Validators and ranges
200206304416Dùng runtime validator/range contract; không reimplement header parser trong handler. Test full, partial, cached, missing, invalid path và interrupted download.
07 · Delivery mechanism
Plaintext HTTP/1.1 đủ điều kiện có thể dùng native sendfile path. TLS, HTTP/2, HTTP/3 hoặc platform khác dùng bounded delivery path phù hợp. Core chọn mechanism/fallback; connector không dựng socket/file loop riêng.
Cache, storage, protocol, kernel và client speed vẫn quyết định copies/CPU.
Security boundary quan trọng hơn một fast path; mechanism không phải application knob.
Successful download không chứng minh syscall/backend; cần matching-host evidence.
Sendfile không parse multipart, chọn destination hoặc persist incoming bytes.
Range tiếp tục tải xuống một response; next_offset tiếp tục tải lên một tệp đang gửi. Xem cách tải tiếp lên server.
08 · Failure law
| Failure | Owner action |
|---|---|
| Outside authority / invalid path | Fail closed; không normalize thành file khác. |
| Not authorized | Application trả public-safe refusal; không tiết lộ existence/path. |
| Missing/changed file | Map theo application/API contract; giữ operator detail riêng. |
| Pressure/timeout/disconnect | Release transfer state; không retry/download vô hạn trong connector. |
| Close refusal | Giữ owner và filesystem dependencies tới khi work converge an toàn. |
09 · Integration checklist