• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OtterJS / parsec / 10445234050

19 Aug 2024 12:54AM UTC coverage: 79.882% (+10.8%) from 69.063%
10445234050

push

github

Lordfirespeed
chore: skip empty test groups (for now)

90 of 131 branches covered (68.7%)

Branch coverage included in aggregate %.

180 of 207 relevant lines covered (86.96%)

9.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/utils/length-validator.ts
1
import stream from 'node:stream'
2
import { ClientError } from '@otterhttp/errors'
3

4
type LengthValidatorOptions = {
5
  expectedLength: number
6
}
7

8
export class LengthValidator extends stream.Transform {
9
  currentLength: number
10
  expectedLength: number
11

12
  constructor({ expectedLength }: LengthValidatorOptions) {
13
    super({ decodeStrings: true })
19✔
14
    this.expectedLength = expectedLength
19✔
15
    this.currentLength = 0
19✔
16
  }
17

18
  _transform(chunk: Buffer, encoding: BufferEncoding, callback: stream.TransformCallback): void {
19
    this.currentLength += chunk.byteLength
17✔
20
    if (this.currentLength > this.expectedLength) {
17✔
21
      return callback(
2✔
22
        new ClientError('Actual content length exceeded claimed content length', {
23
          statusCode: 400,
24
          code: 'ERR_CONTENT_LENGTH_EXCEEDED_CLAIM',
25
        }),
26
      )
27
    }
28
    callback(null, chunk)
15✔
29
  }
30

31
  _final(callback: (error?: Error | null) => void): void {
32
    if (this.currentLength !== this.expectedLength) {
17!
33
      return callback(
×
34
        new ClientError('Actual content length mismatched claimed content length', {
35
          statusCode: 400,
36
          code: 'ERR_CONTENT_LENGTH_MISMATCHED_CLAIM',
37
        }),
38
      )
39
    }
40
    callback(null)
17✔
41
  }
42
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc