wok-server 0.7.1 → 0.7.2

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.
@@ -90,7 +90,8 @@ async function postJson(opts) {
90
90
  timeout: opts.timeout,
91
91
  method: 'POST',
92
92
  body: JSON.stringify(opts.body),
93
- followRedirect: false
93
+ followRedirect: false,
94
+ agent: opts.agent
94
95
  });
95
96
  if (res.status !== 200) {
96
97
  if (res.body.byteLength < 1024) {
@@ -118,7 +119,8 @@ async function getJson(opts) {
118
119
  headers: opts.headers,
119
120
  timeout: opts.timeout,
120
121
  method: 'GET',
121
- followRedirect: true
122
+ followRedirect: true,
123
+ agent: opts.agent
122
124
  });
123
125
  if (res.status !== 200) {
124
126
  if (res.body.byteLength < 1024) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wok-server",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "packageManager": "pnpm@8.9.0",
5
5
  "description": "一个基于 NodeJs 和 TypeScript 的后端框架,轻量级、克制、简洁。A lightweight, restrained, and concise backend framework based on Node.js and TypeScript.",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
- import { IncomingHttpHeaders, request as requestHttp, Agent as HttpAgent } from 'http'
2
- import { request as requestHttps, Agent as HttpsAgent } from 'https'
1
+ import { Agent as HttpAgent, IncomingHttpHeaders, request as requestHttp } from 'http'
2
+ import { Agent as HttpsAgent, request as requestHttps } from 'https'
3
3
  import { URL } from 'url'
4
4
 
5
5
  /**
@@ -141,7 +141,7 @@ export function doRequest(opts: HttpRequestOpts): Promise<HttpResponseInfo> {
141
141
  * @param opts
142
142
  */
143
143
  export async function postJson<T>(
144
- opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'> & { body: any }
144
+ opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout' | 'agent'> & { body: unknown }
145
145
  ): Promise<T> {
146
146
  const headers = Object.assign({}, opts.headers || {}, {
147
147
  'Content-Type': 'application/json; charset=utf-8'
@@ -153,7 +153,8 @@ export async function postJson<T>(
153
153
  timeout: opts.timeout,
154
154
  method: 'POST',
155
155
  body: JSON.stringify(opts.body),
156
- followRedirect: false
156
+ followRedirect: false,
157
+ agent: opts.agent
157
158
  })
158
159
  if (res.status !== 200) {
159
160
  if (res.body.byteLength < 1024) {
@@ -178,7 +179,7 @@ export async function postJson<T>(
178
179
  * @param opts
179
180
  */
180
181
  export async function getJson<T>(
181
- opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'>
182
+ opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout' | 'agent'>
182
183
  ): Promise<T> {
183
184
  const res = await doRequest({
184
185
  url: opts.url,
@@ -186,7 +187,8 @@ export async function getJson<T>(
186
187
  headers: opts.headers,
187
188
  timeout: opts.timeout,
188
189
  method: 'GET',
189
- followRedirect: true
190
+ followRedirect: true,
191
+ agent: opts.agent
190
192
  })
191
193
  if (res.status !== 200) {
192
194
  if (res.body.byteLength < 1024) {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
- import { IncomingHttpHeaders, Agent as HttpAgent } from 'http';
4
+ import { Agent as HttpAgent, IncomingHttpHeaders } from 'http';
5
5
  import { Agent as HttpsAgent } from 'https';
6
6
  /**
7
7
  * 请求选项.
@@ -67,11 +67,11 @@ export declare function doRequest(opts: HttpRequestOpts): Promise<HttpResponseIn
67
67
  * 发送 json 格式的 post 请求,body 是未序列化的普通对象,表示要发送的请求数据.
68
68
  * @param opts
69
69
  */
70
- export declare function postJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'> & {
71
- body: any;
70
+ export declare function postJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout' | 'agent'> & {
71
+ body: unknown;
72
72
  }): Promise<T>;
73
73
  /**
74
74
  * get 请求获取 json 格式数据.
75
75
  * @param opts
76
76
  */
77
- export declare function getJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout'>): Promise<T>;
77
+ export declare function getJson<T>(opts: Pick<HttpRequestOpts, 'url' | 'query' | 'headers' | 'timeout' | 'agent'>): Promise<T>;