11package io .scalajs .nodejs
22package http
33
4+ import com .thoughtworks .enableIf
45import io .scalajs .nodejs .buffer .Buffer
56import io .scalajs .nodejs .net .Socket
6- import io .scalajs .nodejs .stream .Readable
77import io .scalajs .util .PromiseHelper ._
88
99import scala .concurrent .Future
1010import scala .scalajs .js
1111import scala .scalajs .js .annotation .JSImport
12+ import scala .scalajs .js .typedarray .Uint8Array
13+ import scala .scalajs .js .{Any , | }
1214
1315/**
1416 * http.ClientRequest - This object is created internally and returned from http.request(). It represents an in-progress
@@ -31,11 +33,25 @@ import scala.scalajs.js.annotation.JSImport
3133 */
3234@ js.native
3335@ JSImport (" http" , " ClientRequest" )
34- class ClientRequest extends Readable {
36+ class ClientRequest extends stream. Writable {
3537
36- def headers : js. Dictionary [ String ] = js.native
38+ def aborted : Int | Boolean = js.native
3739
38- def socket : Socket = js.native
40+ def connection : net.Socket = js.native
41+
42+ def finished : Boolean = js.native
43+
44+ var maxHeadersCount : Int | Null = js.native
45+
46+ def path : String = js.native
47+
48+ def socket : net.Socket = js.native
49+
50+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
51+ def writableEnded : Boolean = js.native
52+
53+ @ enableIf(io.scalajs.nodejs.CompilerSwitches .gteNodeJs12)
54+ def writableFinished : Boolean = js.native
3955
4056 // ///////////////////////////////////////////////////////////////////////////////
4157 // Methods
@@ -48,34 +64,6 @@ class ClientRequest extends Readable {
4864 */
4965 def abort (): Unit = js.native
5066
51- /**
52- * Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream.
53- * If the request is chunked, this will send the terminating '0\r\n\r\n'.
54- * @see [[https://nodejs.org/api/http.html#http_request_end_data_encoding_callback ]]
55- */
56- def end (data : js.Any , encoding : String , callback : js.Function ): Unit = js.native
57-
58- /**
59- * Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream.
60- * If the request is chunked, this will send the terminating '0\r\n\r\n'.
61- * @see [[https://nodejs.org/api/http.html#http_request_end_data_encoding_callback ]]
62- */
63- def end (data : js.Any , encoding : String ): Unit = js.native
64-
65- /**
66- * Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream.
67- * If the request is chunked, this will send the terminating '0\r\n\r\n'.
68- * @see [[https://nodejs.org/api/http.html#http_request_end_data_encoding_callback ]]
69- */
70- def end (data : js.Any ): Unit = js.native
71-
72- /**
73- * Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream.
74- * If the request is chunked, this will send the terminating '0\r\n\r\n'.
75- * @see [[https://nodejs.org/api/http.html#http_request_end_data_encoding_callback ]]
76- */
77- def end (): Unit = js.native
78-
7967 /**
8068 * Flush the request headers.
8169 *
@@ -90,39 +78,27 @@ class ClientRequest extends Readable {
9078 */
9179 def flushHeaders (): Unit = js.native
9280
93- /**
94- * Once a socket is assigned to this request and is connected socket.setNoDelay() will be called.
95- */
96- def setNoDelay (noDelay : Int ): Unit = js.native
81+ def getHeader [T <: js.Any ](name : String ): T = js.native
9782
98- /**
99- * Once a socket is assigned to this request and is connected socket.setNoDelay() will be called.
100- */
101- def setNoDelay (): Unit = js.native
83+ def removeHeader (name : String ): Unit = js.native
10284
103- /**
104- * Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called.
105- * @see [[https://nodejs.org/api/http.html#http_request_setsocketkeepalive_enable_initialdelay ]]
106- */
107- def setSocketKeepAlive (enable : Boolean , initialDelay : Int ): Unit = js.native
85+ def setHeader (name : String , value : js.Any ): Unit = js.native
10886
10987 /**
110- * Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called.
111- * @see [[https://nodejs.org/api/http.html#http_request_setsocketkeepalive_enable_initialdelay ]]
88+ * Once a socket is assigned to this request and is connected socket.setNoDelay() will be called.
11289 */
113- def setSocketKeepAlive ( enable : Boolean ): Unit = js.native
90+ def setNoDelay ( noDelay : Int ): Unit = js.native
11491
11592 /**
116- * Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called.
117- * @see [[https://nodejs.org/api/http.html#http_request_setsocketkeepalive_enable_initialdelay ]]
93+ * Once a socket is assigned to this request and is connected socket.setNoDelay() will be called.
11894 */
119- def setSocketKeepAlive ( initialDelay : Int ): Unit = js.native
95+ def setNoDelay ( noDelay : Boolean = js.native ): Unit = js.native
12096
12197 /**
12298 * Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called.
12399 * @see [[https://nodejs.org/api/http.html#http_request_setsocketkeepalive_enable_initialdelay ]]
124100 */
125- def setSocketKeepAlive (): Unit = js.native
101+ def setSocketKeepAlive (enable : Boolean = js.native, initialDelay : Int = js.native ): Unit = js.native
126102
127103 /**
128104 * Once a socket is assigned to this request and is connected socket.setTimeout() will be called.
@@ -132,53 +108,7 @@ class ClientRequest extends Readable {
132108 * Same as binding to the timeout event.</li>
133109 * </ul>
134110 */
135- def setTimeout (timeout : Int , callback : js.Function ): Unit = js.native
136-
137- /**
138- * Once a socket is assigned to this request and is connected socket.setTimeout() will be called.
139- * <ul>
140- * <li>timeout {Number} Milliseconds before a request is considered to be timed out.</li>
141- * <li>callback {Function} Optional function to be called when a timeout occurs.
142- * Same as binding to the timeout event.</li>
143- * </ul>
144- */
145- def setTimeout (timeout : Int ): Unit = js.native
146-
147- /**
148- * Sends a chunk of the body. By calling this method many times, the user can stream a
149- * request body to a server--in that case it is suggested to use the ['Transfer-Encoding', 'chunked']
150- * header line when creating the request.
151- *
152- * The chunk argument should be a Buffer or a string.
153- * The encoding argument is optional and only applies when chunk is a string. Defaults to 'utf8'.
154- * The callback argument is optional and will be called when this chunk of data is flushed.
155- * Returns request.
156- */
157- def write (chunk : js.Any , encoding : String , callback : js.Function ): Unit = js.native
158-
159- /**
160- * Sends a chunk of the body. By calling this method many times, the user can stream a
161- * request body to a server--in that case it is suggested to use the ['Transfer-Encoding', 'chunked']
162- * header line when creating the request.
163- *
164- * The chunk argument should be a Buffer or a string.
165- * The encoding argument is optional and only applies when chunk is a string. Defaults to 'utf8'.
166- * The callback argument is optional and will be called when this chunk of data is flushed.
167- * Returns request.
168- */
169- def write (chunk : js.Any , encoding : String ): Unit = js.native
170-
171- /**
172- * Sends a chunk of the body. By calling this method many times, the user can stream a
173- * request body to a server--in that case it is suggested to use the ['Transfer-Encoding', 'chunked']
174- * header line when creating the request.
175- *
176- * The chunk argument should be a Buffer or a string.
177- * The encoding argument is optional and only applies when chunk is a string. Defaults to 'utf8'.
178- * The callback argument is optional and will be called when this chunk of data is flushed.
179- * Returns request.
180- */
181- def write (chunk : js.Any ): Unit = js.native
111+ def setTimeout (timeout : Int , callback : js.Function = js.native): Unit = js.native
182112
183113}
184114
@@ -187,10 +117,7 @@ class ClientRequest extends Readable {
187117 */
188118object ClientRequest {
189119
190- /**
191- * Client Request Events
192- */
193- implicit class ClientRequestEvents (val client : ClientRequest ) extends AnyVal {
120+ implicit final class ClientRequestExtensions (val client : ClientRequest ) extends AnyVal {
194121
195122 /**
196123 * Emitted when the request has been aborted by the client. This event is only emitted on the first call to abort().
@@ -246,23 +173,25 @@ object ClientRequest {
246173 @ inline
247174 def onUpgrade (callback : (IncomingMessage , Socket , Buffer ) => Any ): client.type = client.on(" upgrade" , callback)
248175
249- }
250-
251- /**
252- * Client Request Extensions
253- */
254- implicit class ClientRequestEnrichment (val client : ClientRequest ) extends AnyVal {
176+ @ inline
177+ def endFuture (data : Uint8Array ): Future [Unit ] = {
178+ promiseWithError0[Error ](client.end(data, _))
179+ }
255180
256181 @ inline
257- def endFuture (data : js. Any , encoding : String ): Future [js. Any ] = {
258- promiseWithError1[ SystemError , js. Any ](client.end(data, encoding, _))
182+ def endFuture (data : String , encoding : String ): Future [Unit ] = {
183+ promiseWithError0[ Error ](client.end(data, encoding, _))
259184 }
260185
261186 @ inline
262- def writeFuture (chunk : js. Any , encoding : String ): Future [js. Any ] = {
263- promiseWithError1[ SystemError , js. Any ](client.write(chunk, encoding , _))
187+ def writeFuture (chunk : Uint8Array ): Future [Unit ] = {
188+ promiseWithError0[ Error ](client.write(chunk, _))
264189 }
265190
191+ @ inline
192+ def writeFuture (chunk : String , encoding : String ): Future [Unit ] = {
193+ promiseWithError0[Error ](client.write(chunk, encoding, _))
194+ }
266195 }
267196
268197}
0 commit comments