@@ -37,6 +37,7 @@ def show(m: Method): String = m match {
37
37
/// Each of method, hostname, path, port, and protocol must be called at least once!
38
38
interface RequestBuilder {
39
39
def method(method: Method): Unit
40
+ def auth(authStr: String): Unit
40
41
def hostname(host: String): Unit
41
42
def path(path: String): Unit
42
43
def port(port: Int): Unit
@@ -195,6 +196,7 @@ namespace jsNode {
195
196
var reqBody: ByteArray = allocate(0)
196
197
try body() with RequestBuilder {
197
198
def method(m) = resume(options.js::set("method", m.show))
199
+ def auth(a) = resume(options.js::set("auth", a))
198
200
def hostname(n) = resume(options.js::set("hostname", n))
199
201
def path(p) = resume(options.js::set("path", p))
200
202
def port(p) = resume(options.js::set("port", p))
@@ -249,19 +251,22 @@ namespace jsWeb {
249
251
val options = js::empty()
250
252
options.js::set("headers", js::empty())
251
253
var protocol = HTTPS()
254
+ var auth = None()
252
255
var hostname = ""
253
256
var path = "/"
254
257
var port = None()
255
258
try body() with RequestBuilder {
256
259
def method(m) = resume(options.js::set("method", m.show))
260
+ def auth(a) = resume(auth = Some(a))
257
261
def hostname(n) = resume(hostname = n)
258
262
def path(p) = resume(path = p)
259
263
def port(p) = resume(port = Some(p))
260
264
def header(k, v) = resume(options.js::set("headers", k, v))
261
265
def protocol(p) = resume(protocol = p)
262
266
def body() = resume{ {wr} => options.js::set("body", collectBytes{wr}) }
263
267
}
264
- val url = s"${protocol.show}://${hostname}:${port.getOrElse{ protocol.defaultPort }.show}${path}"
268
+ val authStr = auth.map{ a => a ++ "@" }.getOrElse{ "" }
269
+ val url = s"${protocol.show}://${authStr}${hostname}:${port.getOrElse{ protocol.defaultPort }.show}${path}"
265
270
val res = run(url, options)
266
271
if(res.isError) { println(res.genericShow); do raise(RequestError(), "Request failed") }
267
272
@@ -284,7 +289,7 @@ def uri(uri: String): Unit / { RequestBuilder, Exception[WrongFormat] } = {
284
289
case "HTTPS" => do protocol(HTTPS())
285
290
case _ => do raise(WrongFormat(), "Unsupported protocol " ++ sc)
286
291
})
287
- def userinfo(u) = <>
292
+ def userinfo(u) = resume(do auth(u))
288
293
def host(h) = resume(do hostname(h))
289
294
def port(p) = resume(do port(p))
290
295
def path(p) = resume(do write(p))
0 commit comments