import type http from 'http' ; import type { Socket } from 'net' ; import { Callback , HeadersObject } from '../../_internal/types' ; import { Writable } from '../stream/writable' ; export class ServerResponse extends Writable implements http . ServerResponse { statusCode : number = 200 ; statusMessage : string = '' ; upgrading : boolean = false ; chunkedEncoding : boolean = false ; shouldKeepAlive : boolean = false ; useChunkedEncodingByDefault : boolean = false ; sendDate : boolean = false ; finished : boolean = false ; headersSent : boolean = false ; connection : Socket | null = null ; socket : Socket | null = null ; req : http . IncomingMessage ; _headers : HeadersObject = { } ; constructor ( req ) { super ( ) ; this . req = req ; } assignSocket ( socket ) { socket . _httpMessage = this ; this . socket = socket ; this . connection = socket ; this . emit ( 'socket' , socket ) ; this . _flush ( ) ; } _flush ( ) { this . flushHeaders ( ) ; } detachSocket ( _socket ) { } writeContinue ( _callback ? ) { } writeHead ( statusCode , arg1 ? , arg2 ? ) { if ( statusCode ) { this . statusCode = statusCode ; } if ( typeof arg1 === 'string' ) { this . statusMessage = arg1 ; arg1 = undefined ; } const headers = arg2 || arg1 ; if ( headers ) { if ( Array . isArray ( headers ) ) { } else { for ( const key in headers ) { this . setHeader ( key , headers [ key ] ) ; } } } this . headersSent = true ; return this ; } writeProcessing ( ) { } setTimeout ( _msecs , _callback ? ) { return this ; } setHeader ( name , value ) { this . _headers [ name . toLowerCase ( ) ] = value + '' ; return this ; } getHeader ( name ) { return this . _headers [ name . toLowerCase ( ) ] ; } getHeaders ( ) { return this . _headers ; } getHeaderNames ( ) { return Object . keys ( this . _headers ) ; } hasHeader ( name ) { return name . toLowerCase ( ) in this . _headers ; } removeHeader ( name ) { delete this . _headers [ name . toLowerCase ( ) ] ; } addTrailers ( _headers ) { } flushHeaders ( ) { } }