11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst http = require('http');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Verify that after calling end() on an `OutgoingMessage` (or a type that
71cb0ef41Sopenharmony_ci// inherits from `OutgoingMessage`), its `writable` property is not set to false
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall(function(req, res) {
101cb0ef41Sopenharmony_ci  assert.strictEqual(res.writable, true);
111cb0ef41Sopenharmony_ci  assert.strictEqual(res.finished, false);
121cb0ef41Sopenharmony_ci  assert.strictEqual(res.writableEnded, false);
131cb0ef41Sopenharmony_ci  res.end();
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  // res.writable is set to false after it has finished sending
161cb0ef41Sopenharmony_ci  // Ref: https://github.com/nodejs/node/issues/15029
171cb0ef41Sopenharmony_ci  assert.strictEqual(res.writable, true);
181cb0ef41Sopenharmony_ci  assert.strictEqual(res.finished, true);
191cb0ef41Sopenharmony_ci  assert.strictEqual(res.writableEnded, true);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  server.close();
221cb0ef41Sopenharmony_ci}));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciserver.listen(0);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciserver.on('listening', common.mustCall(function() {
271cb0ef41Sopenharmony_ci  const clientRequest = http.request({
281cb0ef41Sopenharmony_ci    port: server.address().port,
291cb0ef41Sopenharmony_ci    method: 'GET',
301cb0ef41Sopenharmony_ci    path: '/'
311cb0ef41Sopenharmony_ci  });
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  assert.strictEqual(clientRequest.writable, true);
341cb0ef41Sopenharmony_ci  clientRequest.end();
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  // Writable is still true when close
371cb0ef41Sopenharmony_ci  // THIS IS LEGACY, we cannot change it
381cb0ef41Sopenharmony_ci  // unless we break error detection
391cb0ef41Sopenharmony_ci  assert.strictEqual(clientRequest.writable, true);
401cb0ef41Sopenharmony_ci}));
41