11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst http = require('http');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cifunction shouldThrowOnMoreBytes() {
81cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
91cb0ef41Sopenharmony_ci    res.strictContentLength = true;
101cb0ef41Sopenharmony_ci    res.setHeader('Content-Length', 5);
111cb0ef41Sopenharmony_ci    res.write('hello');
121cb0ef41Sopenharmony_ci    assert.throws(() => {
131cb0ef41Sopenharmony_ci      res.write('a');
141cb0ef41Sopenharmony_ci    }, {
151cb0ef41Sopenharmony_ci      code: 'ERR_HTTP_CONTENT_LENGTH_MISMATCH'
161cb0ef41Sopenharmony_ci    });
171cb0ef41Sopenharmony_ci    res.statusCode = 200;
181cb0ef41Sopenharmony_ci    res.end();
191cb0ef41Sopenharmony_ci  }));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  server.listen(0, () => {
221cb0ef41Sopenharmony_ci    const req = http.get({
231cb0ef41Sopenharmony_ci      port: server.address().port,
241cb0ef41Sopenharmony_ci    }, common.mustCall((res) => {
251cb0ef41Sopenharmony_ci      res.resume();
261cb0ef41Sopenharmony_ci      assert.strictEqual(res.statusCode, 200);
271cb0ef41Sopenharmony_ci      server.close();
281cb0ef41Sopenharmony_ci    }));
291cb0ef41Sopenharmony_ci    req.end();
301cb0ef41Sopenharmony_ci  });
311cb0ef41Sopenharmony_ci}
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_cifunction shouldNotThrow() {
341cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
351cb0ef41Sopenharmony_ci    res.strictContentLength = true;
361cb0ef41Sopenharmony_ci    res.write('helloaa');
371cb0ef41Sopenharmony_ci    res.statusCode = 200;
381cb0ef41Sopenharmony_ci    res.end('ending');
391cb0ef41Sopenharmony_ci  }));
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  server.listen(0, () => {
421cb0ef41Sopenharmony_ci    http.get({
431cb0ef41Sopenharmony_ci      port: server.address().port,
441cb0ef41Sopenharmony_ci    }, common.mustCall((res) => {
451cb0ef41Sopenharmony_ci      res.resume();
461cb0ef41Sopenharmony_ci      assert.strictEqual(res.statusCode, 200);
471cb0ef41Sopenharmony_ci      server.close();
481cb0ef41Sopenharmony_ci    }));
491cb0ef41Sopenharmony_ci  });
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_cifunction shouldThrowOnFewerBytes() {
541cb0ef41Sopenharmony_ci  const server = http.createServer(common.mustCall((req, res) => {
551cb0ef41Sopenharmony_ci    res.strictContentLength = true;
561cb0ef41Sopenharmony_ci    res.setHeader('Content-Length', 5);
571cb0ef41Sopenharmony_ci    res.write('a');
581cb0ef41Sopenharmony_ci    res.statusCode = 200;
591cb0ef41Sopenharmony_ci    assert.throws(() => {
601cb0ef41Sopenharmony_ci      res.end('aaa');
611cb0ef41Sopenharmony_ci    }, {
621cb0ef41Sopenharmony_ci      code: 'ERR_HTTP_CONTENT_LENGTH_MISMATCH'
631cb0ef41Sopenharmony_ci    });
641cb0ef41Sopenharmony_ci    res.end('aaaa');
651cb0ef41Sopenharmony_ci  }));
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  server.listen(0, () => {
681cb0ef41Sopenharmony_ci    http.get({
691cb0ef41Sopenharmony_ci      port: server.address().port,
701cb0ef41Sopenharmony_ci    }, common.mustCall((res) => {
711cb0ef41Sopenharmony_ci      res.resume();
721cb0ef41Sopenharmony_ci      assert.strictEqual(res.statusCode, 200);
731cb0ef41Sopenharmony_ci      server.close();
741cb0ef41Sopenharmony_ci    }));
751cb0ef41Sopenharmony_ci  });
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_cishouldThrowOnMoreBytes();
791cb0ef41Sopenharmony_cishouldNotThrow();
801cb0ef41Sopenharmony_cishouldThrowOnFewerBytes();
81