11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { request } = require('http'); 61cb0ef41Sopenharmony_ciconst { Duplex } = require('stream'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_cilet socket; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction createConnection(...args) { 111cb0ef41Sopenharmony_ci socket = new Duplex({ 121cb0ef41Sopenharmony_ci read() {}, 131cb0ef41Sopenharmony_ci write(chunk, encoding, callback) { 141cb0ef41Sopenharmony_ci if (chunk.toString().includes('\r\n\r\n')) { 151cb0ef41Sopenharmony_ci this.push('HTTP/1.1 100 Continue\r\n\r\n'); 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci callback(); 191cb0ef41Sopenharmony_ci } 201cb0ef41Sopenharmony_ci }); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci return socket; 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ciconst req = request('http://localhost:8080', { createConnection }); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_cireq.on('information', common.mustCall(({ statusCode }) => { 281cb0ef41Sopenharmony_ci assert.strictEqual(statusCode, 100); 291cb0ef41Sopenharmony_ci socket.push('HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n'); 301cb0ef41Sopenharmony_ci socket.push(null); 311cb0ef41Sopenharmony_ci})); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_cireq.on('response', common.mustCall(({ statusCode }) => { 341cb0ef41Sopenharmony_ci assert.strictEqual(statusCode, 200); 351cb0ef41Sopenharmony_ci})); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_cireq.end(); 38