Skip to content

Commit 3782a00

Browse files
committed
Less magic numbers, use constant for frame_max setting
1 parent 2416539 commit 3782a00

5 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/amqp-base-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AMQPView } from "./amqp-view.js"
66
import type { Logger } from "./types.js"
77

88
export const VERSION = "3.4.1"
9+
export const MIN_FRAME_SIZE = 4096 // 8192
910

1011
/**
1112
* Base class for AMQPClients.
@@ -44,7 +45,7 @@ export abstract class AMQPBaseClient {
4445
password: string,
4546
name?: string,
4647
platform?: string,
47-
frameMax = 8192,
48+
frameMax = MIN_FRAME_SIZE,
4849
heartbeat = 0,
4950
channelMax = 0,
5051
logger?: Logger | null,
@@ -61,7 +62,7 @@ export abstract class AMQPBaseClient {
6162
this.logger = logger || undefined
6263
this.channels = [new AMQPChannel(this, 0)]
6364
this.onerror = (error: AMQPError) => this.logger?.error("amqp-client connection closed", error.message)
64-
if (frameMax < 8192) throw new Error("frameMax must be 8192 or larger")
65+
if (frameMax < MIN_FRAME_SIZE) throw new Error(`frameMax must be ${MIN_FRAME_SIZE} or larger`)
6566
this.frameMax = frameMax
6667
if (heartbeat < 0) throw new Error("heartbeat must be positive")
6768
this.heartbeat = heartbeat

src/amqp-socket-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AMQPBaseClient } from "./amqp-base-client.js"
1+
import { AMQPBaseClient, MIN_FRAME_SIZE } from "./amqp-base-client.js"
22
import { AMQPError } from "./amqp-error.js"
33
import type { AMQPTlsOptions } from "./amqp-tls-options.js"
44
import type { Logger } from "./types.js"
@@ -32,7 +32,7 @@ export class AMQPClient extends AMQPBaseClient {
3232
const username = decodeURIComponent(u.username) || "guest"
3333
const password = decodeURIComponent(u.password) || "guest"
3434
const name = u.searchParams.get("name") || ""
35-
const frameMax = parseInt(u.searchParams.get("frameMax") || "8192")
35+
const frameMax = parseInt(u.searchParams.get("frameMax") || MIN_FRAME_SIZE.toString())
3636
const heartbeat = parseInt(u.searchParams.get("heartbeat") || "0")
3737
const channelMax = parseInt(u.searchParams.get("channelMax") || "0")
3838
const platform = `${process.release.name} ${process.version} ${process.platform} ${process.arch}`

src/amqp-websocket-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AMQPBaseClient, VERSION } from "./amqp-base-client.js"
1+
import { AMQPBaseClient, VERSION, MIN_FRAME_SIZE } from "./amqp-base-client.js"
22
import { AMQPView } from "./amqp-view.js"
33
import { AMQPError } from "./amqp-error.js"
44
import { AMQPChannel } from "./amqp-channel.js"
@@ -49,7 +49,7 @@ export class AMQPWebSocketClient extends AMQPBaseClient {
4949
username = "guest",
5050
password = "guest",
5151
name?: string,
52-
frameMax = 8192,
52+
frameMax = MIN_FRAME_SIZE,
5353
heartbeat = 0,
5454
logger?: Logger | null,
5555
) {

test-browser/websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ test("onerror is not called when conn is closed by client", async () => {
705705
})
706706

707707
test("will throw on too large headers", async () => {
708-
const amqp = getNewClient({ frameMax: 8192 })
708+
const amqp = getNewClient()
709709
const conn = await amqp.connect()
710710
const ch = await conn.channel()
711711
await expect(
@@ -717,7 +717,7 @@ test("will throw on too large headers", async () => {
717717
})
718718

719719
test("will split body over multiple frames", async () => {
720-
const amqp = getNewClient({ frameMax: 8192 })
720+
const amqp = getNewClient()
721721
const conn = await amqp.connect()
722722
const ch = await conn.channel()
723723
const q = await ch.queue("")

test/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ test("onerror is not called when conn is closed by client", async () => {
786786
})
787787

788788
test("will throw on too large headers", async () => {
789-
const amqp = getNewClient({ frameMax: 8192 })
789+
const amqp = getNewClient()
790790
const conn = await amqp.connect()
791791
const ch = await conn.channel()
792792
await expect(
@@ -798,7 +798,7 @@ test("will throw on too large headers", async () => {
798798
})
799799

800800
test("will split body over multiple frames", async () => {
801-
const amqp = getNewClient({ frameMax: 8192 })
801+
const amqp = getNewClient()
802802
const conn = await amqp.connect()
803803
const ch = await conn.channel()
804804
const q = await ch.queue("")

0 commit comments

Comments
 (0)