forked from LeenkxTeam/LNXSDK
		
	Update Files
This commit is contained in:
		
							
								
								
									
										189
									
								
								Kha/Backends/Node/js/node/http/Agent.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								Kha/Backends/Node/js/node/http/Agent.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,189 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| import haxe.DynamicAccess; | ||||
| import js.node.net.Socket; | ||||
| #if haxe4 | ||||
| import js.lib.Error; | ||||
| #else | ||||
| import js.Error; | ||||
| #end | ||||
|  | ||||
| /** | ||||
| 	An `Agent` is responsible for managing connection persistence and reuse for HTTP clients. | ||||
| 	It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, | ||||
| 	at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to the same host and port. | ||||
| 	Whether it is destroyed or pooled depends on the `keepAlive` option. | ||||
|  | ||||
| 	Pooled connections have TCP Keep-Alive enabled for them, but servers may still close idle connections, in which case they will be removed | ||||
| 	from the pool and a new connection will be made when a new HTTP request is made for that host and port. | ||||
| 	Servers may also refuse to allow multiple requests over the same connection, in which case the connection will have to be remade for every | ||||
| 	request and cannot be pooled. | ||||
| 	The `Agent` will still make the requests to that server, but each one will occur over a new connection. | ||||
|  | ||||
| 	When a connection is closed by the client or the server, it is removed from the pool. | ||||
| 	Any unused sockets in the pool will be unrefed so as not to keep the Node.js process running when there are no outstanding requests. | ||||
| 	(see [socket.unref()](https://nodejs.org/api/net.html#net_socket_unref)). | ||||
|  | ||||
| 	It is good practice, to `destroy()` an Agent instance when it is no longer in use, because unused sockets consume OS resources. | ||||
|  | ||||
| 	Sockets are removed from an agent when the socket emits either a `'close'` event or an `'agentRemove'` event. | ||||
| 	When intending to keep one HTTP request open for a long time without keeping it in the agent, something like the following may be done. | ||||
|  | ||||
| 	An agent may also be used for an individual request. By providing `{agent: false}` as an option to the `http.get()` or `http.request()` functions, | ||||
| 	a one-time use `Agent` with default options will be used for the client connection. | ||||
| **/ | ||||
| @:jsRequire("http", "Agent") | ||||
| extern class Agent { | ||||
| 	/** | ||||
| 		`options` in socket.connect() are also supported. | ||||
|  | ||||
| 		The default `http.globalAgent` that is used by `http.request()` has all of these values set to their respective defaults. | ||||
|  | ||||
| 		To configure any of them, a custom `http.Agent` instance must be created. | ||||
| 	**/ | ||||
| 	function new(?options:HttpAgentOptions); | ||||
|  | ||||
| 	/** | ||||
| 		Produces a socket/stream to be used for HTTP requests. | ||||
|  | ||||
| 		By default, this function is the same as `net.createConnection()`. | ||||
| 		However, custom agents may override this method in case greater flexibility is desired. | ||||
|  | ||||
| 		A socket/stream can be supplied in one of two ways: by returning the socket/stream from this function, | ||||
| 		or by passing the socket/stream to `callback`. | ||||
|  | ||||
| 		`callback` has a signature of `(err, stream)`. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	function createConnection(options:SocketConnectOptionsTcp, ?callback:(err:Error, stream:Socket) -> Void):Socket; | ||||
| 	#else | ||||
| 	function createConnection(options:SocketConnectOptionsTcp, ?callback:Error->Socket->Void):Socket; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		Called when `socket` is detached from a request and could be persisted by the `Agent`. | ||||
|  | ||||
| 		This method can be overridden by a particular `Agent` subclass. | ||||
| 		If this method returns a falsy value, the socket will be destroyed instead of persisting it for use with the next request. | ||||
| 	**/ | ||||
| 	function keepSocketAlive(socket:Socket):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Called when `socket` is attached to `request` after being persisted because of the keep-alive options. | ||||
|  | ||||
| 		This method can be overridden by a particular `Agent` subclass. | ||||
| 	**/ | ||||
| 	function reuseSocket(socket:Socket, request:ClientRequest):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Destroy any sockets that are currently in use by the agent. | ||||
|  | ||||
| 		It is usually not necessary to do this. However, if using an agent with `keepAlive` enabled, | ||||
| 		then it is best to explicitly shut down the agent when it will no longer be used. Otherwise, | ||||
| 		sockets may hang open for quite a long time before the server terminates them. | ||||
| 	**/ | ||||
| 	function destroy():Void; | ||||
|  | ||||
| 	/** | ||||
| 		An object which contains arrays of sockets currently awaiting use by the agent when keepAlive is enabled. | ||||
| 		Do not modify. | ||||
| 	 */ | ||||
| 	var freeSockets(default, null):DynamicAccess<Array<Socket>>; | ||||
|  | ||||
| 	/** | ||||
| 		Get a unique name for a set of request options, to determine whether a connection can be reused. | ||||
| 		For an HTTP agent, this returns `host:port:localAddress` or `host:port:localAddress:family`. | ||||
| 		For an HTTPS agent, the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options that determine socket reusability. | ||||
| 	**/ | ||||
| 	function getName(options:js.node.Http.HttpRequestOptions):String; | ||||
|  | ||||
| 	/** | ||||
| 		By default set to `256`. | ||||
| 		For agents with `keepAlive` enabled, this sets the maximum number of sockets that will be left open in the free state. | ||||
| 	**/ | ||||
| 	var maxFreeSockets:Float; | ||||
|  | ||||
| 	/** | ||||
| 		By default set to `Infinity`. | ||||
| 		Determines how many concurrent sockets the agent can have open per origin. Origin is the returned value of `getName()`. | ||||
| 	**/ | ||||
| 	var maxSockets:Float; | ||||
|  | ||||
| 	/** | ||||
| 		An object which contains queues of requests that have not yet been assigned to sockets. | ||||
| 		Do not modify. | ||||
| 	**/ | ||||
| 	var requests(default, null):DynamicAccess<Array<ClientRequest>>; | ||||
|  | ||||
| 	/** | ||||
| 		An object which contains arrays of sockets currently in use by the agent. | ||||
| 		Do not modify. | ||||
| 	**/ | ||||
| 	var sockets(default, null):DynamicAccess<Array<Socket>>; | ||||
| } | ||||
|  | ||||
| /** | ||||
| 	Options for `Agent` constructor. | ||||
| **/ | ||||
| typedef HttpAgentOptions = { | ||||
| 	/** | ||||
| 		Keep sockets around even when there are no outstanding requests, so they can be used for future requests | ||||
| 		without having to reestablish a TCP connection. | ||||
| 		Not to be confused with the `keep-alive` value of the `Connection` header. | ||||
| 		The `Connection: keep-alive` header is always sent when using an agent except when the `Connection` header | ||||
| 		is explicitly specified or when the `keepAlive` and `maxSockets` options are respectively set to `false` and `Infinity`, | ||||
| 		in which case `Connection: close` will be used. | ||||
|  | ||||
| 		Default: `false` | ||||
| 	**/ | ||||
| 	@:optional var keepAlive:Bool; | ||||
|  | ||||
| 	/** | ||||
| 		When using the `keepAlive` option, specifies the [initial delay](https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay) for TCP Keep-Alive packets. | ||||
| 		Ignored when the `keepAlive` option is `false` or `undefined`. | ||||
|  | ||||
| 		Default: `1000`. | ||||
| 	**/ | ||||
| 	@:optional var keepAliveMsecs:Int; | ||||
|  | ||||
| 	/** | ||||
| 		Maximum number of sockets to allow per host. Each request will use a new socket until the maximum is reached. | ||||
|  | ||||
| 		Default: `Infinity`. | ||||
| 	**/ | ||||
| 	@:optional var maxSockets:Int; | ||||
|  | ||||
| 	/** | ||||
| 		Maximum number of sockets to leave open in a free state. Only relevant if `keepAlive` is set to `true`. | ||||
|  | ||||
| 		Default: `256`. | ||||
| 	**/ | ||||
| 	@:optional var maxFreeSockets:Int; | ||||
|  | ||||
| 	/** | ||||
| 		Socket timeout in milliseconds. This will set the timeout when the socket is created. | ||||
| 	**/ | ||||
| 	@:optional var timeout:Int; | ||||
| } | ||||
							
								
								
									
										223
									
								
								Kha/Backends/Node/js/node/http/ClientRequest.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										223
									
								
								Kha/Backends/Node/js/node/http/ClientRequest.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,223 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| import haxe.DynamicAccess; | ||||
| import js.node.Buffer; | ||||
| import js.node.events.EventEmitter.Event; | ||||
| import js.node.net.Socket; | ||||
| import js.node.stream.Writable; | ||||
|  | ||||
| /** | ||||
| 	Enumeration of events emitted by `ClientRequest` | ||||
| **/ | ||||
| @:enum abstract ClientRequestEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> { | ||||
| 	/** | ||||
| 		Emitted when the request has been aborted by the client. | ||||
| 		This event is only emitted on the first call to `abort()`. | ||||
| 	**/ | ||||
| 	var Abort:ClientRequestEvent<Void->Void> = "abort"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time a server responds to a request with a `CONNECT` method. | ||||
| 		If this event is not being listened for, clients receiving a `CONNECT` method will have their connections closed. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var Connect:ClientRequestEvent<(response:IncomingMessage, socket:Socket, head:Buffer) -> Void> = "connect"; | ||||
| 	#else | ||||
| 	var Connect:ClientRequestEvent<IncomingMessage->Socket->Buffer->Void> = "connect"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when the server sends a '100 Continue' HTTP response, | ||||
| 		usually because the request contained 'Expect: 100-continue'. | ||||
| 		This is an instruction that the client should send the request body. | ||||
| 	**/ | ||||
| 	var Continue:ClientRequestEvent<Void->Void> = "continue"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when the server sends a 1xx intermediate response (excluding 101 Upgrade). | ||||
| 		The listeners of this event will receive an object containing the HTTP version, status code, status message, | ||||
| 		key-value headers object, and array with the raw header names followed by their respective values. | ||||
| 	**/ | ||||
| 	var Information:ClientRequestEvent<InformationEventData->Void> = "information"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when a response is received to this request. This event is emitted only once. | ||||
| 	**/ | ||||
| 	var Response:ClientRequestEvent<IncomingMessage->Void> = "response"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted after a socket is assigned to this request. | ||||
| 	**/ | ||||
| 	var Socket:ClientRequestEvent<Socket->Void> = "socket"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when the underlying socket times out from inactivity. | ||||
| 		This only notifies that the socket has been idle. The request must be aborted manually. | ||||
|  | ||||
| 		See also: [request.setTimeout()](https://nodejs.org/api/http.html#http_request_settimeout_timeout_callback). | ||||
| 	**/ | ||||
| 	var Timeout:ClientRequestEvent<Socket->Void> = "timeout"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time a server responds to a request with an upgrade. | ||||
| 		If this event is not being listened for and the response status code is 101 Switching Protocols, | ||||
| 		clients receiving an upgrade header will have their connections closed. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var Upgrade:ClientRequestEvent<(response:IncomingMessage, socket:Socket, head:Buffer) -> Void> = "upgrade"; | ||||
| 	#else | ||||
| 	var Upgrade:ClientRequestEvent<IncomingMessage->Socket->Buffer->Void> = "upgrade"; | ||||
| 	#end | ||||
| } | ||||
|  | ||||
| /** | ||||
| 	This object is created internally and returned from http.request(). | ||||
| 	It represents an in-progress request whose header has already been queued. | ||||
| 	The header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. | ||||
| 	The actual header will be sent along with the first data chunk or when calling `request.end()`. | ||||
|  | ||||
| 	To get the response, add a listener for `'response'` to the request object. | ||||
| 	`'response'` will be emitted from the request object when the response headers have been received. | ||||
| 	The `'response'` event is executed with one argument which is an instance of `http.IncomingMessage`. | ||||
|  | ||||
| 	During the `'response'` event, one can add listeners to the response object; particularly to listen for the `'data'` event. | ||||
|  | ||||
| 	If no `'response'` handler is added, then the response will be entirely discarded. However, | ||||
| 	if a `'response'` event handler is added, then the data from the response object *must* be consumed, | ||||
| 	either by calling `response.read()` whenever there is a `'readable'` event, or by adding a `'data'` handler, | ||||
| 	or by calling the `.resume()` method. Until the data is consumed, the `'end'` event will not fire. | ||||
| 	Also, until the data is read it will consume memory that can eventually lead to a 'process out of memory' error. | ||||
|  | ||||
| 	Unlike the `request` object, if the response closes prematurely, the response object does not emit an `'error'` event | ||||
| 	but instead emits the `'aborted'` event. | ||||
|  | ||||
| 	Node.js does not check whether Content-Length and the length of the body which has been transmitted are equal or not. | ||||
| **/ | ||||
| @:jsRequire("http", "ClientRequest") | ||||
| extern class ClientRequest extends Writable<ClientRequest> { | ||||
| 	/** | ||||
| 		Marks the request as aborting. Calling this will cause remaining data in the response to be dropped and the socket to be destroyed. | ||||
| 	**/ | ||||
| 	function abort():Void; | ||||
|  | ||||
| 	/** | ||||
| 		The request.aborted property will be true if the request has been aborted. | ||||
| 	**/ | ||||
| 	var aborted(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		See `request.socket`. | ||||
| 	**/ | ||||
| 	var connection(default, null):Socket; | ||||
|  | ||||
| 	/** | ||||
| 		The `response.finished` property will be true if `response.end()` has been called. | ||||
| 	**/ | ||||
| 	var finished(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Flush the request headers. | ||||
|  | ||||
| 		For efficiency reasons, node.js normally buffers the request headers until you call `request.end()` | ||||
| 		or write the first chunk of request data. It then tries hard to pack the request headers and data | ||||
| 		into a single TCP packet. | ||||
|  | ||||
| 		That's usually what you want (it saves a TCP round-trip) but not when the first data isn't sent | ||||
| 		until possibly much later. `flushHeaders` lets you bypass the optimization and kickstart the request. | ||||
| 	**/ | ||||
| 	function flushHeaders():Void; | ||||
|  | ||||
| 	/** | ||||
| 		Reads out a header on the request. The name is case-insensitive. | ||||
| 		The type of the return value depends on the arguments provided to `request.setHeader()`. | ||||
| 	**/ | ||||
| 	function getHeader(name:String):haxe.extern.EitherType<String, Array<String>>; | ||||
|  | ||||
| 	/** | ||||
| 		Limits maximum response headers count. If set to 0, no limit will be applied. | ||||
|  | ||||
| 		Default: `2000` | ||||
| 	**/ | ||||
| 	var maxHeadersCount:Null<Int>; | ||||
|  | ||||
| 	/** | ||||
| 		The request path. | ||||
| 	**/ | ||||
| 	var path(default, null):String; | ||||
|  | ||||
| 	/** | ||||
| 		Removes a header that's already defined into headers object. | ||||
| 	**/ | ||||
| 	function removeHeader(name:String):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Sets a single header value for headers object. | ||||
| 		If this header already exists in the to-be-sent headers, its value will be replaced. | ||||
| 		Use an array of strings here to send multiple headers with the same name. | ||||
| 		Non-string values will be stored without modification. Therefore, `request.getHeader()` may return non-string values. | ||||
| 		However, the non-string values will be converted to strings for network transmission. | ||||
| 	**/ | ||||
| 	@:overload(function(name:String, value:Array<String>):Void {}) | ||||
| 	function setHeader(name:String, value:String):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Once a socket is assigned to this request and is connected | ||||
| 		`socket.setNoDelay` will be called. | ||||
| 	**/ | ||||
| 	function setNoDelay(?noDelay:Bool):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Once a socket is assigned to this request and is connected | ||||
| 		`socket.setKeepAlive`() will be called. | ||||
| 	**/ | ||||
| 	@:overload(function(?initialDelay:Int):Void {}) | ||||
| 	function setSocketKeepAlive(enable:Bool, ?initialDelay:Int):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called. | ||||
| 	**/ | ||||
| 	function setTimeout(timeout:Int, ?callback:Socket->Void):ClientRequest; | ||||
|  | ||||
| 	/** | ||||
| 		Reference to the underlying socket. Usually users will not want to access this property. | ||||
| 		In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket. | ||||
| 		The `socket` may also be accessed via `request.connection`. | ||||
| 	 */ | ||||
| 	var socket(default, null):Socket; | ||||
|  | ||||
| 	// This field is defined in super class. | ||||
| 	// var writableEnded(default, null):Bool; | ||||
| 	// var writableFinished(default, null):Bool; | ||||
| } | ||||
|  | ||||
| typedef InformationEventData = { | ||||
| 	var httpVersion:String; | ||||
| 	var httpVersionMajor:Int; | ||||
| 	var httpVersionMinor:Int; | ||||
| 	var statusCode:Int; | ||||
| 	var statusMessage:String; | ||||
| 	var headers:DynamicAccess<String>; | ||||
| 	var rawHeaders:Array<String>; | ||||
| } | ||||
							
								
								
									
										171
									
								
								Kha/Backends/Node/js/node/http/IncomingMessage.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										171
									
								
								Kha/Backends/Node/js/node/http/IncomingMessage.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,171 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| import haxe.DynamicAccess; | ||||
| import js.node.events.EventEmitter.Event; | ||||
| import js.node.net.Socket; | ||||
| import js.node.stream.Readable; | ||||
| #if haxe4 | ||||
| import js.lib.Error; | ||||
| #else | ||||
| import js.Error; | ||||
| #end | ||||
|  | ||||
| /** | ||||
| 	Enumeration of events emitted by the `IncomingMessage` objects in addition to its parent class events. | ||||
| **/ | ||||
| @:enum abstract IncomingMessageeEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> { | ||||
| 	/** | ||||
| 		Emitted when the request has been aborted. | ||||
| 	**/ | ||||
| 	var Aborted:IncomingMessageeEvent<Void->Void> = "aborted"; | ||||
|  | ||||
| 	/** | ||||
| 		Indicates that the underlying connection was closed. | ||||
| 	**/ | ||||
| 	var Close:IncomingMessageeEvent<Void->Void> = "close"; | ||||
| } | ||||
|  | ||||
| /** | ||||
| 	An `IncomingMessage` object is created by `http.Server` or `http.ClientRequest` and passed as the first argument to the `'request'` and `'response'` event respectively. | ||||
| 	It may be used to access response status, headers and data. | ||||
|  | ||||
| 	It implements the `Readable Stream` interface, as well as the following additional events, methods, and properties. | ||||
| **/ | ||||
| @:jsRequire("http", "IncomingMessage") | ||||
| extern class IncomingMessage extends Readable<IncomingMessage> { | ||||
| 	/** | ||||
| 		The `aborted` property will be `true` if the request has been aborted. | ||||
| 	**/ | ||||
| 	var aborted(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		The `complete` property will be `true` if a complete HTTP message has been received and successfully parsed. | ||||
| 	**/ | ||||
| 	var complete(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Calls `destroy()` on the socket that received the `IncomingMessage`. | ||||
| 		If `error` is provided, an `'error'` event is emitted and `error` is passed as an argument to any listeners on the event. | ||||
| 	**/ | ||||
| 	override function destroy(?error:Error):IncomingMessage; | ||||
|  | ||||
| 	/** | ||||
| 		The request/response headers object. | ||||
|  | ||||
| 		Key-value pairs of header names and values. Header names are lower-cased. | ||||
|  | ||||
| 		Duplicates in raw headers are handled in the following ways, depending on the header name: | ||||
|  | ||||
| 		- Duplicates of `age`, `authorization`, `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`, | ||||
| 		  `last-modified`, `location`, `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, or `user-agent` are discarded. | ||||
| 		- `set-cookie` is always an array. Duplicates are added to the array. | ||||
| 		- For duplicate `cookie` headers, the values are joined together with '; '. | ||||
| 		- For all other headers, the values are joined together with ', '. | ||||
| 	**/ | ||||
| 	var headers(default, null):DynamicAccess<haxe.extern.EitherType<String, Array<String>>>; | ||||
|  | ||||
| 	/** | ||||
| 		In case of server request, the HTTP version sent by the client. | ||||
| 		In the case of client response, the HTTP version of the connected-to server. | ||||
| 		Probably either `'1.1'` or `'1.0'`. | ||||
| 	**/ | ||||
| 	var httpVersion(default, null):String; | ||||
|  | ||||
| 	/** | ||||
| 		HTTP Version first integer | ||||
| 	**/ | ||||
| 	var httpVersionMajor(default, null):Int; | ||||
|  | ||||
| 	/** | ||||
| 		HTTP Version second integer | ||||
| 	**/ | ||||
| 	var httpVersionMinor(default, null):Int; | ||||
|  | ||||
| 	/** | ||||
| 		*Only valid for request obtained from* `Server`. | ||||
|  | ||||
| 		The request method as a string. | ||||
| 		Read only. Example: `'GET'`, `'DELETE'`. | ||||
| 	**/ | ||||
| 	var method(default, null):Method; | ||||
|  | ||||
| 	/** | ||||
| 		The raw request/response headers list exactly as they were received. | ||||
|  | ||||
| 		The keys and values are in the same list. It is not a list of tuples. So, the even-numbered offsets are key values, | ||||
| 		and the odd-numbered offsets are the associated values. | ||||
|  | ||||
| 		Header names are not lowercased, and duplicates are not merged. | ||||
| 	**/ | ||||
| 	var rawHeaders(default, null):Array<String>; | ||||
|  | ||||
| 	/** | ||||
| 		The raw request/response trailer keys and values exactly as they were received. | ||||
| 		Only populated at the `'end'` event. | ||||
| 	**/ | ||||
| 	var rawTrailers(default, null):Array<String>; | ||||
|  | ||||
| 	/** | ||||
| 		Calls `connection.setTimeout(msecs, callback)`. | ||||
| 	**/ | ||||
| 	function setTimeout(msecs:Int, ?callback:Void->Void):Void; | ||||
|  | ||||
| 	/** | ||||
| 		The `Socket` object associated with the connection. | ||||
|  | ||||
| 		With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the client's authentication details. | ||||
| 	**/ | ||||
| 	var socket(default, null):Socket; | ||||
|  | ||||
| 	/** | ||||
| 		Alias for `socket`. | ||||
| 	**/ | ||||
| 	var connection(default, null):Socket; | ||||
|  | ||||
| 	/** | ||||
| 		*Only valid for response obtained from* `ClientRequest`. | ||||
| 		The 3-digit HTTP response status code. E.G. `404`. | ||||
| 	**/ | ||||
| 	var statusCode(default, null):Int; | ||||
|  | ||||
| 	/** | ||||
| 		*Only valid for response obtained from* `ClientRequest`. | ||||
| 		The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`. | ||||
| 	**/ | ||||
| 	var statusMessage(default, null):String; | ||||
|  | ||||
| 	/** | ||||
| 		The request/response trailers object. | ||||
| 		Only populated after the `'end'` event. | ||||
| 	**/ | ||||
| 	var trailers(default, null):DynamicAccess<String>; | ||||
|  | ||||
| 	/** | ||||
| 		*Only valid for request obtained from* `Server`. | ||||
|  | ||||
| 		Request URL string. This contains only the URL that is present in the actual HTTP request. | ||||
| 	**/ | ||||
| 	var url(default, null):String; | ||||
| } | ||||
							
								
								
									
										63
									
								
								Kha/Backends/Node/js/node/http/Method.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								Kha/Backends/Node/js/node/http/Method.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| /** | ||||
| 	Enumeration of possible HTTP methods as described in | ||||
| 	http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html | ||||
| **/ | ||||
| @:enum abstract Method(String) from String to String { | ||||
| 	var Acl = "ACL"; | ||||
| 	var Bind = "BIND"; | ||||
| 	var Checkout = "CHECKOUT"; | ||||
| 	var Connect = "CONNECT"; | ||||
| 	var Copy = "COPY"; | ||||
| 	var Delete = "DELETE"; | ||||
| 	var Get = "GET"; | ||||
| 	var Head = "HEAD"; | ||||
| 	var Link = "LINK'"; | ||||
| 	var Lock = "LOCK'"; | ||||
| 	var MSearch = "M-SEARCH'"; | ||||
| 	var Merge = "MERGE'"; | ||||
| 	var Mkactivity = "MKACTIVITY'"; | ||||
| 	var Mkcalendar = "MKCALENDAR'"; | ||||
| 	var Mkcol = "MKCOL'"; | ||||
| 	var Move = "MOVE'"; | ||||
| 	var Notify = "NOTIFY'"; | ||||
| 	var Options = "OPTIONS"; | ||||
| 	var Patch = "PATCH"; | ||||
| 	var Post = "POST"; | ||||
| 	var Propfind = "PROPFIND"; | ||||
| 	var Proppatch = "PROPPATCH"; | ||||
| 	var Purge = "PURGE"; | ||||
| 	var Put = "PUT"; | ||||
| 	var Rebind = "REBIND"; | ||||
| 	var Report = "REPORT"; | ||||
| 	var Search = "SEARCH"; | ||||
| 	var Subscribe = "SUBSCRIBE"; | ||||
| 	var Trace = "TRACE"; | ||||
| 	var Unbind = "UNBIND"; | ||||
| 	var Unlink = "UNLINK"; | ||||
| 	var Unlock = "UNLOCK"; | ||||
| 	var Unsubscribe = "UNSUBSCRIBE"; | ||||
| } | ||||
							
								
								
									
										204
									
								
								Kha/Backends/Node/js/node/http/Server.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								Kha/Backends/Node/js/node/http/Server.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,204 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| import js.node.Buffer; | ||||
| import js.node.events.EventEmitter.Event; | ||||
| import js.node.net.Socket; | ||||
| #if haxe4 | ||||
| import js.lib.Error; | ||||
| #else | ||||
| import js.Error; | ||||
| #end | ||||
|  | ||||
| /** | ||||
| 	Enumeration of events emitted by `http.Server` class in addition to | ||||
| 	its parent `net.Server` class. | ||||
| **/ | ||||
| @:enum abstract ServerEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> { | ||||
| 	/** | ||||
| 		Emitted each time a request with an HTTP Expect: `100-continue` is received. | ||||
| 		If this event is not listened for, the server will automatically respond with a `100 Continue` as appropriate. | ||||
|  | ||||
| 		Handling this event involves calling `response.writeContinue` if the client should continue | ||||
| 		to send the request body, or generating an appropriate HTTP response (e.g. 400 Bad Request) if the client | ||||
| 		should not continue to send the request body. | ||||
|  | ||||
| 		When this event is emitted and handled, the 'request' event will not be emitted. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var CheckContinue:ServerEvent<(request:IncomingMessage, response:ServerResponse) -> Void> = "checkContinue"; | ||||
| 	#else | ||||
| 	var CheckContinue:ServerEvent<IncomingMessage->ServerResponse->Void> = "checkContinue"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time a request with an HTTP `Expect` header is received, where the value is not `100-continue`. | ||||
| 		If this event is not listened for, the server will automatically respond with a `417 Expectation Failed` as appropriate. | ||||
|  | ||||
| 		When this event is emitted and handled, the `'request'` event will not be emitted. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var CheckExpectation:ServerEvent<(request:IncomingMessage, response:ServerResponse) -> Void> = "checkExpectation"; | ||||
| 	#else | ||||
| 	var CheckExpectation:ServerEvent<IncomingMessage->ServerResponse->Void> = "checkExpectation"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		If a client connection emits an `'error'` event, it will be forwarded here. | ||||
| 		Listener of this event is responsible for closing/destroying the underlying socket. | ||||
| 		For example, one may wish to more gracefully close the socket with a custom HTTP response instead of abruptly severing the connection. | ||||
|  | ||||
| 		Default behavior is to try close the socket with a HTTP '400 Bad Request', or a HTTP '431 Request Header Fields Too Large' | ||||
| 		in the case of a `HPE_HEADER_OVERFLOW` error. If the socket is not writable it is immediately destroyed. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var ClientError:ServerEvent<(exception:Error, socket:Socket) -> Void> = "clientError"; | ||||
| 	#else | ||||
| 	var ClientError:ServerEvent<Error->Socket->Void> = "clientError"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when the server closes. | ||||
| 	**/ | ||||
| 	var Close:ServerEvent<Void->Void> = "close"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time a client requests an HTTP `CONNECT` method. | ||||
| 		If this event is not listened for, then clients requesting a `CONNECT` method will have their connections closed. | ||||
|  | ||||
| 		After this event is emitted, the request's socket will not have a `'data'` event listener, | ||||
| 		meaning it will need to be bound in order to handle data sent to the server on that socket. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var Connect:ServerEvent<(request:IncomingMessage, socekt:Socket, head:Buffer) -> Void> = "connect"; | ||||
| 	#else | ||||
| 	var Connect:ServerEvent<IncomingMessage->Socket->Buffer->Void> = "connect"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		This event is emitted when a new TCP stream is established. | ||||
| 		`socket` is typically an object of type net.Socket. Usually users will not want to access this event. | ||||
| 		In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket. | ||||
| 		The `socket` can also be accessed at `request.connection`. | ||||
|  | ||||
| 		This event can also be explicitly emitted by users to inject connections into the HTTP server. In that case, | ||||
| 		any `Duplex` stream can be passed. | ||||
|  | ||||
| 		If `socket.setTimeout()` is called here, the timeout will be replaced with `server.keepAliveTimeout` | ||||
| 		when the socket has served a request (if `server.keepAliveTimeout` is non-zero). | ||||
| 	**/ | ||||
| 	var Connection:ServerEvent<Socket->Void> = "connection"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time there is a request. | ||||
| 		There may be multiple requests per connection (in the case of HTTP Keep-Alive connections). | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var Request:ServerEvent<(request:IncomingMessage, response:ServerResponse) -> Void> = "request"; | ||||
| 	#else | ||||
| 	var Request:ServerEvent<IncomingMessage->ServerResponse->Void> = "request"; | ||||
| 	#end | ||||
|  | ||||
| 	/** | ||||
| 		Emitted each time a client requests an HTTP upgrade. | ||||
| 		Listening to this event is optional and clients cannot insist on a protocol change. | ||||
|  | ||||
| 		After this event is emitted, the request's socket will not have a `'data'` event listener, | ||||
| 		meaning it will need to be bound in order to handle data sent to the server on that socket. | ||||
| 	**/ | ||||
| 	#if haxe4 | ||||
| 	var Upgrade:ServerEvent<(request:IncomingMessage, socket:Socket, buffer:Buffer) -> Void> = "upgrade"; | ||||
| 	#else | ||||
| 	var Upgrade:ServerEvent<IncomingMessage->Socket->Buffer->Void> = "upgrade"; | ||||
| 	#end | ||||
| } | ||||
|  | ||||
| /** | ||||
| 	This class inherits `from net.Server`. | ||||
| **/ | ||||
| @:jsRequire("http", "Server") | ||||
| extern class Server extends js.node.net.Server { | ||||
| 	/** | ||||
| 		Limit the amount of time the parser will wait to receive the complete HTTP headers. | ||||
|  | ||||
| 		In case of inactivity, the rules defined in `server.timeout` apply. | ||||
| 		However, that inactivity based timeout would still allow the connection to be kept open | ||||
| 		if the headers are being sent very slowly (by default, up to a byte per 2 minutes). | ||||
| 		In order to prevent this, whenever header data arrives an additional check is made that | ||||
| 		more than `server.headersTimeout` milliseconds has not passed since the connection was established. | ||||
| 		If the check fails, a `'timeout'` event is emitted on the server object, and (by default) the socket is destroyed. | ||||
| 		See [server.timeout](https://nodejs.org/api/http.html#http_server_timeout) for more information on how timeout behavior can be customized. | ||||
|  | ||||
| 		Default: `40000` | ||||
| 	**/ | ||||
| 	var headersTimeout:Int; | ||||
|  | ||||
| 	/** | ||||
| 		Limits maximum incoming headers count. If set to 0, no limit will be applied. | ||||
|  | ||||
| 		Default: `2000` | ||||
| 	**/ | ||||
| 	var maxHeadersCount:Null<Int>; | ||||
|  | ||||
| 	/** | ||||
| 		Sets the timeout value for sockets, and emits a `'timeout'` event on the Server object, | ||||
| 		passing the socket as an argument, if a timeout occurs. | ||||
|  | ||||
| 		If there is a `'timeout'` event listener on the Server object, then it will be called with the timed-out socket as an argument. | ||||
|  | ||||
| 		By default, the Server's timeout value is 2 minutes, and sockets are destroyed automatically if they time out. | ||||
| 		However, if a callback is assigned to the Server's `'timeout'` event, timeouts must be handled explicitly. | ||||
|  | ||||
| 		To change the default timeout use the `--http-server-default-timeout` flag. | ||||
| 	**/ | ||||
| 	function setTimeout(msecs:Int, ?callback:js.node.net.Socket->Void):Void; | ||||
|  | ||||
| 	/** | ||||
| 		The number of milliseconds of inactivity before a socket is presumed to have timed out. | ||||
|  | ||||
| 		A value of `0` will disable the timeout behavior on incoming connections. | ||||
|  | ||||
| 		The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, | ||||
| 		not any existing connections. | ||||
|  | ||||
| 		To change the default timeout use the `--http-server-default-timeout` flag. | ||||
|  | ||||
| 		Default: `120000` (2 minutes) | ||||
| 	**/ | ||||
| 	var timeout:Int; | ||||
|  | ||||
| 	/** | ||||
| 		The number of milliseconds of inactivity a server needs to wait for additional incoming data, | ||||
| 		after it has finished writing the last response, before a socket will be destroyed. | ||||
| 		If the server receives new data before the keep-alive timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`. | ||||
|  | ||||
| 		A value of `0` will disable the keep-alive timeout behavior on incoming connections | ||||
| 		A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout. | ||||
|  | ||||
| 		The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections. | ||||
|  | ||||
| 		Default: `5000` (5 seconds). | ||||
| 	**/ | ||||
| 	var keepAliveTimeout:Int; | ||||
| } | ||||
							
								
								
									
										210
									
								
								Kha/Backends/Node/js/node/http/ServerResponse.hx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										210
									
								
								Kha/Backends/Node/js/node/http/ServerResponse.hx
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,210 @@ | ||||
| /* | ||||
|  * Copyright (C)2014-2020 Haxe Foundation | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a | ||||
|  * copy of this software and associated documentation files (the "Software"), | ||||
|  * to deal in the Software without restriction, including without limitation | ||||
|  * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||||
|  * and/or sell copies of the Software, and to permit persons to whom the | ||||
|  * Software is furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||||
|  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
|  * DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package js.node.http; | ||||
|  | ||||
| import haxe.DynamicAccess; | ||||
| import js.node.events.EventEmitter.Event; | ||||
| import js.node.net.Socket; | ||||
| import js.node.stream.Writable; | ||||
|  | ||||
| /** | ||||
| 	Enumeration of events emitted by the `ServerResponse` objects in addition to its parent class events. | ||||
| **/ | ||||
| @:enum abstract ServerResponseEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> { | ||||
| 	/** | ||||
| 		Indicates that the underlying connection was terminated. | ||||
| 	**/ | ||||
| 	var Close:ServerResponseEvent<Void->Void> = "close"; | ||||
|  | ||||
| 	/** | ||||
| 		Emitted when the response has been sent. | ||||
| 		More specifically, this event is emitted when the last segment of the response header | ||||
| 		and body have been handed off to the operating system for transmission over the network. | ||||
| 		It does not imply that the client has received anything yet. | ||||
| 	**/ | ||||
| 	var Finish:ServerResponseEvent<Void->Void> = "finish"; | ||||
| } | ||||
|  | ||||
| /** | ||||
| 	This object is created internally by an HTTP server — not by the user. | ||||
| 	It is passed as the second parameter to the 'request' event. | ||||
| **/ | ||||
| @:jsRequire("http", "ServerResponse") | ||||
| extern class ServerResponse extends Writable<ServerResponse> { | ||||
| 	/** | ||||
| 		This method adds HTTP trailing headers (a header but at the end of the message) to the response. | ||||
|  | ||||
| 		Trailers will only be emitted if chunked encoding is used for the response; | ||||
| 		if it is not (e.g., if the request was HTTP/1.0), they will be silently discarded. | ||||
|  | ||||
| 		Note that HTTP requires the 'Trailer' header to be sent if you intend to emit trailers, | ||||
| 		with a list of the header fields in its value. | ||||
| 	**/ | ||||
| 	@:overload(function(headers:Array<Array<String>>):Void {}) | ||||
| 	function addTrailers(headers:DynamicAccess<String>):Void; | ||||
|  | ||||
| 	/** | ||||
| 		See `socket`. | ||||
| 	**/ | ||||
| 	var connection(default, null):Socket; | ||||
|  | ||||
| 	/** | ||||
| 		The `finished` property will be true if `end()` has been called. | ||||
| 	**/ | ||||
| 	var finished(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Flushes the response headers. | ||||
| 		See also: [request.flushHeaders()](https://nodejs.org/api/http.html#http_request_flushheaders). | ||||
| 	**/ | ||||
| 	function flushHeaders():Void; | ||||
|  | ||||
| 	/** | ||||
| 		Reads out a header that's already been queued but not sent to the client. | ||||
| 		The name is case-insensitive. The type of the return value depends on the arguments provided to `setHeader()`. | ||||
| 	**/ | ||||
| 	function getHeader(name:String):haxe.extern.EitherType<String, Array<String>>; | ||||
|  | ||||
| 	/** | ||||
| 		Returns an array containing the unique names of the current outgoing headers. All header names are lowercase. | ||||
| 	**/ | ||||
| 	function getHeaderNames():Array<String>; | ||||
|  | ||||
| 	/** | ||||
| 		Returns a shallow copy of the current outgoing headers. Since a shallow copy is used, | ||||
| 		array values may be mutated without additional calls to various header-related http module methods. | ||||
| 		The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase. | ||||
|  | ||||
| 		The object returned by the `getHeaders()` method does not prototypically inherit from the JavaScript Object. | ||||
| 		This means that typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others are not defined and will not work. | ||||
| 	 */ | ||||
| 	function getHeaders():DynamicAccess<haxe.extern.EitherType<String, Array<String>>>; | ||||
|  | ||||
| 	/** | ||||
| 		Returns true if the header identified by `name` is currently set in the outgoing headers. | ||||
| 		The header name matching is case-insensitive. | ||||
| 	**/ | ||||
| 	function hasHeader(name:String):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Boolean (read-only). True if headers were sent, false otherwise. | ||||
| 	**/ | ||||
| 	var headersSent(default, null):Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Removes a header that's queued for implicit sending. | ||||
| 	**/ | ||||
| 	function removeHeader(name:String):Void; | ||||
|  | ||||
| 	/** | ||||
| 		When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. | ||||
| 		Defaults to true. | ||||
|  | ||||
| 		This should only be disabled for testing; HTTP requires the Date header in responses. | ||||
| 	**/ | ||||
| 	var sendDate:Bool; | ||||
|  | ||||
| 	/** | ||||
| 		Sets a single header value for implicit headers. | ||||
| 		If this header already exists in the to-be-sent headers, its value will be replaced. | ||||
| 		Use an array of strings here to send multiple headers with the same name. | ||||
| 		Non-string values will be stored without modification. | ||||
| 		Therefore, `getHeader()` may return non-string values. | ||||
| 		However, the non-string values will be converted to strings for network transmission. | ||||
| 	**/ | ||||
| 	@:overload(function(name:String, value:Array<String>):Void {}) | ||||
| 	function setHeader(name:String, value:String):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Sets the Socket's timeout value to `msecs`. | ||||
| 		If a callback is provided, then it is added as a listener on the `'timeout'` event on the response object. | ||||
|  | ||||
| 		If no `'timeout'` listener is added to the request, the response, or the server, then sockets are destroyed when they time out. | ||||
| 		If a handler is assigned to the request, the response, or the server's `'timeout'` events, timed out sockets must be handled explicitly. | ||||
| 	**/ | ||||
| 	function setTimeout(msecs:Int, ?callback:Void->Void):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Reference to the underlying socket. Usually users will not want to access this property. | ||||
| 		In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket. | ||||
| 		After `end()`, the property is nulled. The `socket` may also be accessed via `connection`. | ||||
| 	**/ | ||||
| 	var socket(default, null):Socket; | ||||
|  | ||||
| 	/** | ||||
| 		When using implicit headers (not calling `writeHead` explicitly), this property controls the status code | ||||
| 		that will be sent to the client when the headers get flushed. | ||||
|  | ||||
| 		After response header was sent to the client, this property indicates the status code which was sent out. | ||||
| 	**/ | ||||
| 	var statusCode:Int; | ||||
|  | ||||
| 	/** | ||||
| 		When using implicit headers (not calling `writeHead()` explicitly), | ||||
| 		this property controls the status message that will be sent to the client when the headers get flushed. | ||||
| 		If this is left as `undefined` then the standard message for the status code will be used. | ||||
|  | ||||
| 		After response header was sent to the client, this property indicates the status message which was sent out. | ||||
| 	**/ | ||||
| 	var statusMessage:String; | ||||
|  | ||||
| 	/** | ||||
| 		Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. | ||||
| 		See the `'checkContinue'` event on `Server`. | ||||
| 	 */ | ||||
| 	function writeContinue():Void; | ||||
|  | ||||
| 	/** | ||||
| 		Sends a response header to the request. | ||||
| 		The status code is a 3-digit HTTP status code, like `404`. The last argument, `headers`, are the response headers. | ||||
| 		Optionally one can give a human-readable `statusMessage` as the second argument. | ||||
|  | ||||
| 		This method must only be called once on a message and it must be called before `end()` is called. | ||||
|  | ||||
| 		If `write()` or `end()` are called before calling this, the implicit/mutable headers will be calculated and call this function. | ||||
|  | ||||
| 		When headers have been set with `setHeader()`, they will be merged with any headers passed to `writeHead()`, with the headers passed to `writeHead()` given precedence. | ||||
|  | ||||
| 		If this method is called and `setHeader()` has not been called, it will directly write the supplied header values onto the network channel without caching internally, | ||||
| 		and the `getHeader()` on the header will not yield the expected result. | ||||
| 		If progressive population of headers is desired with potential future retrieval and modification, use `setHeader()` instead. | ||||
|  | ||||
| 		`Content-Length` is given in bytes not characters. | ||||
| 		The above example works because the string `'hello world'` contains only single byte characters. | ||||
| 		If the body contains higher coded characters then `Buffer.byteLength()` should be used to determine the number of bytes in a given encoding. | ||||
| 		And Node.js does not check whether `Content-Length` and the length of the body which has been transmitted are equal or not. | ||||
|  | ||||
| 		Attempting to set a header field name or value that contains invalid characters will result in a `TypeError` being thrown. | ||||
| 	**/ | ||||
| 	@:overload(function(statusCode:Int, ?headers:DynamicAccess<String>):Void {}) | ||||
| 	function writeHead(statusCode:Int, reasonPhrase:String, ?headers:DynamicAccess<String>):Void; | ||||
|  | ||||
| 	/** | ||||
| 		Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent. | ||||
| 	**/ | ||||
| 	function writeProcessing():Void; | ||||
|  | ||||
| 	// This field is defined in super class. | ||||
| 	// var writableEnded(default, null):Bool; | ||||
| 	// var writableFinished(default, null):Bool; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user