bluera-knowledge 0.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/commit.md +37 -0
- package/.claude/hooks/post-edit-check.sh +41 -0
- package/.claude/settings.local.json.example +40 -0
- package/.claude/skills/atomic-commits/SKILL.md +53 -0
- package/.claude-plugin/plugin.json +13 -0
- package/.editorconfig +15 -0
- package/.github/workflows/auto-release.yml +59 -0
- package/.github/workflows/ci.yml +142 -0
- package/.github/workflows/release.yml +66 -0
- package/.github/workflows/update-marketplace.yml +96 -0
- package/.husky/pre-commit +47 -0
- package/.husky/pre-push +29 -0
- package/.versionrc.json +28 -0
- package/CHANGELOG.md +410 -0
- package/CLAUDE.md +109 -0
- package/LICENSE +21 -0
- package/NOTICE +47 -0
- package/README.md +1546 -0
- package/SECURITY.md +65 -0
- package/bun.lock +1758 -0
- package/commands/add-folder.md +48 -0
- package/commands/add-repo.md +50 -0
- package/commands/cancel.md +63 -0
- package/commands/check-status.md +78 -0
- package/commands/crawl.md +51 -0
- package/commands/index.md +48 -0
- package/commands/remove-store.md +52 -0
- package/commands/search.md +79 -0
- package/commands/search.sh +63 -0
- package/commands/stores.md +54 -0
- package/commands/suggest.md +82 -0
- package/dist/chunk-5QMHZUC4.js +3617 -0
- package/dist/chunk-5QMHZUC4.js.map +1 -0
- package/dist/chunk-BICFAWMN.js +656 -0
- package/dist/chunk-BICFAWMN.js.map +1 -0
- package/dist/chunk-J7J6LXOJ.js +958 -0
- package/dist/chunk-J7J6LXOJ.js.map +1 -0
- package/dist/chunk-L2YVNC63.js +59 -0
- package/dist/chunk-L2YVNC63.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1429 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +15 -0
- package/dist/mcp/server.js +11 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/watch.service-YAIKKDCF.js +7 -0
- package/dist/watch.service-YAIKKDCF.js.map +1 -0
- package/dist/workers/background-worker-cli.d.ts +1 -0
- package/dist/workers/background-worker-cli.js +310 -0
- package/dist/workers/background-worker-cli.js.map +1 -0
- package/docs/plans/2024-12-17-ai-search-quality-implementation.md +752 -0
- package/docs/plans/2024-12-17-ai-search-quality-testing-design.md +201 -0
- package/docs/plans/2025-12-16-bluera-knowledge-cli.md +2951 -0
- package/docs/plans/2025-12-16-phase2-features.md +1518 -0
- package/docs/plans/2025-12-17-hil-implementation.md +926 -0
- package/docs/plans/2025-12-17-hil-quality-testing.md +224 -0
- package/docs/plans/2025-12-17-search-quality-phase1-implementation.md +1416 -0
- package/docs/plans/2025-12-17-search-quality-testing-v2-design.md +212 -0
- package/docs/plans/2025-12-28-ai-agent-optimization.md +1630 -0
- package/eslint-rules/require-skip-comment.js +81 -0
- package/eslint.config.js +61 -0
- package/hooks/check-dependencies.sh +110 -0
- package/hooks/format-search-results.py +132 -0
- package/hooks/hooks.json +27 -0
- package/hooks/job-status-hook.sh +51 -0
- package/knip.json +43 -0
- package/mcp.plugin.json +12 -0
- package/package.json +103 -0
- package/python/crawl_worker.py +275 -0
- package/python/requirements.txt +2 -0
- package/scripts/readme-version-updater.cjs +18 -0
- package/skills/advanced-workflows/SKILL.md +273 -0
- package/skills/atomic-commits/SKILL.md +77 -0
- package/skills/knowledge-search/SKILL.md +54 -0
- package/skills/search-optimization/SKILL.md +396 -0
- package/skills/store-lifecycle/SKILL.md +470 -0
- package/skills/when-to-query/SKILL.md +66 -0
- package/src/analysis/ast-parser.test.ts +423 -0
- package/src/analysis/ast-parser.ts +192 -0
- package/src/analysis/code-graph.test.ts +698 -0
- package/src/analysis/code-graph.ts +245 -0
- package/src/analysis/dependency-usage-analyzer.test.ts +799 -0
- package/src/analysis/dependency-usage-analyzer.ts +405 -0
- package/src/analysis/go-ast-parser.test.ts +531 -0
- package/src/analysis/go-ast-parser.ts +478 -0
- package/src/analysis/parser-factory.test.ts +132 -0
- package/src/analysis/parser-factory.ts +44 -0
- package/src/analysis/python-ast-parser.test.ts +210 -0
- package/src/analysis/python-ast-parser.ts +34 -0
- package/src/analysis/repo-url-resolver.test.ts +533 -0
- package/src/analysis/repo-url-resolver.ts +233 -0
- package/src/analysis/rust-ast-parser.test.ts +568 -0
- package/src/analysis/rust-ast-parser.ts +477 -0
- package/src/analysis/tree-sitter-parser.test.ts +297 -0
- package/src/analysis/tree-sitter-parser.ts +223 -0
- package/src/cli/commands/crawl.test.ts +942 -0
- package/src/cli/commands/crawl.ts +141 -0
- package/src/cli/commands/index-cmd.test.ts +722 -0
- package/src/cli/commands/index-cmd.ts +105 -0
- package/src/cli/commands/mcp.test.ts +218 -0
- package/src/cli/commands/mcp.ts +18 -0
- package/src/cli/commands/plugin-api.test.ts +313 -0
- package/src/cli/commands/plugin-api.ts +45 -0
- package/src/cli/commands/search.test.ts +911 -0
- package/src/cli/commands/search.ts +113 -0
- package/src/cli/commands/serve.test.ts +329 -0
- package/src/cli/commands/serve.ts +28 -0
- package/src/cli/commands/setup.test.ts +820 -0
- package/src/cli/commands/setup.ts +153 -0
- package/src/cli/commands/store.test.ts +1003 -0
- package/src/cli/commands/store.ts +167 -0
- package/src/cli/index.ts +7 -0
- package/src/cli/program.ts +59 -0
- package/src/crawl/article-converter.test.ts +604 -0
- package/src/crawl/article-converter.ts +98 -0
- package/src/crawl/bridge.test.ts +674 -0
- package/src/crawl/bridge.ts +236 -0
- package/src/crawl/claude-client.test.ts +663 -0
- package/src/crawl/claude-client.ts +234 -0
- package/src/crawl/intelligent-crawler.test.ts +931 -0
- package/src/crawl/intelligent-crawler.ts +428 -0
- package/src/crawl/markdown-utils.test.ts +703 -0
- package/src/crawl/markdown-utils.ts +228 -0
- package/src/crawl/schemas.ts +114 -0
- package/src/db/embeddings.test.ts +63 -0
- package/src/db/embeddings.ts +69 -0
- package/src/db/index.ts +2 -0
- package/src/db/lance.test.ts +390 -0
- package/src/db/lance.ts +164 -0
- package/src/defaults/repos.ts +67 -0
- package/src/index.ts +107 -0
- package/src/mcp/cache.test.ts +202 -0
- package/src/mcp/cache.ts +103 -0
- package/src/mcp/commands/index.ts +20 -0
- package/src/mcp/commands/job.commands.ts +54 -0
- package/src/mcp/commands/meta.commands.ts +54 -0
- package/src/mcp/commands/registry.ts +183 -0
- package/src/mcp/commands/store.commands.ts +75 -0
- package/src/mcp/handlers/execute.handler.test.ts +179 -0
- package/src/mcp/handlers/execute.handler.ts +24 -0
- package/src/mcp/handlers/index.ts +43 -0
- package/src/mcp/handlers/job.handler.test.ts +189 -0
- package/src/mcp/handlers/job.handler.ts +116 -0
- package/src/mcp/handlers/search.handler.test.ts +334 -0
- package/src/mcp/handlers/search.handler.ts +209 -0
- package/src/mcp/handlers/store.handler.test.ts +415 -0
- package/src/mcp/handlers/store.handler.ts +295 -0
- package/src/mcp/schemas/index.test.ts +315 -0
- package/src/mcp/schemas/index.ts +138 -0
- package/src/mcp/server.test.ts +36 -0
- package/src/mcp/server.ts +162 -0
- package/src/mcp/types.ts +41 -0
- package/src/plugin/commands.test.ts +789 -0
- package/src/plugin/commands.ts +257 -0
- package/src/plugin/dependency-analyzer.test.ts +380 -0
- package/src/plugin/dependency-analyzer.ts +147 -0
- package/src/plugin/git-clone.test.ts +332 -0
- package/src/plugin/git-clone.ts +57 -0
- package/src/server/app.test.ts +752 -0
- package/src/server/app.ts +119 -0
- package/src/server/index.test.ts +477 -0
- package/src/server/index.ts +1 -0
- package/src/services/chunking.service.test.ts +363 -0
- package/src/services/chunking.service.ts +350 -0
- package/src/services/code-graph.service.test.ts +304 -0
- package/src/services/code-graph.service.ts +302 -0
- package/src/services/code-unit.service.test.ts +596 -0
- package/src/services/code-unit.service.ts +115 -0
- package/src/services/config.service.test.ts +127 -0
- package/src/services/config.service.ts +69 -0
- package/src/services/index.service.test.ts +1002 -0
- package/src/services/index.service.ts +266 -0
- package/src/services/index.ts +75 -0
- package/src/services/job.service.test.ts +418 -0
- package/src/services/job.service.ts +246 -0
- package/src/services/project-root.service.test.ts +506 -0
- package/src/services/project-root.service.ts +112 -0
- package/src/services/search.service.test.ts +1105 -0
- package/src/services/search.service.ts +892 -0
- package/src/services/services.test.ts +38 -0
- package/src/services/snippet.service.test.ts +205 -0
- package/src/services/snippet.service.ts +166 -0
- package/src/services/store.service.test.ts +474 -0
- package/src/services/store.service.ts +225 -0
- package/src/services/watch.service.test.ts +553 -0
- package/src/services/watch.service.ts +71 -0
- package/src/types/brands.test.ts +45 -0
- package/src/types/brands.ts +32 -0
- package/src/types/config.ts +79 -0
- package/src/types/document.ts +30 -0
- package/src/types/index.ts +66 -0
- package/src/types/job.ts +46 -0
- package/src/types/progress.ts +9 -0
- package/src/types/result.test.ts +44 -0
- package/src/types/result.ts +41 -0
- package/src/types/search.ts +95 -0
- package/src/types/store.test.ts +69 -0
- package/src/types/store.ts +47 -0
- package/src/utils/type-guards.test.ts +346 -0
- package/src/utils/type-guards.ts +61 -0
- package/src/workers/background-worker-cli.ts +105 -0
- package/src/workers/background-worker.test.ts +178 -0
- package/src/workers/background-worker.ts +294 -0
- package/src/workers/spawn-worker.test.ts +128 -0
- package/src/workers/spawn-worker.ts +49 -0
- package/tests/analysis/ast-parser.test.ts +98 -0
- package/tests/analysis/code-graph.test.ts +60 -0
- package/tests/fixtures/README.md +114 -0
- package/tests/fixtures/code-snippets/api/error-handling.ts +267 -0
- package/tests/fixtures/code-snippets/api/rest-controller.ts +303 -0
- package/tests/fixtures/code-snippets/auth/jwt-auth.ts +213 -0
- package/tests/fixtures/code-snippets/auth/oauth-flow.ts +245 -0
- package/tests/fixtures/code-snippets/database/repository-pattern.ts +272 -0
- package/tests/fixtures/corpus/VERSION.md +25 -0
- package/tests/fixtures/corpus/articles/jwt-authentication.md +97 -0
- package/tests/fixtures/corpus/articles/react-hooks-patterns.md +127 -0
- package/tests/fixtures/corpus/articles/typescript-generics.md +111 -0
- package/tests/fixtures/corpus/documentation/express-middleware.md +71 -0
- package/tests/fixtures/corpus/documentation/express-routing.md +83 -0
- package/tests/fixtures/corpus/documentation/node-streams.md +78 -0
- package/tests/fixtures/corpus/oss-repos/express/History.md +3871 -0
- package/tests/fixtures/corpus/oss-repos/express/LICENSE +24 -0
- package/tests/fixtures/corpus/oss-repos/express/Readme.md +276 -0
- package/tests/fixtures/corpus/oss-repos/express/SECURITY.md +56 -0
- package/tests/fixtures/corpus/oss-repos/express/benchmarks/Makefile +17 -0
- package/tests/fixtures/corpus/oss-repos/express/benchmarks/README.md +34 -0
- package/tests/fixtures/corpus/oss-repos/express/benchmarks/middleware.js +20 -0
- package/tests/fixtures/corpus/oss-repos/express/benchmarks/run +18 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/README.md +29 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/auth/index.js +134 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/auth/views/foot.ejs +2 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/auth/views/head.ejs +20 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/auth/views/login.ejs +21 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/content-negotiation/db.js +9 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/content-negotiation/index.js +46 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/content-negotiation/users.js +19 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/cookie-sessions/index.js +25 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/cookies/index.js +53 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/downloads/files/CCTV/345/244/247/350/265/233/344/270/212/346/265/267/345/210/206/350/265/233/345/214/272.txt +2 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/downloads/files/amazing.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/downloads/files/notes/groceries.txt +3 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/downloads/index.js +40 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/ejs/index.js +57 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/ejs/public/stylesheets/style.css +4 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/ejs/views/footer.html +2 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/ejs/views/header.html +9 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/ejs/views/users.html +10 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error/index.js +53 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/index.js +103 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/views/404.ejs +3 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/views/500.ejs +8 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/views/error_header.ejs +10 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/views/footer.ejs +2 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/error-pages/views/index.ejs +20 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/hello-world/index.js +15 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/markdown/index.js +44 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/markdown/views/index.md +4 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/multi-router/controllers/api_v1.js +15 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/multi-router/controllers/api_v2.js +15 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/multi-router/index.js +18 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/main/index.js +5 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/pet/index.js +31 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/pet/views/edit.ejs +17 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/pet/views/show.ejs +15 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/user/index.js +41 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/user/views/edit.hbs +27 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/user/views/list.hbs +18 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/user/views/show.hbs +31 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/controllers/user-pet/index.js +22 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/db.js +16 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/index.js +95 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/lib/boot.js +83 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/public/style.css +14 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/views/404.ejs +13 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/mvc/views/5xx.ejs +13 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/online/index.js +61 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/params/index.js +74 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/resource/index.js +95 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-map/index.js +75 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-middleware/index.js +90 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/index.js +55 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/post.js +13 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/public/style.css +24 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/site.js +5 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/user.js +47 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/footer.ejs +2 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/header.ejs +9 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/index.ejs +10 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/posts/index.ejs +12 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/users/edit.ejs +23 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/users/index.ejs +14 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/route-separation/views/users/view.ejs +9 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/search/index.js +61 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/search/public/client.js +15 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/search/public/index.html +21 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/session/index.js +37 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/session/redis.js +39 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/static-files/index.js +43 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/static-files/public/css/style.css +3 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/static-files/public/hello.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/static-files/public/js/app.js +1 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/vhost/index.js +53 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/view-constructor/github-view.js +53 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/view-constructor/index.js +48 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/view-locals/index.js +155 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/view-locals/user.js +36 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/view-locals/views/index.ejs +20 -0
- package/tests/fixtures/corpus/oss-repos/express/examples/web-service/index.js +117 -0
- package/tests/fixtures/corpus/oss-repos/express/index.js +11 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/application.js +631 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/express.js +81 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/request.js +514 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/response.js +1053 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/utils.js +271 -0
- package/tests/fixtures/corpus/oss-repos/express/lib/view.js +205 -0
- package/tests/fixtures/corpus/oss-repos/express/package.json +99 -0
- package/tests/fixtures/corpus/oss-repos/express/test/Route.js +274 -0
- package/tests/fixtures/corpus/oss-repos/express/test/Router.js +636 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/auth.js +117 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/content-negotiation.js +49 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/cookie-sessions.js +38 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/cookies.js +71 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/downloads.js +47 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/ejs.js +17 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/error-pages.js +99 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/error.js +29 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/hello-world.js +21 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/markdown.js +21 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/multi-router.js +44 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/mvc.js +132 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/params.js +44 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/resource.js +68 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/route-map.js +45 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/route-separation.js +97 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/vhost.js +46 -0
- package/tests/fixtures/corpus/oss-repos/express/test/acceptance/web-service.js +105 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.all.js +38 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.engine.js +83 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.head.js +66 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.js +120 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.listen.js +55 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.locals.js +26 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.options.js +116 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.param.js +323 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.render.js +374 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.request.js +143 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.response.js +143 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.route.js +197 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.router.js +1217 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.routes.error.js +62 -0
- package/tests/fixtures/corpus/oss-repos/express/test/app.use.js +542 -0
- package/tests/fixtures/corpus/oss-repos/express/test/config.js +207 -0
- package/tests/fixtures/corpus/oss-repos/express/test/exports.js +82 -0
- package/tests/fixtures/corpus/oss-repos/express/test/express.json.js +755 -0
- package/tests/fixtures/corpus/oss-repos/express/test/express.raw.js +513 -0
- package/tests/fixtures/corpus/oss-repos/express/test/express.static.js +815 -0
- package/tests/fixtures/corpus/oss-repos/express/test/express.text.js +566 -0
- package/tests/fixtures/corpus/oss-repos/express/test/express.urlencoded.js +828 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/% of dogs.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/.name +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/blog/index.html +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/blog/post/index.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/broken.send +0 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/default_layout/name.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/default_layout/user.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/email.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/empty.txt +0 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/local_layout/user.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/name.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/name.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/nums.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/pets/names.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/snow /342/230/203/.gitkeep +0 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/todo.html +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/todo.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/user.html +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/user.tmpl +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/users/index.html +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/fixtures/users/tobi.txt +1 -0
- package/tests/fixtures/corpus/oss-repos/express/test/middleware.basic.js +42 -0
- package/tests/fixtures/corpus/oss-repos/express/test/regression.js +20 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.accepts.js +125 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.acceptsCharsets.js +50 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.acceptsEncodings.js +39 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.acceptsLanguages.js +57 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.baseUrl.js +88 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.fresh.js +70 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.get.js +60 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.host.js +156 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.hostname.js +188 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.ip.js +113 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.ips.js +71 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.is.js +169 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.path.js +20 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.protocol.js +113 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.query.js +106 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.range.js +104 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.route.js +28 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.secure.js +101 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.signedCookies.js +37 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.stale.js +50 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.subdomains.js +173 -0
- package/tests/fixtures/corpus/oss-repos/express/test/req.xhr.js +42 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.append.js +116 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.attachment.js +79 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.clearCookie.js +62 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.cookie.js +295 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.download.js +487 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.format.js +248 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.get.js +21 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.json.js +186 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.jsonp.js +344 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.links.js +65 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.locals.js +40 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.location.js +316 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.redirect.js +214 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.render.js +367 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.send.js +569 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.sendFile.js +913 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.sendStatus.js +44 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.set.js +124 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.status.js +206 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.type.js +46 -0
- package/tests/fixtures/corpus/oss-repos/express/test/res.vary.js +90 -0
- package/tests/fixtures/corpus/oss-repos/express/test/support/env.js +3 -0
- package/tests/fixtures/corpus/oss-repos/express/test/support/tmpl.js +36 -0
- package/tests/fixtures/corpus/oss-repos/express/test/support/utils.js +86 -0
- package/tests/fixtures/corpus/oss-repos/express/test/utils.js +83 -0
- package/tests/fixtures/corpus/oss-repos/hono/.devcontainer/Dockerfile +11 -0
- package/tests/fixtures/corpus/oss-repos/hono/.devcontainer/devcontainer.json +21 -0
- package/tests/fixtures/corpus/oss-repos/hono/.devcontainer/docker-compose.yml +18 -0
- package/tests/fixtures/corpus/oss-repos/hono/.eslintignore +1 -0
- package/tests/fixtures/corpus/oss-repos/hono/.eslintrc.cjs +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/.gitpod.yml +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/.prettierrc +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/.vitest.config/jsx-runtime-default.ts +15 -0
- package/tests/fixtures/corpus/oss-repos/hono/.vitest.config/jsx-runtime-dom.ts +15 -0
- package/tests/fixtures/corpus/oss-repos/hono/.vitest.config/setup-vitest.ts +47 -0
- package/tests/fixtures/corpus/oss-repos/hono/LICENSE +21 -0
- package/tests/fixtures/corpus/oss-repos/hono/README.md +91 -0
- package/tests/fixtures/corpus/oss-repos/hono/build.ts +80 -0
- package/tests/fixtures/corpus/oss-repos/hono/bun.lockb +0 -0
- package/tests/fixtures/corpus/oss-repos/hono/bunfig.toml +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/codecov.yml +13 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/CODE_OF_CONDUCT.md +128 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/CONTRIBUTING.md +62 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/MIGRATION.md +295 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/images/hono-logo.png +0 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/images/hono-logo.pxm +0 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/images/hono-logo.svg +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/images/hono-title.png +0 -0
- package/tests/fixtures/corpus/oss-repos/hono/docs/images/hono-title.pxm +0 -0
- package/tests/fixtures/corpus/oss-repos/hono/jsr.json +119 -0
- package/tests/fixtures/corpus/oss-repos/hono/package.cjs.json +3 -0
- package/tests/fixtures/corpus/oss-repos/hono/package.json +650 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/aws-lambda/handler.ts +492 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/aws-lambda/index.ts +13 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/aws-lambda/types.ts +144 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/conninfo.ts +28 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/index.ts +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/serve-static.ts +35 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/server.ts +30 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/ssg.ts +27 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/bun/websocket.ts +110 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-pages/handler.ts +120 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-pages/index.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/conninfo.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/index.ts +8 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/serve-static-module.ts +12 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/serve-static.ts +39 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/utils.ts +50 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/cloudflare-workers/websocket.ts +50 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/conninfo.ts +17 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/deno.d.ts +28 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/index.ts +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/serve-static.ts +40 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/ssg.ts +27 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/deno/websocket.ts +51 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/lambda-edge/conninfo.ts +15 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/lambda-edge/handler.ts +189 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/lambda-edge/index.ts +14 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/netlify/handler.ts +10 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/netlify/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/netlify/mod.ts +1 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/service-worker/handler.ts +34 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/service-worker/index.ts +5 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/service-worker/types.ts +14 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/vercel/conninfo.ts +8 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/vercel/handler.ts +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/adapter/vercel/index.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/client/client.ts +214 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/client/index.ts +14 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/client/types.ts +180 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/client/utils.ts +54 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/compose.ts +94 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/context.ts +914 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/accepts/accepts.ts +81 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/accepts/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/adapter/index.ts +85 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/conninfo/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/conninfo/types.ts +45 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/cookie/index.ts +130 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/css/common.ts +243 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/css/index.ts +220 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/dev/index.ts +79 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/factory/index.ts +246 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/html/index.ts +56 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/ssg/index.ts +13 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/ssg/middleware.ts +79 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/ssg/ssg.ts +388 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/ssg/utils.ts +71 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/streaming/index.ts +9 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/streaming/sse.ts +89 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/streaming/stream.ts +36 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/streaming/text.ts +15 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/testing/index.ts +26 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/helper/websocket/index.ts +57 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/hono-base.ts +523 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/hono.ts +34 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/http-exception.ts +78 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/index.ts +51 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/base.ts +419 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/children.ts +20 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/components.ts +195 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/constants.ts +5 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/context.ts +50 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/client.ts +89 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/components.ts +39 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/context.ts +52 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/css.ts +246 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/hooks/index.ts +91 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/index.ts +159 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/intrinsic-element/components.ts +398 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/jsx-dev-runtime.ts +22 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/jsx-runtime.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/render.ts +772 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/server.ts +70 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/dom/utils.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/hooks/index.ts +426 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/index.ts +114 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/intrinsic-element/common.ts +11 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/intrinsic-element/components.ts +196 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/intrinsic-elements.ts +924 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/jsx-dev-runtime.ts +26 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/jsx-runtime.ts +18 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/streaming.ts +184 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/types.ts +41 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/jsx/utils.ts +36 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/basic-auth/index.ts +128 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/bearer-auth/index.ts +159 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/body-limit/index.ts +115 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/cache/index.ts +127 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/combine/index.ts +153 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/compress/index.ts +79 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/context-storage/index.ts +55 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/cors/index.ts +141 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/csrf/index.ts +90 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/etag/index.ts +88 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/ip-restriction/index.ts +178 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/jsx-renderer/index.ts +158 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/jwt/index.ts +8 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/jwt/jwt.ts +159 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/logger/index.ts +93 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/method-override/index.ts +146 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/powered-by/index.ts +13 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/pretty-json/index.ts +50 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/request-id/index.ts +8 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/request-id/request-id.ts +59 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/secure-headers/index.ts +8 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/secure-headers/permissions-policy.ts +86 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/secure-headers/secure-headers.ts +319 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/serve-static/index.ts +140 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/timeout/index.ts +58 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/timing/index.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/timing/timing.ts +225 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/middleware/trailing-slash/index.ts +71 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/preset/quick.ts +24 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/preset/tiny.ts +20 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/request.ts +403 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/linear-router/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/linear-router/router.ts +132 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/pattern-router/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/pattern-router/router.ts +54 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/reg-exp-router/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/reg-exp-router/node.ts +159 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/reg-exp-router/router.ts +274 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/reg-exp-router/trie.ts +74 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/smart-router/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/smart-router/router.ts +69 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/trie-router/index.ts +6 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/trie-router/node.ts +205 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router/trie-router/router.ts +28 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/router.ts +103 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/types.ts +2009 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/basic-auth.ts +26 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/body.ts +225 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/buffer.ts +65 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/color.ts +26 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/concurrent.ts +55 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/cookie.ts +230 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/crypto.ts +65 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/encode.ts +34 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/filepath.ts +56 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/handler.ts +15 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/html.ts +182 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/http-status.ts +69 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/ipaddr.ts +113 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/index.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/jwa.ts +23 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/jws.ts +226 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/jwt.ts +114 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/types.ts +83 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/jwt/utf8.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/mime.ts +142 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/stream.ts +96 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/types.ts +105 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/utils/url.ts +310 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/validator/index.ts +7 -0
- package/tests/fixtures/corpus/oss-repos/hono/src/validator/validator.ts +151 -0
- package/tests/fixtures/corpus/oss-repos/hono/tsconfig.build.json +23 -0
- package/tests/fixtures/corpus/oss-repos/hono/tsconfig.json +28 -0
- package/tests/fixtures/corpus/oss-repos/hono/vitest.config.ts +34 -0
- package/tests/fixtures/corpus/oss-repos/hono/yarn.lock +6232 -0
- package/tests/fixtures/documentation/api-reference.md +412 -0
- package/tests/fixtures/documentation/architecture.md +214 -0
- package/tests/fixtures/documentation/deployment-guide.md +420 -0
- package/tests/fixtures/github-readmes/express.md +133 -0
- package/tests/fixtures/github-readmes/nextjs.md +106 -0
- package/tests/fixtures/github-readmes/react.md +74 -0
- package/tests/fixtures/github-readmes/typescript.md +93 -0
- package/tests/fixtures/github-readmes/vite.md +79 -0
- package/tests/fixtures/queries/core.json +125 -0
- package/tests/fixtures/queries/extended.json +427 -0
- package/tests/fixtures/queries/generated/.gitkeep +0 -0
- package/tests/fixtures/test-server.ts +267 -0
- package/tests/helpers/performance-metrics.ts +387 -0
- package/tests/helpers/search-relevance.ts +381 -0
- package/tests/integration/cli-consistency.test.ts +299 -0
- package/tests/integration/cli.test.ts +69 -0
- package/tests/integration/e2e-workflow.test.ts +612 -0
- package/tests/integration/python-bridge.test.ts +183 -0
- package/tests/integration/search-quality.test.ts +718 -0
- package/tests/integration/stress.test.ts +326 -0
- package/tests/mcp/server.test.ts +15 -0
- package/tests/scripts/schemas/evaluation.json +44 -0
- package/tests/scripts/schemas/query-generation.json +21 -0
- package/tests/services/code-unit.service.test.ts +47 -0
- package/tests/services/search.progressive-context.test.ts +35 -0
- package/tsconfig.json +34 -0
- package/tsup.config.ts +15 -0
- package/turndown-plugin-gfm.d.ts +29 -0
- package/vitest.config.ts +79 -0
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* express
|
|
3
|
+
* Copyright(c) 2009-2013 TJ Holowaychuk
|
|
4
|
+
* Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Module dependencies.
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var contentDisposition = require('content-disposition');
|
|
16
|
+
var createError = require('http-errors')
|
|
17
|
+
var deprecate = require('depd')('express');
|
|
18
|
+
var encodeUrl = require('encodeurl');
|
|
19
|
+
var escapeHtml = require('escape-html');
|
|
20
|
+
var http = require('node:http');
|
|
21
|
+
var onFinished = require('on-finished');
|
|
22
|
+
var mime = require('mime-types')
|
|
23
|
+
var path = require('node:path');
|
|
24
|
+
var pathIsAbsolute = require('node:path').isAbsolute;
|
|
25
|
+
var statuses = require('statuses')
|
|
26
|
+
var sign = require('cookie-signature').sign;
|
|
27
|
+
var normalizeType = require('./utils').normalizeType;
|
|
28
|
+
var normalizeTypes = require('./utils').normalizeTypes;
|
|
29
|
+
var setCharset = require('./utils').setCharset;
|
|
30
|
+
var cookie = require('cookie');
|
|
31
|
+
var send = require('send');
|
|
32
|
+
var extname = path.extname;
|
|
33
|
+
var resolve = path.resolve;
|
|
34
|
+
var vary = require('vary');
|
|
35
|
+
const { Buffer } = require('node:buffer');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Response prototype.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
var res = Object.create(http.ServerResponse.prototype)
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Module exports.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
module.exports = res
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Set the HTTP status code for the response.
|
|
53
|
+
*
|
|
54
|
+
* Expects an integer value between 100 and 999 inclusive.
|
|
55
|
+
* Throws an error if the provided status code is not an integer or if it's outside the allowable range.
|
|
56
|
+
*
|
|
57
|
+
* @param {number} code - The HTTP status code to set.
|
|
58
|
+
* @return {ServerResponse} - Returns itself for chaining methods.
|
|
59
|
+
* @throws {TypeError} If `code` is not an integer.
|
|
60
|
+
* @throws {RangeError} If `code` is outside the range 100 to 999.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
res.status = function status(code) {
|
|
65
|
+
// Check if the status code is not an integer
|
|
66
|
+
if (!Number.isInteger(code)) {
|
|
67
|
+
throw new TypeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be an integer.`);
|
|
68
|
+
}
|
|
69
|
+
// Check if the status code is outside of Node's valid range
|
|
70
|
+
if (code < 100 || code > 999) {
|
|
71
|
+
throw new RangeError(`Invalid status code: ${JSON.stringify(code)}. Status code must be greater than 99 and less than 1000.`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.statusCode = code;
|
|
75
|
+
return this;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Set Link header field with the given `links`.
|
|
80
|
+
*
|
|
81
|
+
* Examples:
|
|
82
|
+
*
|
|
83
|
+
* res.links({
|
|
84
|
+
* next: 'http://api.example.com/users?page=2',
|
|
85
|
+
* last: 'http://api.example.com/users?page=5',
|
|
86
|
+
* pages: [
|
|
87
|
+
* 'http://api.example.com/users?page=1',
|
|
88
|
+
* 'http://api.example.com/users?page=2'
|
|
89
|
+
* ]
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* @param {Object} links
|
|
93
|
+
* @return {ServerResponse}
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
res.links = function(links) {
|
|
98
|
+
var link = this.get('Link') || '';
|
|
99
|
+
if (link) link += ', ';
|
|
100
|
+
return this.set('Link', link + Object.keys(links).map(function(rel) {
|
|
101
|
+
// Allow multiple links if links[rel] is an array
|
|
102
|
+
if (Array.isArray(links[rel])) {
|
|
103
|
+
return links[rel].map(function (singleLink) {
|
|
104
|
+
return `<${singleLink}>; rel="${rel}"`;
|
|
105
|
+
}).join(', ');
|
|
106
|
+
} else {
|
|
107
|
+
return `<${links[rel]}>; rel="${rel}"`;
|
|
108
|
+
}
|
|
109
|
+
}).join(', '));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Send a response.
|
|
114
|
+
*
|
|
115
|
+
* Examples:
|
|
116
|
+
*
|
|
117
|
+
* res.send(Buffer.from('wahoo'));
|
|
118
|
+
* res.send({ some: 'json' });
|
|
119
|
+
* res.send('<p>some html</p>');
|
|
120
|
+
*
|
|
121
|
+
* @param {string|number|boolean|object|Buffer} body
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
res.send = function send(body) {
|
|
126
|
+
var chunk = body;
|
|
127
|
+
var encoding;
|
|
128
|
+
var req = this.req;
|
|
129
|
+
var type;
|
|
130
|
+
|
|
131
|
+
// settings
|
|
132
|
+
var app = this.app;
|
|
133
|
+
|
|
134
|
+
switch (typeof chunk) {
|
|
135
|
+
// string defaulting to html
|
|
136
|
+
case 'string':
|
|
137
|
+
if (!this.get('Content-Type')) {
|
|
138
|
+
this.type('html');
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case 'boolean':
|
|
142
|
+
case 'number':
|
|
143
|
+
case 'object':
|
|
144
|
+
if (chunk === null) {
|
|
145
|
+
chunk = '';
|
|
146
|
+
} else if (ArrayBuffer.isView(chunk)) {
|
|
147
|
+
if (!this.get('Content-Type')) {
|
|
148
|
+
this.type('bin');
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
return this.json(chunk);
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// write strings in utf-8
|
|
157
|
+
if (typeof chunk === 'string') {
|
|
158
|
+
encoding = 'utf8';
|
|
159
|
+
type = this.get('Content-Type');
|
|
160
|
+
|
|
161
|
+
// reflect this in content-type
|
|
162
|
+
if (typeof type === 'string') {
|
|
163
|
+
this.set('Content-Type', setCharset(type, 'utf-8'));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// determine if ETag should be generated
|
|
168
|
+
var etagFn = app.get('etag fn')
|
|
169
|
+
var generateETag = !this.get('ETag') && typeof etagFn === 'function'
|
|
170
|
+
|
|
171
|
+
// populate Content-Length
|
|
172
|
+
var len
|
|
173
|
+
if (chunk !== undefined) {
|
|
174
|
+
if (Buffer.isBuffer(chunk)) {
|
|
175
|
+
// get length of Buffer
|
|
176
|
+
len = chunk.length
|
|
177
|
+
} else if (!generateETag && chunk.length < 1000) {
|
|
178
|
+
// just calculate length when no ETag + small chunk
|
|
179
|
+
len = Buffer.byteLength(chunk, encoding)
|
|
180
|
+
} else {
|
|
181
|
+
// convert chunk to Buffer and calculate
|
|
182
|
+
chunk = Buffer.from(chunk, encoding)
|
|
183
|
+
encoding = undefined;
|
|
184
|
+
len = chunk.length
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.set('Content-Length', len);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// populate ETag
|
|
191
|
+
var etag;
|
|
192
|
+
if (generateETag && len !== undefined) {
|
|
193
|
+
if ((etag = etagFn(chunk, encoding))) {
|
|
194
|
+
this.set('ETag', etag);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// freshness
|
|
199
|
+
if (req.fresh) this.status(304);
|
|
200
|
+
|
|
201
|
+
// strip irrelevant headers
|
|
202
|
+
if (204 === this.statusCode || 304 === this.statusCode) {
|
|
203
|
+
this.removeHeader('Content-Type');
|
|
204
|
+
this.removeHeader('Content-Length');
|
|
205
|
+
this.removeHeader('Transfer-Encoding');
|
|
206
|
+
chunk = '';
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// alter headers for 205
|
|
210
|
+
if (this.statusCode === 205) {
|
|
211
|
+
this.set('Content-Length', '0')
|
|
212
|
+
this.removeHeader('Transfer-Encoding')
|
|
213
|
+
chunk = ''
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (req.method === 'HEAD') {
|
|
217
|
+
// skip body for HEAD
|
|
218
|
+
this.end();
|
|
219
|
+
} else {
|
|
220
|
+
// respond
|
|
221
|
+
this.end(chunk, encoding);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return this;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Send JSON response.
|
|
229
|
+
*
|
|
230
|
+
* Examples:
|
|
231
|
+
*
|
|
232
|
+
* res.json(null);
|
|
233
|
+
* res.json({ user: 'tj' });
|
|
234
|
+
*
|
|
235
|
+
* @param {string|number|boolean|object} obj
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
res.json = function json(obj) {
|
|
240
|
+
// settings
|
|
241
|
+
var app = this.app;
|
|
242
|
+
var escape = app.get('json escape')
|
|
243
|
+
var replacer = app.get('json replacer');
|
|
244
|
+
var spaces = app.get('json spaces');
|
|
245
|
+
var body = stringify(obj, replacer, spaces, escape)
|
|
246
|
+
|
|
247
|
+
// content-type
|
|
248
|
+
if (!this.get('Content-Type')) {
|
|
249
|
+
this.set('Content-Type', 'application/json');
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return this.send(body);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Send JSON response with JSONP callback support.
|
|
257
|
+
*
|
|
258
|
+
* Examples:
|
|
259
|
+
*
|
|
260
|
+
* res.jsonp(null);
|
|
261
|
+
* res.jsonp({ user: 'tj' });
|
|
262
|
+
*
|
|
263
|
+
* @param {string|number|boolean|object} obj
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
res.jsonp = function jsonp(obj) {
|
|
268
|
+
// settings
|
|
269
|
+
var app = this.app;
|
|
270
|
+
var escape = app.get('json escape')
|
|
271
|
+
var replacer = app.get('json replacer');
|
|
272
|
+
var spaces = app.get('json spaces');
|
|
273
|
+
var body = stringify(obj, replacer, spaces, escape)
|
|
274
|
+
var callback = this.req.query[app.get('jsonp callback name')];
|
|
275
|
+
|
|
276
|
+
// content-type
|
|
277
|
+
if (!this.get('Content-Type')) {
|
|
278
|
+
this.set('X-Content-Type-Options', 'nosniff');
|
|
279
|
+
this.set('Content-Type', 'application/json');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// fixup callback
|
|
283
|
+
if (Array.isArray(callback)) {
|
|
284
|
+
callback = callback[0];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// jsonp
|
|
288
|
+
if (typeof callback === 'string' && callback.length !== 0) {
|
|
289
|
+
this.set('X-Content-Type-Options', 'nosniff');
|
|
290
|
+
this.set('Content-Type', 'text/javascript');
|
|
291
|
+
|
|
292
|
+
// restrict callback charset
|
|
293
|
+
callback = callback.replace(/[^\[\]\w$.]/g, '');
|
|
294
|
+
|
|
295
|
+
if (body === undefined) {
|
|
296
|
+
// empty argument
|
|
297
|
+
body = ''
|
|
298
|
+
} else if (typeof body === 'string') {
|
|
299
|
+
// replace chars not allowed in JavaScript that are in JSON
|
|
300
|
+
body = body
|
|
301
|
+
.replace(/\u2028/g, '\\u2028')
|
|
302
|
+
.replace(/\u2029/g, '\\u2029')
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
|
|
306
|
+
// the typeof check is just to reduce client error noise
|
|
307
|
+
body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return this.send(body);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Send given HTTP status code.
|
|
315
|
+
*
|
|
316
|
+
* Sets the response status to `statusCode` and the body of the
|
|
317
|
+
* response to the standard description from node's http.STATUS_CODES
|
|
318
|
+
* or the statusCode number if no description.
|
|
319
|
+
*
|
|
320
|
+
* Examples:
|
|
321
|
+
*
|
|
322
|
+
* res.sendStatus(200);
|
|
323
|
+
*
|
|
324
|
+
* @param {number} statusCode
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
res.sendStatus = function sendStatus(statusCode) {
|
|
329
|
+
var body = statuses.message[statusCode] || String(statusCode)
|
|
330
|
+
|
|
331
|
+
this.status(statusCode);
|
|
332
|
+
this.type('txt');
|
|
333
|
+
|
|
334
|
+
return this.send(body);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Transfer the file at the given `path`.
|
|
339
|
+
*
|
|
340
|
+
* Automatically sets the _Content-Type_ response header field.
|
|
341
|
+
* The callback `callback(err)` is invoked when the transfer is complete
|
|
342
|
+
* or when an error occurs. Be sure to check `res.headersSent`
|
|
343
|
+
* if you wish to attempt responding, as the header and some data
|
|
344
|
+
* may have already been transferred.
|
|
345
|
+
*
|
|
346
|
+
* Options:
|
|
347
|
+
*
|
|
348
|
+
* - `maxAge` defaulting to 0 (can be string converted by `ms`)
|
|
349
|
+
* - `root` root directory for relative filenames
|
|
350
|
+
* - `headers` object of headers to serve with file
|
|
351
|
+
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
|
|
352
|
+
*
|
|
353
|
+
* Other options are passed along to `send`.
|
|
354
|
+
*
|
|
355
|
+
* Examples:
|
|
356
|
+
*
|
|
357
|
+
* The following example illustrates how `res.sendFile()` may
|
|
358
|
+
* be used as an alternative for the `static()` middleware for
|
|
359
|
+
* dynamic situations. The code backing `res.sendFile()` is actually
|
|
360
|
+
* the same code, so HTTP cache support etc is identical.
|
|
361
|
+
*
|
|
362
|
+
* app.get('/user/:uid/photos/:file', function(req, res){
|
|
363
|
+
* var uid = req.params.uid
|
|
364
|
+
* , file = req.params.file;
|
|
365
|
+
*
|
|
366
|
+
* req.user.mayViewFilesFrom(uid, function(yes){
|
|
367
|
+
* if (yes) {
|
|
368
|
+
* res.sendFile('/uploads/' + uid + '/' + file);
|
|
369
|
+
* } else {
|
|
370
|
+
* res.send(403, 'Sorry! you cant see that.');
|
|
371
|
+
* }
|
|
372
|
+
* });
|
|
373
|
+
* });
|
|
374
|
+
*
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
res.sendFile = function sendFile(path, options, callback) {
|
|
379
|
+
var done = callback;
|
|
380
|
+
var req = this.req;
|
|
381
|
+
var res = this;
|
|
382
|
+
var next = req.next;
|
|
383
|
+
var opts = options || {};
|
|
384
|
+
|
|
385
|
+
if (!path) {
|
|
386
|
+
throw new TypeError('path argument is required to res.sendFile');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (typeof path !== 'string') {
|
|
390
|
+
throw new TypeError('path must be a string to res.sendFile')
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// support function as second arg
|
|
394
|
+
if (typeof options === 'function') {
|
|
395
|
+
done = options;
|
|
396
|
+
opts = {};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!opts.root && !pathIsAbsolute(path)) {
|
|
400
|
+
throw new TypeError('path must be absolute or specify root to res.sendFile');
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// create file stream
|
|
404
|
+
var pathname = encodeURI(path);
|
|
405
|
+
|
|
406
|
+
// wire application etag option to send
|
|
407
|
+
opts.etag = this.app.enabled('etag');
|
|
408
|
+
var file = send(req, pathname, opts);
|
|
409
|
+
|
|
410
|
+
// transfer
|
|
411
|
+
sendfile(res, file, opts, function (err) {
|
|
412
|
+
if (done) return done(err);
|
|
413
|
+
if (err && err.code === 'EISDIR') return next();
|
|
414
|
+
|
|
415
|
+
// next() all but write errors
|
|
416
|
+
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
|
|
417
|
+
next(err);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Transfer the file at the given `path` as an attachment.
|
|
424
|
+
*
|
|
425
|
+
* Optionally providing an alternate attachment `filename`,
|
|
426
|
+
* and optional callback `callback(err)`. The callback is invoked
|
|
427
|
+
* when the data transfer is complete, or when an error has
|
|
428
|
+
* occurred. Be sure to check `res.headersSent` if you plan to respond.
|
|
429
|
+
*
|
|
430
|
+
* Optionally providing an `options` object to use with `res.sendFile()`.
|
|
431
|
+
* This function will set the `Content-Disposition` header, overriding
|
|
432
|
+
* any `Content-Disposition` header passed as header options in order
|
|
433
|
+
* to set the attachment and filename.
|
|
434
|
+
*
|
|
435
|
+
* This method uses `res.sendFile()`.
|
|
436
|
+
*
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
|
|
440
|
+
res.download = function download (path, filename, options, callback) {
|
|
441
|
+
var done = callback;
|
|
442
|
+
var name = filename;
|
|
443
|
+
var opts = options || null
|
|
444
|
+
|
|
445
|
+
// support function as second or third arg
|
|
446
|
+
if (typeof filename === 'function') {
|
|
447
|
+
done = filename;
|
|
448
|
+
name = null;
|
|
449
|
+
opts = null
|
|
450
|
+
} else if (typeof options === 'function') {
|
|
451
|
+
done = options
|
|
452
|
+
opts = null
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// support optional filename, where options may be in it's place
|
|
456
|
+
if (typeof filename === 'object' &&
|
|
457
|
+
(typeof options === 'function' || options === undefined)) {
|
|
458
|
+
name = null
|
|
459
|
+
opts = filename
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// set Content-Disposition when file is sent
|
|
463
|
+
var headers = {
|
|
464
|
+
'Content-Disposition': contentDisposition(name || path)
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// merge user-provided headers
|
|
468
|
+
if (opts && opts.headers) {
|
|
469
|
+
var keys = Object.keys(opts.headers)
|
|
470
|
+
for (var i = 0; i < keys.length; i++) {
|
|
471
|
+
var key = keys[i]
|
|
472
|
+
if (key.toLowerCase() !== 'content-disposition') {
|
|
473
|
+
headers[key] = opts.headers[key]
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// merge user-provided options
|
|
479
|
+
opts = Object.create(opts)
|
|
480
|
+
opts.headers = headers
|
|
481
|
+
|
|
482
|
+
// Resolve the full path for sendFile
|
|
483
|
+
var fullPath = !opts.root
|
|
484
|
+
? resolve(path)
|
|
485
|
+
: path
|
|
486
|
+
|
|
487
|
+
// send file
|
|
488
|
+
return this.sendFile(fullPath, opts, done)
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Set _Content-Type_ response header with `type` through `mime.contentType()`
|
|
493
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
494
|
+
* When no mapping is found though `mime.contentType()`, the type is set to
|
|
495
|
+
* "application/octet-stream".
|
|
496
|
+
*
|
|
497
|
+
* Examples:
|
|
498
|
+
*
|
|
499
|
+
* res.type('.html');
|
|
500
|
+
* res.type('html');
|
|
501
|
+
* res.type('json');
|
|
502
|
+
* res.type('application/json');
|
|
503
|
+
* res.type('png');
|
|
504
|
+
*
|
|
505
|
+
* @param {String} type
|
|
506
|
+
* @return {ServerResponse} for chaining
|
|
507
|
+
* @public
|
|
508
|
+
*/
|
|
509
|
+
|
|
510
|
+
res.contentType =
|
|
511
|
+
res.type = function contentType(type) {
|
|
512
|
+
var ct = type.indexOf('/') === -1
|
|
513
|
+
? (mime.contentType(type) || 'application/octet-stream')
|
|
514
|
+
: type;
|
|
515
|
+
|
|
516
|
+
return this.set('Content-Type', ct);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Respond to the Acceptable formats using an `obj`
|
|
521
|
+
* of mime-type callbacks.
|
|
522
|
+
*
|
|
523
|
+
* This method uses `req.accepted`, an array of
|
|
524
|
+
* acceptable types ordered by their quality values.
|
|
525
|
+
* When "Accept" is not present the _first_ callback
|
|
526
|
+
* is invoked, otherwise the first match is used. When
|
|
527
|
+
* no match is performed the server responds with
|
|
528
|
+
* 406 "Not Acceptable".
|
|
529
|
+
*
|
|
530
|
+
* Content-Type is set for you, however if you choose
|
|
531
|
+
* you may alter this within the callback using `res.type()`
|
|
532
|
+
* or `res.set('Content-Type', ...)`.
|
|
533
|
+
*
|
|
534
|
+
* res.format({
|
|
535
|
+
* 'text/plain': function(){
|
|
536
|
+
* res.send('hey');
|
|
537
|
+
* },
|
|
538
|
+
*
|
|
539
|
+
* 'text/html': function(){
|
|
540
|
+
* res.send('<p>hey</p>');
|
|
541
|
+
* },
|
|
542
|
+
*
|
|
543
|
+
* 'application/json': function () {
|
|
544
|
+
* res.send({ message: 'hey' });
|
|
545
|
+
* }
|
|
546
|
+
* });
|
|
547
|
+
*
|
|
548
|
+
* In addition to canonicalized MIME types you may
|
|
549
|
+
* also use extnames mapped to these types:
|
|
550
|
+
*
|
|
551
|
+
* res.format({
|
|
552
|
+
* text: function(){
|
|
553
|
+
* res.send('hey');
|
|
554
|
+
* },
|
|
555
|
+
*
|
|
556
|
+
* html: function(){
|
|
557
|
+
* res.send('<p>hey</p>');
|
|
558
|
+
* },
|
|
559
|
+
*
|
|
560
|
+
* json: function(){
|
|
561
|
+
* res.send({ message: 'hey' });
|
|
562
|
+
* }
|
|
563
|
+
* });
|
|
564
|
+
*
|
|
565
|
+
* By default Express passes an `Error`
|
|
566
|
+
* with a `.status` of 406 to `next(err)`
|
|
567
|
+
* if a match is not made. If you provide
|
|
568
|
+
* a `.default` callback it will be invoked
|
|
569
|
+
* instead.
|
|
570
|
+
*
|
|
571
|
+
* @param {Object} obj
|
|
572
|
+
* @return {ServerResponse} for chaining
|
|
573
|
+
* @public
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
res.format = function(obj){
|
|
577
|
+
var req = this.req;
|
|
578
|
+
var next = req.next;
|
|
579
|
+
|
|
580
|
+
var keys = Object.keys(obj)
|
|
581
|
+
.filter(function (v) { return v !== 'default' })
|
|
582
|
+
|
|
583
|
+
var key = keys.length > 0
|
|
584
|
+
? req.accepts(keys)
|
|
585
|
+
: false;
|
|
586
|
+
|
|
587
|
+
this.vary("Accept");
|
|
588
|
+
|
|
589
|
+
if (key) {
|
|
590
|
+
this.set('Content-Type', normalizeType(key).value);
|
|
591
|
+
obj[key](req, this, next);
|
|
592
|
+
} else if (obj.default) {
|
|
593
|
+
obj.default(req, this, next)
|
|
594
|
+
} else {
|
|
595
|
+
next(createError(406, {
|
|
596
|
+
types: normalizeTypes(keys).map(function (o) { return o.value })
|
|
597
|
+
}))
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return this;
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
605
|
+
*
|
|
606
|
+
* @param {String} filename
|
|
607
|
+
* @return {ServerResponse}
|
|
608
|
+
* @public
|
|
609
|
+
*/
|
|
610
|
+
|
|
611
|
+
res.attachment = function attachment(filename) {
|
|
612
|
+
if (filename) {
|
|
613
|
+
this.type(extname(filename));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
this.set('Content-Disposition', contentDisposition(filename));
|
|
617
|
+
|
|
618
|
+
return this;
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Append additional header `field` with value `val`.
|
|
623
|
+
*
|
|
624
|
+
* Example:
|
|
625
|
+
*
|
|
626
|
+
* res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
|
|
627
|
+
* res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
|
|
628
|
+
* res.append('Warning', '199 Miscellaneous warning');
|
|
629
|
+
*
|
|
630
|
+
* @param {String} field
|
|
631
|
+
* @param {String|Array} val
|
|
632
|
+
* @return {ServerResponse} for chaining
|
|
633
|
+
* @public
|
|
634
|
+
*/
|
|
635
|
+
|
|
636
|
+
res.append = function append(field, val) {
|
|
637
|
+
var prev = this.get(field);
|
|
638
|
+
var value = val;
|
|
639
|
+
|
|
640
|
+
if (prev) {
|
|
641
|
+
// concat the new and prev vals
|
|
642
|
+
value = Array.isArray(prev) ? prev.concat(val)
|
|
643
|
+
: Array.isArray(val) ? [prev].concat(val)
|
|
644
|
+
: [prev, val]
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
return this.set(field, value);
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Set header `field` to `val`, or pass
|
|
652
|
+
* an object of header fields.
|
|
653
|
+
*
|
|
654
|
+
* Examples:
|
|
655
|
+
*
|
|
656
|
+
* res.set('Foo', ['bar', 'baz']);
|
|
657
|
+
* res.set('Accept', 'application/json');
|
|
658
|
+
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
659
|
+
*
|
|
660
|
+
* Aliased as `res.header()`.
|
|
661
|
+
*
|
|
662
|
+
* When the set header is "Content-Type", the type is expanded to include
|
|
663
|
+
* the charset if not present using `mime.contentType()`.
|
|
664
|
+
*
|
|
665
|
+
* @param {String|Object} field
|
|
666
|
+
* @param {String|Array} val
|
|
667
|
+
* @return {ServerResponse} for chaining
|
|
668
|
+
* @public
|
|
669
|
+
*/
|
|
670
|
+
|
|
671
|
+
res.set =
|
|
672
|
+
res.header = function header(field, val) {
|
|
673
|
+
if (arguments.length === 2) {
|
|
674
|
+
var value = Array.isArray(val)
|
|
675
|
+
? val.map(String)
|
|
676
|
+
: String(val);
|
|
677
|
+
|
|
678
|
+
// add charset to content-type
|
|
679
|
+
if (field.toLowerCase() === 'content-type') {
|
|
680
|
+
if (Array.isArray(value)) {
|
|
681
|
+
throw new TypeError('Content-Type cannot be set to an Array');
|
|
682
|
+
}
|
|
683
|
+
value = mime.contentType(value)
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
this.setHeader(field, value);
|
|
687
|
+
} else {
|
|
688
|
+
for (var key in field) {
|
|
689
|
+
this.set(key, field[key]);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return this;
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Get value for header `field`.
|
|
697
|
+
*
|
|
698
|
+
* @param {String} field
|
|
699
|
+
* @return {String}
|
|
700
|
+
* @public
|
|
701
|
+
*/
|
|
702
|
+
|
|
703
|
+
res.get = function(field){
|
|
704
|
+
return this.getHeader(field);
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Clear cookie `name`.
|
|
709
|
+
*
|
|
710
|
+
* @param {String} name
|
|
711
|
+
* @param {Object} [options]
|
|
712
|
+
* @return {ServerResponse} for chaining
|
|
713
|
+
* @public
|
|
714
|
+
*/
|
|
715
|
+
|
|
716
|
+
res.clearCookie = function clearCookie(name, options) {
|
|
717
|
+
// Force cookie expiration by setting expires to the past
|
|
718
|
+
const opts = { path: '/', ...options, expires: new Date(1)};
|
|
719
|
+
// ensure maxAge is not passed
|
|
720
|
+
delete opts.maxAge
|
|
721
|
+
|
|
722
|
+
return this.cookie(name, '', opts);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Set cookie `name` to `value`, with the given `options`.
|
|
727
|
+
*
|
|
728
|
+
* Options:
|
|
729
|
+
*
|
|
730
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
731
|
+
* - `signed` sign the cookie
|
|
732
|
+
* - `path` defaults to "/"
|
|
733
|
+
*
|
|
734
|
+
* Examples:
|
|
735
|
+
*
|
|
736
|
+
* // "Remember Me" for 15 minutes
|
|
737
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
738
|
+
*
|
|
739
|
+
* // same as above
|
|
740
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
741
|
+
*
|
|
742
|
+
* @param {String} name
|
|
743
|
+
* @param {String|Object} value
|
|
744
|
+
* @param {Object} [options]
|
|
745
|
+
* @return {ServerResponse} for chaining
|
|
746
|
+
* @public
|
|
747
|
+
*/
|
|
748
|
+
|
|
749
|
+
res.cookie = function (name, value, options) {
|
|
750
|
+
var opts = { ...options };
|
|
751
|
+
var secret = this.req.secret;
|
|
752
|
+
var signed = opts.signed;
|
|
753
|
+
|
|
754
|
+
if (signed && !secret) {
|
|
755
|
+
throw new Error('cookieParser("secret") required for signed cookies');
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
var val = typeof value === 'object'
|
|
759
|
+
? 'j:' + JSON.stringify(value)
|
|
760
|
+
: String(value);
|
|
761
|
+
|
|
762
|
+
if (signed) {
|
|
763
|
+
val = 's:' + sign(val, secret);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (opts.maxAge != null) {
|
|
767
|
+
var maxAge = opts.maxAge - 0
|
|
768
|
+
|
|
769
|
+
if (!isNaN(maxAge)) {
|
|
770
|
+
opts.expires = new Date(Date.now() + maxAge)
|
|
771
|
+
opts.maxAge = Math.floor(maxAge / 1000)
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
if (opts.path == null) {
|
|
776
|
+
opts.path = '/';
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
this.append('Set-Cookie', cookie.serialize(name, String(val), opts));
|
|
780
|
+
|
|
781
|
+
return this;
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Set the location header to `url`.
|
|
786
|
+
*
|
|
787
|
+
* The given `url` can also be "back", which redirects
|
|
788
|
+
* to the _Referrer_ or _Referer_ headers or "/".
|
|
789
|
+
*
|
|
790
|
+
* Examples:
|
|
791
|
+
*
|
|
792
|
+
* res.location('/foo/bar').;
|
|
793
|
+
* res.location('http://example.com');
|
|
794
|
+
* res.location('../login');
|
|
795
|
+
*
|
|
796
|
+
* @param {String} url
|
|
797
|
+
* @return {ServerResponse} for chaining
|
|
798
|
+
* @public
|
|
799
|
+
*/
|
|
800
|
+
|
|
801
|
+
res.location = function location(url) {
|
|
802
|
+
return this.set('Location', encodeUrl(url));
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Redirect to the given `url` with optional response `status`
|
|
807
|
+
* defaulting to 302.
|
|
808
|
+
*
|
|
809
|
+
* Examples:
|
|
810
|
+
*
|
|
811
|
+
* res.redirect('/foo/bar');
|
|
812
|
+
* res.redirect('http://example.com');
|
|
813
|
+
* res.redirect(301, 'http://example.com');
|
|
814
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
815
|
+
*
|
|
816
|
+
* @public
|
|
817
|
+
*/
|
|
818
|
+
|
|
819
|
+
res.redirect = function redirect(url) {
|
|
820
|
+
var address = url;
|
|
821
|
+
var body;
|
|
822
|
+
var status = 302;
|
|
823
|
+
|
|
824
|
+
// allow status / url
|
|
825
|
+
if (arguments.length === 2) {
|
|
826
|
+
status = arguments[0]
|
|
827
|
+
address = arguments[1]
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
if (!address) {
|
|
831
|
+
deprecate('Provide a url argument');
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
if (typeof address !== 'string') {
|
|
835
|
+
deprecate('Url must be a string');
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
if (typeof status !== 'number') {
|
|
839
|
+
deprecate('Status must be a number');
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// Set location header
|
|
843
|
+
address = this.location(address).get('Location');
|
|
844
|
+
|
|
845
|
+
// Support text/{plain,html} by default
|
|
846
|
+
this.format({
|
|
847
|
+
text: function(){
|
|
848
|
+
body = statuses.message[status] + '. Redirecting to ' + address
|
|
849
|
+
},
|
|
850
|
+
|
|
851
|
+
html: function(){
|
|
852
|
+
var u = escapeHtml(address);
|
|
853
|
+
body = '<p>' + statuses.message[status] + '. Redirecting to ' + u + '</p>'
|
|
854
|
+
},
|
|
855
|
+
|
|
856
|
+
default: function(){
|
|
857
|
+
body = '';
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
// Respond
|
|
862
|
+
this.status(status);
|
|
863
|
+
this.set('Content-Length', Buffer.byteLength(body));
|
|
864
|
+
|
|
865
|
+
if (this.req.method === 'HEAD') {
|
|
866
|
+
this.end();
|
|
867
|
+
} else {
|
|
868
|
+
this.end(body);
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Add `field` to Vary. If already present in the Vary set, then
|
|
874
|
+
* this call is simply ignored.
|
|
875
|
+
*
|
|
876
|
+
* @param {Array|String} field
|
|
877
|
+
* @return {ServerResponse} for chaining
|
|
878
|
+
* @public
|
|
879
|
+
*/
|
|
880
|
+
|
|
881
|
+
res.vary = function(field){
|
|
882
|
+
vary(this, field);
|
|
883
|
+
|
|
884
|
+
return this;
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Render `view` with the given `options` and optional callback `fn`.
|
|
889
|
+
* When a callback function is given a response will _not_ be made
|
|
890
|
+
* automatically, otherwise a response of _200_ and _text/html_ is given.
|
|
891
|
+
*
|
|
892
|
+
* Options:
|
|
893
|
+
*
|
|
894
|
+
* - `cache` boolean hinting to the engine it should cache
|
|
895
|
+
* - `filename` filename of the view being rendered
|
|
896
|
+
*
|
|
897
|
+
* @public
|
|
898
|
+
*/
|
|
899
|
+
|
|
900
|
+
res.render = function render(view, options, callback) {
|
|
901
|
+
var app = this.req.app;
|
|
902
|
+
var done = callback;
|
|
903
|
+
var opts = options || {};
|
|
904
|
+
var req = this.req;
|
|
905
|
+
var self = this;
|
|
906
|
+
|
|
907
|
+
// support callback function as second arg
|
|
908
|
+
if (typeof options === 'function') {
|
|
909
|
+
done = options;
|
|
910
|
+
opts = {};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// merge res.locals
|
|
914
|
+
opts._locals = self.locals;
|
|
915
|
+
|
|
916
|
+
// default callback to respond
|
|
917
|
+
done = done || function (err, str) {
|
|
918
|
+
if (err) return req.next(err);
|
|
919
|
+
self.send(str);
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// render
|
|
923
|
+
app.render(view, opts, done);
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// pipe the send file stream
|
|
927
|
+
function sendfile(res, file, options, callback) {
|
|
928
|
+
var done = false;
|
|
929
|
+
var streaming;
|
|
930
|
+
|
|
931
|
+
// request aborted
|
|
932
|
+
function onaborted() {
|
|
933
|
+
if (done) return;
|
|
934
|
+
done = true;
|
|
935
|
+
|
|
936
|
+
var err = new Error('Request aborted');
|
|
937
|
+
err.code = 'ECONNABORTED';
|
|
938
|
+
callback(err);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// directory
|
|
942
|
+
function ondirectory() {
|
|
943
|
+
if (done) return;
|
|
944
|
+
done = true;
|
|
945
|
+
|
|
946
|
+
var err = new Error('EISDIR, read');
|
|
947
|
+
err.code = 'EISDIR';
|
|
948
|
+
callback(err);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// errors
|
|
952
|
+
function onerror(err) {
|
|
953
|
+
if (done) return;
|
|
954
|
+
done = true;
|
|
955
|
+
callback(err);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// ended
|
|
959
|
+
function onend() {
|
|
960
|
+
if (done) return;
|
|
961
|
+
done = true;
|
|
962
|
+
callback();
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// file
|
|
966
|
+
function onfile() {
|
|
967
|
+
streaming = false;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// finished
|
|
971
|
+
function onfinish(err) {
|
|
972
|
+
if (err && err.code === 'ECONNRESET') return onaborted();
|
|
973
|
+
if (err) return onerror(err);
|
|
974
|
+
if (done) return;
|
|
975
|
+
|
|
976
|
+
setImmediate(function () {
|
|
977
|
+
if (streaming !== false && !done) {
|
|
978
|
+
onaborted();
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
if (done) return;
|
|
983
|
+
done = true;
|
|
984
|
+
callback();
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// streaming
|
|
989
|
+
function onstream() {
|
|
990
|
+
streaming = true;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
file.on('directory', ondirectory);
|
|
994
|
+
file.on('end', onend);
|
|
995
|
+
file.on('error', onerror);
|
|
996
|
+
file.on('file', onfile);
|
|
997
|
+
file.on('stream', onstream);
|
|
998
|
+
onFinished(res, onfinish);
|
|
999
|
+
|
|
1000
|
+
if (options.headers) {
|
|
1001
|
+
// set headers on successful transfer
|
|
1002
|
+
file.on('headers', function headers(res) {
|
|
1003
|
+
var obj = options.headers;
|
|
1004
|
+
var keys = Object.keys(obj);
|
|
1005
|
+
|
|
1006
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1007
|
+
var k = keys[i];
|
|
1008
|
+
res.setHeader(k, obj[k]);
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// pipe
|
|
1014
|
+
file.pipe(res);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Stringify JSON, like JSON.stringify, but v8 optimized, with the
|
|
1019
|
+
* ability to escape characters that can trigger HTML sniffing.
|
|
1020
|
+
*
|
|
1021
|
+
* @param {*} value
|
|
1022
|
+
* @param {function} replacer
|
|
1023
|
+
* @param {number} spaces
|
|
1024
|
+
* @param {boolean} escape
|
|
1025
|
+
* @returns {string}
|
|
1026
|
+
* @private
|
|
1027
|
+
*/
|
|
1028
|
+
|
|
1029
|
+
function stringify (value, replacer, spaces, escape) {
|
|
1030
|
+
// v8 checks arguments.length for optimizing simple call
|
|
1031
|
+
// https://bugs.chromium.org/p/v8/issues/detail?id=4730
|
|
1032
|
+
var json = replacer || spaces
|
|
1033
|
+
? JSON.stringify(value, replacer, spaces)
|
|
1034
|
+
: JSON.stringify(value);
|
|
1035
|
+
|
|
1036
|
+
if (escape && typeof json === 'string') {
|
|
1037
|
+
json = json.replace(/[<>&]/g, function (c) {
|
|
1038
|
+
switch (c.charCodeAt(0)) {
|
|
1039
|
+
case 0x3c:
|
|
1040
|
+
return '\\u003c'
|
|
1041
|
+
case 0x3e:
|
|
1042
|
+
return '\\u003e'
|
|
1043
|
+
case 0x26:
|
|
1044
|
+
return '\\u0026'
|
|
1045
|
+
/* istanbul ignore next: unreachable default */
|
|
1046
|
+
default:
|
|
1047
|
+
return c
|
|
1048
|
+
}
|
|
1049
|
+
})
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
return json
|
|
1053
|
+
}
|