Skip to content

Commit

Permalink
fix: update http and add missing exports
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 5, 2022
1 parent 62d3f77 commit 16338d4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 68 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
},
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/node": "latest",
"@types/node-fetch": "latest",
"@types/node": "^17.0.31",
"consola": "latest",
"eslint": "latest",
"standard-version": "latest",
Expand Down
48 changes: 1 addition & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/runtime/node/http/_consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ export const STATUS_CODES = {
510: 'Not Extended',
511: 'Network Authentication Required'
}

export const maxHeaderSize = 16384
30 changes: 24 additions & 6 deletions src/runtime/node/http/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
// https://nodejs.org/api/http.html
import type http from 'node:http'
import http from 'node:http'
import { notImplemented } from '../../_internal/utils'

import * as consts from './_consts'
import * as request from './_request'
import * as response from './_response'
import { IncomingMessage } from './_request'
import { ServerResponse } from './_response'

export * from './_consts'
export * from './_request'
export * from './_response'

// @ts-ignore
export const createServer: typeof http.createServer = notImplemented('http.createServer')
export const request: typeof http.request = notImplemented('http.request')
export const get: typeof http.get = notImplemented('http.get')

export const Server: typeof http.Server = undefined as any as typeof http.Server
export const OutgoingMessage: typeof http.OutgoingMessage = undefined as any as typeof http.OutgoingMessage
export const ClientRequest: typeof http.ClientRequest = undefined as any as typeof http.ClientRequest
export const Agent: typeof http.Agent = undefined as any as typeof http.Agent
export const globalAgent: typeof http.globalAgent = undefined as any as typeof http.globalAgent

export default <typeof http> {
...consts,
...request,
...response
IncomingMessage: IncomingMessage as any as typeof http.IncomingMessage,
ServerResponse: ServerResponse as any as typeof http.ServerResponse,
createServer,
request,
get,
Server,
OutgoingMessage,
ClientRequest,
Agent,
globalAgent
}
11 changes: 5 additions & 6 deletions src/runtime/node/net/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ export class Socket extends Duplex implements net.Socket {
readonly remoteAddress?: string = ''
readonly remoteFamily?: string = ''
readonly remotePort?: number = 0
readonly readyState: net.SocketReadyState = 'readOnly'

constructor (_options?: net.SocketConstructorOpts) {
super()
}

write (_buffer: Uint8Array | string,
_arg1?: BufferEncoding | Callback<Error | undefined>,
write (_buffer: Uint8Array | string, _arg1?: BufferEncoding | Callback<Error | undefined>,
_arg2?: Callback<Error | undefined>): boolean {
return false
}

connect (_arg1: number | string | net.SocketConnectOpts,
_arg2?: string | Callback, _arg3?: Callback) {
connect (_arg1: number | string | net.SocketConnectOpts, _arg2?: string | Callback, _arg3?: Callback) {
return this
}

end (_arg1?: Callback | Uint8Array | string,
_arg2?: BufferEncoding | Callback, _arg3?: Callback): void {
end (_arg1?: Callback | Uint8Array | string, _arg2?: BufferEncoding | Callback, _arg3?: Callback) {
return this
}

setEncoding (_encoding?: BufferEncoding): this {
Expand Down
5 changes: 4 additions & 1 deletion src/runtime/node/stream/readable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class Readable extends EventEmitter implements stream.Readable {
readonly readableHighWaterMark: number = 0
readonly readableLength: number = 0
readonly readableObjectMode: boolean = false
readonly readableAborted: boolean = false
readonly readableDidRead: boolean = false

readable: boolean = false
destroyed: boolean = false
Expand Down Expand Up @@ -67,7 +69,8 @@ export class Readable extends EventEmitter implements stream.Readable {

destroy (error?: Error) {
this.destroyed = true
return this._destroy(error)
this._destroy(error)
return this
}

pipe<T> (_destenition: T, _options?: { end?: boolean }): T {
Expand Down
10 changes: 4 additions & 6 deletions src/runtime/node/stream/writable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class Writable extends EventEmitter implements stream.Writable {
return this
}

end (arg1: Callback | any, arg2?: Callback | BufferEncoding, arg3?: Callback): void {
end (arg1: Callback | any, arg2?: Callback | BufferEncoding, arg3?: Callback) {
const cb = (typeof arg1 === 'function') ? arg1 : (typeof arg2 === 'function' ? arg2 : (typeof arg3 === 'function' ? arg3 : undefined))
const data = arg1 !== cb ? arg1 : undefined
if (data) {
Expand All @@ -66,8 +66,7 @@ export class Writable extends EventEmitter implements stream.Writable {
this.writableFinished = true
this.emit('close')
this.emit('finish')
// TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57473
return this as unknown as void
return this
}

cork (): void {
Expand All @@ -76,11 +75,10 @@ export class Writable extends EventEmitter implements stream.Writable {
uncork (): void {
}

destroy (_error?: Error): void {
destroy (_error?: Error) {
this.destroyed = true
delete this._data
this.removeAllListeners()
// TODO: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/57473
return this as unknown as void
return this
}
}

0 comments on commit 16338d4

Please sign in to comment.