# @epilot/axios-large-response 中文文档

规范地址：https://npmcn.com/package/%40epilot/axios-large-response/

版本：0\.0\.3
npm 元数据更新时间：2026-11-10T09:27:53.593Z
中文译文更新时间：2026-11-13T19:42:07.063Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40epilot/axios-large-response
原文对照：https://npmcn.com/package/%40epilot/axios-large-response/?lang=original
项目主页：https://github.com/epilot-dev/aws-lambda-utility-middlewares/tree/main#readme
源码仓库：https://github.com/epilot-dev/aws-lambda-utility-middlewares#main

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：19.7 kB，5 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=14
- 运行依赖：0 个
- peer 依赖：axios \>=0\.25\.0
- 首次发布：2025-02-18T13:27:40.635Z
- 最新版本发布：2026-09-10T12:32:40.326Z
- 近 30 天下载量：17835（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 3 个）

## 中文简介

截取大响应的 Axios 插件

## 安装

```sh
npm install @epilot/axios-large-response
```

也可以使用：`pnpm add @epilot/axios-large-response`、`yarn add @epilot/axios-large-response`、`bun add @epilot/axios-large-response`

## README

# Axios 大型反应

[![@epilot/axios-large-response downloads](https://img.shields.io/npm/dm/@epilot/axios-large-response.svg?label=%40epilot%2Faxios-large-response)](https://www.npmjs.com/package/@epilot/axios-large-response)

一个Axios拦截器,设计用来处理大型响应. 默认情况下, 它假设您的后端使用 `@epilot/large-response-middleware`如本报告所述 [大型响应-中型软件](https://github.com/epilot-dev/aws-lambda-utility-middlewares/blob/main/packages/large-response-middleware/README.md)然而,它也支持自定义回调功能,从参考数据、自定义参考属性名称、信头和其他选项中获取大型有效载荷。 详情见下文.

它支持每个请求选项, 这样您就可以启用/ 禁用特定请求的截取器( 轴配置命名空间是 ) `axios-large-response` - 请检查一下 [使用量](https://npmcn.com/package/%40epilot/axios-large-response/#readme-usage) 详细情况请参见该节)。 目前,它默认是被禁用,然而,我们可以根据使用情况进行一些组合,例如,我们可以在全球范围禁用它,并在需要时按请求允许.

拦截器是 **默认禁用**,所以你需要明确启用它.

## 安装

```bash
pnpm add @epilot/axios-large-response
npm install @epilot/axios-large-response
yarn add @epilot/axios-large-response
```

## 使用量

```ts
import { axiosLargeResponse } from '@epilot/axios-large-response';
import axios from 'axios';

// Axios instance
const axiosInstance = axios.create();

// Example 1: disable interceptor globally so we enable it per-request
axiosLargeResponse(axiosInstance, {
  // enabled: false, -> disabled by default
  // ... other global options
});
...
const response = await axiosInstance.get('https://api.example.com/data', {
  'axios-large-response': {
    enabled: true,
    headerFlag: 'application/custom-large-response.vnd+json',
    refProperty: '$customRef',
    debug: true,
    onFetchLargePayloadFromRef: async (refUrl) => {
      // Custom handling for this specific request
      const response = await axios.get(refUrl);
      return response.data;
    }
  }
});

// Example 2: enable interceptor globally so we disable it per-request
axiosLargeResponse(axiosInstance, {
  enabled: true,
  // ... other global options
});
...
const response =  await axiosInstance.get('https://api.example.com/data', {
  'axios-large-response': {
    enabled: false
  }
});
```

## 不通过轴线发送的客户(`withLargeResponse`(中文(简体) )

截取器只运行通过轴适配器的请求. 配置有自身跑跑器的客户端绕过适配器,因此拦截器从未看到过这些请求- 运输有效载荷限制的响应以一个 `413`。最常见的案例是服务对服务电话,通过AWS Lambda 调用,与 `openapi-client-axios`' `registerRunner`。 。 。 .

`withLargeResponse` 包裹这样的跑者,并给予它与拦截器相同的行为:

```ts
import { withLargeResponse } from '@epilot/axios-large-response';
import { getLambdaRunner } from 'openapi-lambda-adapter';

client.api.registerRunner(
  withLargeResponse(getLambdaRunner(lambdaName, context), {
    enabled: true,
    // ... same options as the interceptor
  }),
);
```

跑者在结构上被描述 任何带有 `runRequest(request, ...rest)` 方法,其第一个参数是具有条件的物体,因此,它与AWS Lambda或任何特定的运输不相连。 HTTP 客户端,在流程中调用和测试将全部工作双倍,以及后继参数(例如 `openapi-client-axios`' `operation` 财务报告和审定财务报表 `context`)经过未受侵犯. 一揽子计划除此之外无依赖性 `axios` 由此而来.

每个请求选项在截取器上一样工作:设置在 `axios-large-response` 在请求中键,并且它们取代了全球性的。 在请求到达跑道之前 钥匙被剥了.

```ts
client.getThings({}, null, {
  'axios-large-response': { onFetchLargePayloadFromRef: myAuthenticatedFetch },
});
```

`enabled` 因此,上面例1的组合 -- -- 全球禁用,只允许需要的呼号 -- -- 也能对跑者起作用:

```ts
client.api.registerRunner(withLargeResponse(getLambdaRunner(lambdaName, context)));
...
client.getThings({}, null, {
  'axios-large-response': { enabled: true },
});
```

一个音符:

-   **被包裹的跑者保留了原作原型并拥有自有属性.** 这一点很重要: `openapi-client-axios` 引用注册跑道作为 `runner.runRequest(request, operation, runner.context)`,羊肉跑者读取目标函数名 `context`分类实例保留其方法和身份,以及 `runRequest` 保持与原始的绑定, 所以一个方法读取 `this` 还行 而不是重建它.

## 选项

| 名称 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| 启用 | 布尔 | 虚假 | 启用/ 禁用截取器 |
| 页眉旗 | 字符串 | “ 应用/ 大响应. vnd+json ” | 表示大型有效载荷参考响应的内容类型标题 |
| 财产 | 字符串 | “$活口量 ref” | 在回复中包含引用 URL 的属性名称 |
| 调试 | 布尔 | 虚假 | 启用调试日志 |
| 日志 | 对象 | 控制台 | 有调试、出错和警告方法的锁定对象 |
| 从参考文献中提取的 | 函数 | 获取参考 URL并返回全部有效载荷 | 回调函数从参考 URL 获取全部有效载荷 |
| 错误 | 未知/ 任意 | 未定义 | 如果找不到参考 URL 或出错, 返回错误的有效载荷 - 这将在响应数据中返回, 而不是丢出错误 。 除 `undefined` 计数为配置的, falsy 的(`null`, (中文(简体) ), `0`, (中文(简体) ), `''`, (中文(简体) ), `false`列入 |
| 禁用警告 | 布尔 | 虚假 | 禁用警告, 仅在选项中全球可用 |

为调试目的,您也可以设置 `AXIOS_INTERCEPTOR_LARGE_RESPONSE_DEBUG` 环境变量改为 `true` 或者说 `1` 以启用调试日志.

## 如何运作

1.  在请求中添加表示大有效载荷支持的适当接受信头;
2.  检测带有所配置标题内容类型的响应;
3.  如果答复中包含指定的参考物,则自动取出全部有效载荷;
4.  返回回复中的完整数据.

大型有效载荷的服务器响应示例:

```json
{
  "$payload_ref": "https://api.example.com/large-payloads/123"
}
```

在拦截器处理后,反应变为:

```json
{
  "huge": "data",
  "nested": {
    "complex": "structure"
  }
}
```

## 常见问题

### @epilot/axios-large-response 是什么？

截取大响应的 Axios 插件

### 如何安装 @epilot/axios-large-response？

在项目目录运行 npm install @epilot/axios-large-response，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：axios（\>=0\.25\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @epilot/axios-large-response 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @epilot/axios-large-response 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @epilot/axios-large-response 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=14。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @epilot/axios-large-response 可以商用吗？

@epilot/axios-large-response 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @epilot/axios-large-response 的下载量有多少？

根据 npm 官方下载统计，@epilot/axios-large-response 在 2026/10/14 – 2026/11/12 这 30 天内被下载 17,835 次，日均约 595 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @epilot/axios-large-response 还在维护吗？

最新版本 0\.0\.3 发布于 2026/09/10（2 个月前）；至今共发布 5 个版本，其中过去 12 个月发布了 3 个；首次发布于 2025/02/18。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

