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

OtterJS / parsec / 10444328288

18 Aug 2024 10:43PM UTC coverage: 74.516% (+13.5%) from 60.967%
10444328288

push

github

Lordfirespeed
refactor: remove dependency on `raw-body`

71 of 113 branches covered (62.83%)

Branch coverage included in aggregate %.

47 of 55 new or added lines in 6 files covered. (85.45%)

160 of 197 relevant lines covered (81.22%)

3.63 hits per line

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

71.43
/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 })
8✔
14
    this.expectedLength = expectedLength
8✔
15
    this.currentLength = 0
8✔
16
  }
17

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

29
  _final(callback: (error?: Error | null) => void): void {
30
    if (this.currentLength !== this.expectedLength) {
8!
NEW
31
      return callback(new ClientError('Actual content length mismatched claimed content length', {
×
32
        statusCode: 400,
33
        code: "ERR_CONTENT_LENGTH_MISMATCHED_CLAIM"
34
      }))
35
    }
36
    callback(null)
8✔
37
  }
38
}
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