sfml.js 1.0.0 → 1.1.0
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/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +40 -48
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/dist/network/http.js
CHANGED
|
@@ -279,7 +279,9 @@ class HttpRequest {
|
|
|
279
279
|
* @ja リクエストメソッドを設定します。
|
|
280
280
|
* @ko 요청 메서드를 설정합니다.
|
|
281
281
|
*/
|
|
282
|
-
setMethod(method) {
|
|
282
|
+
setMethod(method) {
|
|
283
|
+
this.method = (0, common_1.uint)(method, 4);
|
|
284
|
+
}
|
|
283
285
|
/**
|
|
284
286
|
* Set the URL-encoded path and query string, adding a leading slash
|
|
285
287
|
* if missing.
|
|
@@ -318,17 +320,21 @@ class HttpRequest {
|
|
|
318
320
|
}
|
|
319
321
|
[prepareRequest](host) {
|
|
320
322
|
const fields = new Map(this.fields);
|
|
321
|
-
if (!fields.has('host'))
|
|
323
|
+
if (!fields.has('host')) {
|
|
322
324
|
fields.set('host', host);
|
|
323
|
-
|
|
325
|
+
}
|
|
326
|
+
if (!fields.has('from')) {
|
|
324
327
|
fields.set('from', 'user@sfml-dev.org');
|
|
325
|
-
|
|
328
|
+
}
|
|
329
|
+
if (!fields.has('user-agent')) {
|
|
326
330
|
fields.set('user-agent', 'sfml.js');
|
|
331
|
+
}
|
|
327
332
|
if (!fields.has('content-length')) {
|
|
328
333
|
fields.set('content-length', String(this.body.length));
|
|
329
334
|
}
|
|
330
|
-
if (!fields.has('connection'))
|
|
335
|
+
if (!fields.has('connection')) {
|
|
331
336
|
fields.set('connection', 'close');
|
|
337
|
+
}
|
|
332
338
|
if (fields.has('transfer-encoding')) {
|
|
333
339
|
throw new TypeError('Request bodies use Content-Length framing');
|
|
334
340
|
}
|
|
@@ -339,8 +345,10 @@ class HttpRequest {
|
|
|
339
345
|
`HTTP/${this.major}.${this.minor}\r\n` +
|
|
340
346
|
[...fields].map(([key, value]) => `${key}: ${value}\r\n`).join('') +
|
|
341
347
|
'\r\n';
|
|
342
|
-
return {
|
|
343
|
-
|
|
348
|
+
return {
|
|
349
|
+
bytes: Buffer.concat([Buffer.from(header), this.body]),
|
|
350
|
+
head: this.method === HttpMethod.Head,
|
|
351
|
+
};
|
|
344
352
|
}
|
|
345
353
|
}
|
|
346
354
|
/**
|
|
@@ -383,42 +391,54 @@ class HttpResponse {
|
|
|
383
391
|
* @ko 대소문자를 구분하지 않는 이름으로 응답 헤더를 읽습니다.
|
|
384
392
|
* 없으면 빈 문자열을 반환합니다.
|
|
385
393
|
*/
|
|
386
|
-
getField(field) {
|
|
394
|
+
getField(field) {
|
|
395
|
+
return this.fields.get(field.toLowerCase()) ?? '';
|
|
396
|
+
}
|
|
387
397
|
/**
|
|
388
398
|
* Return the server status code or client error code.
|
|
389
399
|
* @zh 返回服务端状态码或客户端错误码。
|
|
390
400
|
* @ja サーバーの状態コードまたはクライアントのエラーコードを返します。
|
|
391
401
|
* @ko 서버 상태 코드 또는 클라이언트 오류 코드를 반환합니다.
|
|
392
402
|
*/
|
|
393
|
-
getStatus() {
|
|
403
|
+
getStatus() {
|
|
404
|
+
return this.status;
|
|
405
|
+
}
|
|
394
406
|
/**
|
|
395
407
|
* Return the response's HTTP major version.
|
|
396
408
|
* @zh 返回响应的 HTTP 主版本。
|
|
397
409
|
* @ja レスポンスの HTTP メジャーバージョンを返します。
|
|
398
410
|
* @ko 응답의 HTTP 주 버전을 반환합니다.
|
|
399
411
|
*/
|
|
400
|
-
getMajorHttpVersion() {
|
|
412
|
+
getMajorHttpVersion() {
|
|
413
|
+
return this.major;
|
|
414
|
+
}
|
|
401
415
|
/**
|
|
402
416
|
* Return the response's HTTP minor version.
|
|
403
417
|
* @zh 返回响应的 HTTP 次版本。
|
|
404
418
|
* @ja レスポンスの HTTP マイナーバージョンを返します。
|
|
405
419
|
* @ko 응답의 HTTP 부 버전을 반환합니다.
|
|
406
420
|
*/
|
|
407
|
-
getMinorHttpVersion() {
|
|
421
|
+
getMinorHttpVersion() {
|
|
422
|
+
return this.minor;
|
|
423
|
+
}
|
|
408
424
|
/**
|
|
409
425
|
* Decode the response body as a UTF-8 string.
|
|
410
426
|
* @zh 将响应体按 UTF-8 解码为字符串。
|
|
411
427
|
* @ja レスポンス本文を UTF-8 文字列として復号します。
|
|
412
428
|
* @ko 응답 본문을 UTF-8 문자열로 디코딩합니다.
|
|
413
429
|
*/
|
|
414
|
-
getBody() {
|
|
430
|
+
getBody() {
|
|
431
|
+
return this.body.toString('utf8');
|
|
432
|
+
}
|
|
415
433
|
/**
|
|
416
434
|
* Return an independent copy of the raw response body bytes.
|
|
417
435
|
* @zh 返回响应体原始字节的独立副本。
|
|
418
436
|
* @ja レスポンス本文の生バイトの独立したコピーを返します。
|
|
419
437
|
* @ko 응답 본문 원시 바이트의 독립적인 복사본을 반환합니다.
|
|
420
438
|
*/
|
|
421
|
-
getBodyBytes() {
|
|
439
|
+
getBodyBytes() {
|
|
440
|
+
return Uint8Array.from(this.body);
|
|
441
|
+
}
|
|
422
442
|
}
|
|
423
443
|
/**
|
|
424
444
|
* HTTP response status enumeration.
|
|
@@ -445,55 +465,69 @@ class ResponseParser {
|
|
|
445
465
|
this.done = false;
|
|
446
466
|
}
|
|
447
467
|
feed(data, ended = false) {
|
|
448
|
-
if (this.pending.length)
|
|
468
|
+
if (this.pending.length) {
|
|
449
469
|
this.pending = Buffer.concat([this.pending, data]);
|
|
450
|
-
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
451
472
|
this.pending = data;
|
|
473
|
+
}
|
|
452
474
|
if (!this.status) {
|
|
453
475
|
const end = this.pending.indexOf('\r\n\r\n');
|
|
454
476
|
if (end < 0) {
|
|
455
|
-
if (this.pending.length > 65536 || ended)
|
|
477
|
+
if (this.pending.length > 65536 || ended) {
|
|
456
478
|
throw new Error('Invalid header');
|
|
479
|
+
}
|
|
457
480
|
return undefined;
|
|
458
481
|
}
|
|
459
482
|
const lines = this.pending.toString('latin1', 0, end).split('\r\n');
|
|
460
483
|
const match = /^HTTP\/(\d+)\.(\d+) (\d{3})(?: |$)/.exec(lines.shift());
|
|
461
|
-
if (!match)
|
|
484
|
+
if (!match) {
|
|
462
485
|
throw new Error('Invalid HTTP status line');
|
|
486
|
+
}
|
|
463
487
|
this.major = Number(match[1]);
|
|
464
488
|
this.minor = Number(match[2]);
|
|
465
489
|
this.status = Number(match[3]);
|
|
466
|
-
for (const line of lines)
|
|
490
|
+
for (const line of lines) {
|
|
467
491
|
this.field(line);
|
|
492
|
+
}
|
|
468
493
|
this.pending = this.pending.subarray(end + 4);
|
|
469
494
|
if (this.status >= 100 && this.status < 200 && this.status !== 101) {
|
|
470
495
|
this.status = 0;
|
|
471
496
|
this.fields.clear();
|
|
472
497
|
return this.feed(Buffer.alloc(0), ended);
|
|
473
498
|
}
|
|
474
|
-
this.chunked =
|
|
475
|
-
.
|
|
476
|
-
|
|
477
|
-
|
|
499
|
+
this.chunked =
|
|
500
|
+
this.fields
|
|
501
|
+
.get('transfer-encoding')
|
|
502
|
+
?.toLowerCase()
|
|
503
|
+
.split(',')
|
|
504
|
+
.map(value => value.trim())
|
|
505
|
+
.includes('chunked') ?? false;
|
|
478
506
|
const length = this.fields.get('content-length');
|
|
479
507
|
if (!this.chunked && length !== undefined) {
|
|
480
|
-
if (!/^\d+$/.test(length))
|
|
508
|
+
if (!/^\d+$/.test(length)) {
|
|
481
509
|
throw new Error('Invalid Content-Length');
|
|
510
|
+
}
|
|
482
511
|
this.remaining = Number(length);
|
|
483
|
-
if (!Number.isSafeInteger(this.remaining) ||
|
|
512
|
+
if (!Number.isSafeInteger(this.remaining) ||
|
|
513
|
+
this.remaining > 67108864) {
|
|
484
514
|
throw new Error('HTTP body exceeds 64 MiB');
|
|
485
515
|
}
|
|
486
516
|
}
|
|
487
|
-
if (this.head ||
|
|
488
|
-
this.status ===
|
|
517
|
+
if (this.head ||
|
|
518
|
+
this.status === 204 ||
|
|
519
|
+
this.status === 304 ||
|
|
520
|
+
this.status === 101) {
|
|
489
521
|
this.done = true;
|
|
522
|
+
}
|
|
490
523
|
}
|
|
491
524
|
while (!this.done && this.pending.length) {
|
|
492
525
|
if (this.chunked) {
|
|
493
526
|
if (this.trailers) {
|
|
494
527
|
const end = this.pending.indexOf('\r\n');
|
|
495
|
-
if (end < 0)
|
|
528
|
+
if (end < 0) {
|
|
496
529
|
break;
|
|
530
|
+
}
|
|
497
531
|
if (end === 0) {
|
|
498
532
|
this.done = true;
|
|
499
533
|
break;
|
|
@@ -503,8 +537,9 @@ class ResponseParser {
|
|
|
503
537
|
continue;
|
|
504
538
|
}
|
|
505
539
|
if (this.chunkCrlf) {
|
|
506
|
-
if (this.pending.length < 2)
|
|
540
|
+
if (this.pending.length < 2) {
|
|
507
541
|
break;
|
|
542
|
+
}
|
|
508
543
|
if (this.pending.toString('latin1', 0, 2) !== '\r\n') {
|
|
509
544
|
throw new Error('Invalid chunk terminator');
|
|
510
545
|
}
|
|
@@ -513,11 +548,15 @@ class ResponseParser {
|
|
|
513
548
|
}
|
|
514
549
|
if (this.chunkRemaining === undefined) {
|
|
515
550
|
const end = this.pending.indexOf('\r\n');
|
|
516
|
-
if (end < 0)
|
|
551
|
+
if (end < 0) {
|
|
517
552
|
break;
|
|
518
|
-
|
|
519
|
-
|
|
553
|
+
}
|
|
554
|
+
const text = this.pending
|
|
555
|
+
.toString('latin1', 0, end)
|
|
556
|
+
.split(';')[0];
|
|
557
|
+
if (!/^[0-9a-f]+$/i.test(text)) {
|
|
520
558
|
throw new Error('Invalid chunk length');
|
|
559
|
+
}
|
|
521
560
|
this.chunkRemaining = parseInt(text, 16);
|
|
522
561
|
if (this.chunkRemaining > 67108864 - this.count) {
|
|
523
562
|
throw new Error('HTTP body exceeds 64 MiB');
|
|
@@ -541,40 +580,50 @@ class ResponseParser {
|
|
|
541
580
|
this.consume(count);
|
|
542
581
|
if (this.remaining !== undefined) {
|
|
543
582
|
this.remaining -= count;
|
|
544
|
-
if (!this.remaining)
|
|
583
|
+
if (!this.remaining) {
|
|
545
584
|
this.done = true;
|
|
585
|
+
}
|
|
546
586
|
}
|
|
547
587
|
}
|
|
548
588
|
}
|
|
549
|
-
if (this.remaining === 0 && !this.chunked)
|
|
589
|
+
if (this.remaining === 0 && !this.chunked) {
|
|
550
590
|
this.done = true;
|
|
551
|
-
|
|
591
|
+
}
|
|
592
|
+
if (this.pending.length > 65536) {
|
|
552
593
|
throw new Error('HTTP framing exceeds limit');
|
|
594
|
+
}
|
|
553
595
|
if (ended && !this.done) {
|
|
554
596
|
if (this.chunked || this.remaining !== undefined) {
|
|
555
597
|
throw new Error('Truncated HTTP response');
|
|
556
598
|
}
|
|
557
599
|
this.done = true;
|
|
558
600
|
}
|
|
559
|
-
return this.done
|
|
601
|
+
return this.done
|
|
602
|
+
? new HttpResponse(this.status, this.fields, Buffer.concat(this.chunks, this.count), this.major, this.minor)
|
|
603
|
+
: undefined;
|
|
560
604
|
}
|
|
561
605
|
consume(count) {
|
|
562
|
-
if (this.count + count > 67108864)
|
|
606
|
+
if (this.count + count > 67108864) {
|
|
563
607
|
throw new Error('HTTP body exceeds 64 MiB');
|
|
564
|
-
|
|
608
|
+
}
|
|
609
|
+
if (count) {
|
|
565
610
|
this.chunks.push(this.pending.subarray(0, count));
|
|
611
|
+
}
|
|
566
612
|
this.count += count;
|
|
567
613
|
this.pending = this.pending.subarray(count);
|
|
568
614
|
}
|
|
569
615
|
field(line) {
|
|
570
616
|
const split = line.indexOf(':');
|
|
571
|
-
if (split <= 0)
|
|
617
|
+
if (split <= 0) {
|
|
572
618
|
throw new Error('Invalid HTTP header field');
|
|
619
|
+
}
|
|
573
620
|
const name = line.slice(0, split).toLowerCase();
|
|
574
621
|
const value = line.slice(split + 1).trim();
|
|
575
|
-
if (name === 'content-length' &&
|
|
576
|
-
this.fields.
|
|
622
|
+
if (name === 'content-length' &&
|
|
623
|
+
this.fields.has(name) &&
|
|
624
|
+
this.fields.get(name) !== value) {
|
|
577
625
|
throw new Error('Conflicting lengths');
|
|
626
|
+
}
|
|
578
627
|
this.fields.set(name, value);
|
|
579
628
|
}
|
|
580
629
|
}
|
|
@@ -598,8 +647,9 @@ class Http {
|
|
|
598
647
|
* port가 0이면 URL 포트 또는 프로토콜 기본 포트를 유지합니다.
|
|
599
648
|
*/
|
|
600
649
|
constructor(host, port = 0, type) {
|
|
601
|
-
if (host !== undefined)
|
|
650
|
+
if (host !== undefined) {
|
|
602
651
|
this.setHost(host, port, type);
|
|
652
|
+
}
|
|
603
653
|
}
|
|
604
654
|
/**
|
|
605
655
|
* Set the server and optional IP address family, returning whether the
|
|
@@ -612,16 +662,20 @@ class Http {
|
|
|
612
662
|
*/
|
|
613
663
|
setHost(host, port = 0, type) {
|
|
614
664
|
(0, common_1.uint)(port, 65535);
|
|
615
|
-
if (type !== undefined)
|
|
665
|
+
if (type !== undefined) {
|
|
616
666
|
(0, common_1.uint)(type, 1);
|
|
617
|
-
|
|
667
|
+
}
|
|
668
|
+
if (typeof host !== 'string') {
|
|
618
669
|
throw new TypeError('Expected a hostname');
|
|
670
|
+
}
|
|
619
671
|
try {
|
|
620
672
|
const parsed = new URL(host.includes('://') ? host : `http://${host}`);
|
|
621
|
-
if (!['http:', 'https:'].includes(parsed.protocol))
|
|
673
|
+
if (!['http:', 'https:'].includes(parsed.protocol)) {
|
|
622
674
|
return false;
|
|
623
|
-
|
|
675
|
+
}
|
|
676
|
+
if (port) {
|
|
624
677
|
parsed.port = String(port);
|
|
678
|
+
}
|
|
625
679
|
this.host = parsed;
|
|
626
680
|
this.family = type;
|
|
627
681
|
return true;
|
|
@@ -659,37 +713,50 @@ class Http {
|
|
|
659
713
|
* @ko signal - 선택적 취소 신호. 취소 시 ConnectionFailed를 반환합니다.
|
|
660
714
|
*/
|
|
661
715
|
async sendRequest(request, timeout = time_1.Time.Zero, verifyServer = true, signal) {
|
|
662
|
-
if (!(request instanceof HttpRequest))
|
|
716
|
+
if (!(request instanceof HttpRequest)) {
|
|
663
717
|
throw new TypeError('Expected Request');
|
|
718
|
+
}
|
|
664
719
|
const milliseconds = (0, common_1.millisecondsOf)(timeout);
|
|
665
720
|
const host = this.host;
|
|
666
|
-
if (!host || signal?.aborted)
|
|
721
|
+
if (!host || signal?.aborted) {
|
|
667
722
|
return new HttpResponse();
|
|
723
|
+
}
|
|
668
724
|
const prepared = request[prepareRequest](host.host);
|
|
669
|
-
const options = {
|
|
725
|
+
const options = {
|
|
726
|
+
host: host.hostname.replace(/^\[|\]$/g, ''),
|
|
670
727
|
port: Number(host.port) || (host.protocol === 'https:' ? 443 : 80),
|
|
671
|
-
family: this.family === undefined
|
|
728
|
+
family: this.family === undefined
|
|
729
|
+
? 0
|
|
730
|
+
: this.family === ip_address_1.IpAddressType.IpV4
|
|
731
|
+
? 4
|
|
732
|
+
: 6,
|
|
733
|
+
};
|
|
672
734
|
return new Promise(resolve => {
|
|
673
735
|
let finished = false;
|
|
674
736
|
let timer;
|
|
675
737
|
const parser = new ResponseParser(prepared.head);
|
|
676
738
|
let socket;
|
|
677
739
|
const finish = (response = new HttpResponse()) => {
|
|
678
|
-
if (finished)
|
|
740
|
+
if (finished) {
|
|
679
741
|
return;
|
|
742
|
+
}
|
|
680
743
|
finished = true;
|
|
681
|
-
if (timer)
|
|
744
|
+
if (timer) {
|
|
682
745
|
clearTimeout(timer);
|
|
746
|
+
}
|
|
683
747
|
signal?.removeEventListener('abort', abort);
|
|
684
748
|
socket?.destroy();
|
|
685
749
|
resolve(response);
|
|
686
750
|
};
|
|
687
|
-
function abort() {
|
|
751
|
+
function abort() {
|
|
752
|
+
finish();
|
|
753
|
+
}
|
|
688
754
|
const receive = (data, ended = false) => {
|
|
689
755
|
try {
|
|
690
756
|
const response = parser.feed(data, ended);
|
|
691
|
-
if (response)
|
|
757
|
+
if (response) {
|
|
692
758
|
finish(response);
|
|
759
|
+
}
|
|
693
760
|
}
|
|
694
761
|
catch {
|
|
695
762
|
finish(new HttpResponse(HttpStatus.InvalidResponse));
|
|
@@ -703,15 +770,18 @@ class Http {
|
|
|
703
770
|
};
|
|
704
771
|
socket = (0, node_tls_1.connect)(secureOptions, () => socket.write(prepared.bytes));
|
|
705
772
|
}
|
|
706
|
-
else
|
|
773
|
+
else {
|
|
707
774
|
socket = (0, node_net_1.connect)(options, () => socket.write(prepared.bytes));
|
|
708
|
-
|
|
775
|
+
}
|
|
776
|
+
socket
|
|
777
|
+
.on('data', receive)
|
|
709
778
|
.on('end', () => receive(Buffer.alloc(0), true))
|
|
710
779
|
.on('error', () => finish())
|
|
711
780
|
.on('close', () => finish());
|
|
712
781
|
signal?.addEventListener('abort', abort, { once: true });
|
|
713
|
-
if (milliseconds)
|
|
782
|
+
if (milliseconds) {
|
|
714
783
|
timer = setTimeout(abort, milliseconds);
|
|
784
|
+
}
|
|
715
785
|
});
|
|
716
786
|
}
|
|
717
787
|
}
|
|
@@ -37,16 +37,22 @@ var IpAddressType;
|
|
|
37
37
|
*/
|
|
38
38
|
class IpAddress {
|
|
39
39
|
constructor(address, b, c, d) {
|
|
40
|
-
if (address instanceof IpAddress)
|
|
40
|
+
if (address instanceof IpAddress) {
|
|
41
41
|
this.data = Buffer.from(address.data);
|
|
42
|
+
}
|
|
42
43
|
else if (address instanceof Uint8Array) {
|
|
43
|
-
if (address.length !== 16)
|
|
44
|
+
if (address.length !== 16) {
|
|
44
45
|
throw new RangeError('IPv6 needs 16 bytes');
|
|
46
|
+
}
|
|
45
47
|
this.data = Buffer.from(address);
|
|
46
48
|
}
|
|
47
49
|
else if (b !== undefined) {
|
|
48
|
-
this.data = Buffer.from([
|
|
49
|
-
(0, common_1.uint)(
|
|
50
|
+
this.data = Buffer.from([
|
|
51
|
+
(0, common_1.uint)(address, 255),
|
|
52
|
+
(0, common_1.uint)(b, 255),
|
|
53
|
+
(0, common_1.uint)(c, 255),
|
|
54
|
+
(0, common_1.uint)(d, 255),
|
|
55
|
+
]);
|
|
50
56
|
}
|
|
51
57
|
else {
|
|
52
58
|
this.data = Buffer.alloc(4);
|
|
@@ -63,22 +69,27 @@ class IpAddress {
|
|
|
63
69
|
* 허용하지 않으며, 형식이 잘못되면 undefined를 반환합니다.
|
|
64
70
|
*/
|
|
65
71
|
static fromString(address) {
|
|
66
|
-
if (typeof address !== 'string')
|
|
72
|
+
if (typeof address !== 'string') {
|
|
67
73
|
throw new TypeError('Expected an IP string');
|
|
74
|
+
}
|
|
68
75
|
// SFML inet_pton rejects zone identifiers and non-canonical IPv4 forms.
|
|
69
76
|
const family = address.includes('%') ? 0 : (0, node_net_1.isIP)(address);
|
|
70
|
-
if (!family)
|
|
77
|
+
if (!family) {
|
|
71
78
|
return undefined;
|
|
79
|
+
}
|
|
72
80
|
// ipaddr.js normalizes ::a.b.c.d into ::ffff:a.b.c.d. SFML retains the
|
|
73
81
|
// original 128 bits, so expand the dotted suffix before parsing IPv6.
|
|
74
82
|
const normalized = family === 6
|
|
75
83
|
? address.replace(/(?:\d+\.){3}\d+$/, suffix => {
|
|
76
84
|
const octets = suffix.split('.').map(Number);
|
|
77
|
-
return (octets[0] * 256 + octets[1]).toString(16) +
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
return ((octets[0] * 256 + octets[1]).toString(16) +
|
|
86
|
+
':' +
|
|
87
|
+
(octets[2] * 256 + octets[3]).toString(16));
|
|
88
|
+
})
|
|
89
|
+
: address;
|
|
80
90
|
const data = Buffer.from(ipaddr.parse(normalized).toByteArray());
|
|
81
|
-
return family === 4
|
|
91
|
+
return family === 4
|
|
92
|
+
? new IpAddress(data.readUInt32BE())
|
|
82
93
|
: new IpAddress(data);
|
|
83
94
|
}
|
|
84
95
|
/**
|
|
@@ -92,8 +103,9 @@ class IpAddress {
|
|
|
92
103
|
*/
|
|
93
104
|
static async resolve(hostname) {
|
|
94
105
|
const literal = this.fromString(hostname);
|
|
95
|
-
if (literal)
|
|
106
|
+
if (literal) {
|
|
96
107
|
return literal;
|
|
108
|
+
}
|
|
97
109
|
const { resolve } = await Promise.resolve().then(() => require('./dns'));
|
|
98
110
|
return (await resolve(hostname))?.find(address => address.isV4());
|
|
99
111
|
}
|
|
@@ -129,23 +141,27 @@ class IpAddress {
|
|
|
129
141
|
* secure는 HTTPS를 사용하며, 실패 시 undefined를 반환합니다.
|
|
130
142
|
*/
|
|
131
143
|
static async getPublicAddress(timeout = time_1.Time.Zero, type = IpAddressType.IpV4, secure = false) {
|
|
132
|
-
if (type !== undefined)
|
|
144
|
+
if (type !== undefined) {
|
|
133
145
|
(0, common_1.uint)(type, 1);
|
|
146
|
+
}
|
|
134
147
|
if (!secure) {
|
|
135
148
|
const dns = await Promise.resolve().then(() => require('./dns'));
|
|
136
149
|
for (const family of type === undefined
|
|
137
|
-
? [IpAddressType.IpV6, IpAddressType.IpV4]
|
|
150
|
+
? [IpAddressType.IpV6, IpAddressType.IpV4]
|
|
151
|
+
: [type]) {
|
|
138
152
|
const address = await dns.getPublicAddress(timeout, family);
|
|
139
|
-
if (address)
|
|
153
|
+
if (address) {
|
|
140
154
|
return address;
|
|
155
|
+
}
|
|
141
156
|
}
|
|
142
157
|
}
|
|
143
158
|
const { Http } = await Promise.resolve().then(() => require('./http'));
|
|
144
159
|
for (const host of ['ifconfig.co', 'ifconfig.me', 'icanhazip.com']) {
|
|
145
160
|
const client = new Http(`${secure ? 'https' : 'http'}://${host}`, 0, type);
|
|
146
161
|
const response = await client.sendRequest(new Http.Request('/ip'), timeout, secure);
|
|
147
|
-
if (response.getStatus() !== 200)
|
|
162
|
+
if (response.getStatus() !== 200) {
|
|
148
163
|
continue;
|
|
164
|
+
}
|
|
149
165
|
const address = this.fromString(response.getBody().trim());
|
|
150
166
|
if (address && (type === undefined || address.getType() === type)) {
|
|
151
167
|
return address;
|
|
@@ -160,13 +176,15 @@ class IpAddress {
|
|
|
160
176
|
* @ko 점으로 구분한 십진수 IPv4 또는 압축된 IPv6 텍스트를 반환합니다.
|
|
161
177
|
*/
|
|
162
178
|
toString() {
|
|
163
|
-
if (this.isV4())
|
|
179
|
+
if (this.isV4()) {
|
|
164
180
|
return [...this.data].join('.');
|
|
181
|
+
}
|
|
165
182
|
const compatible = this.data.subarray(0, 12).every(byte => byte === 0);
|
|
166
183
|
const mapped = this.data.subarray(0, 10).every(byte => byte === 0) &&
|
|
167
|
-
this.data[10] === 255 &&
|
|
184
|
+
this.data[10] === 255 &&
|
|
185
|
+
this.data[11] === 255;
|
|
168
186
|
if (mapped || (compatible && (this.data[12] || this.data[13]))) {
|
|
169
|
-
return (mapped ? '::ffff:' : '::') + [...this.data.subarray(12)].join('.');
|
|
187
|
+
return ((mapped ? '::ffff:' : '::') + [...this.data.subarray(12)].join('.'));
|
|
170
188
|
}
|
|
171
189
|
return ipaddr.fromByteArray([...this.data]).toString();
|
|
172
190
|
}
|
|
@@ -180,8 +198,9 @@ class IpAddress {
|
|
|
180
198
|
* IPv6 주소이면 TypeError를 던집니다.
|
|
181
199
|
*/
|
|
182
200
|
toInteger() {
|
|
183
|
-
if (!this.isV4())
|
|
201
|
+
if (!this.isV4()) {
|
|
184
202
|
throw new TypeError('Expected an IPv4 address');
|
|
203
|
+
}
|
|
185
204
|
return this.data.readUInt32BE();
|
|
186
205
|
}
|
|
187
206
|
/**
|
|
@@ -193,8 +212,9 @@ class IpAddress {
|
|
|
193
212
|
* IPv4 주소이면 TypeError를 던집니다.
|
|
194
213
|
*/
|
|
195
214
|
toBytes() {
|
|
196
|
-
if (!this.isV6())
|
|
215
|
+
if (!this.isV6()) {
|
|
197
216
|
throw new TypeError('Expected an IPv6 address');
|
|
217
|
+
}
|
|
198
218
|
return Uint8Array.from(this.data);
|
|
199
219
|
}
|
|
200
220
|
/**
|
|
@@ -212,14 +232,18 @@ class IpAddress {
|
|
|
212
232
|
* @ja IPv4 アドレスかどうかを返します。
|
|
213
233
|
* @ko IPv4 주소인지 반환합니다.
|
|
214
234
|
*/
|
|
215
|
-
isV4() {
|
|
235
|
+
isV4() {
|
|
236
|
+
return this.data.length === 4;
|
|
237
|
+
}
|
|
216
238
|
/**
|
|
217
239
|
* Return whether this is an IPv6 address.
|
|
218
240
|
* @zh 返回是否为 IPv6 地址。
|
|
219
241
|
* @ja IPv6 アドレスかどうかを返します。
|
|
220
242
|
* @ko IPv6 주소인지 반환합니다.
|
|
221
243
|
*/
|
|
222
|
-
isV6() {
|
|
244
|
+
isV6() {
|
|
245
|
+
return this.data.length === 16;
|
|
246
|
+
}
|
|
223
247
|
/**
|
|
224
248
|
* Compare by address family then address bytes;
|
|
225
249
|
* return a negative number, zero, or a positive number.
|
|
@@ -229,10 +253,11 @@ class IpAddress {
|
|
|
229
253
|
* @ko 주소 계열, 주소 바이트 순서로 비교하며 음수, 0 또는 양수를 반환합니다.
|
|
230
254
|
*/
|
|
231
255
|
compare(other) {
|
|
232
|
-
if (!(other instanceof IpAddress))
|
|
256
|
+
if (!(other instanceof IpAddress)) {
|
|
233
257
|
throw new TypeError('Expected IpAddress');
|
|
234
|
-
|
|
235
|
-
|
|
258
|
+
}
|
|
259
|
+
return (this.data.length - other.data.length ||
|
|
260
|
+
Buffer.compare(this.data, other.data));
|
|
236
261
|
}
|
|
237
262
|
}
|
|
238
263
|
/**
|