|
// retoor <retoor@molodetz.nl>
|
|
|
|
import "web" for Response
|
|
|
|
var r1 = Response.redirect("/dashboard", 301)
|
|
System.print(r1.status) // expect: 301
|
|
System.print(r1.headers["Location"]) // expect: /dashboard
|
|
|
|
var r2 = Response.new()
|
|
r2.status = 404
|
|
r2.body = "Not Found"
|
|
System.print(r2.status) // expect: 404
|
|
System.print(r2.body) // expect: Not Found
|
|
|
|
var r3 = Response.new()
|
|
r3.header("X-Custom", "value1")
|
|
r3.header("X-Another", "value2")
|
|
System.print(r3.headers["X-Custom"]) // expect: value1
|
|
System.print(r3.headers["X-Another"]) // expect: value2
|
|
|
|
var r4 = Response.new()
|
|
r4.cookie("session", "abc123")
|
|
r4.body = "test"
|
|
var built = r4.build()
|
|
System.print(built.contains("Set-Cookie: session=abc123")) // expect: true
|
|
|
|
var r5 = Response.new()
|
|
r5.cookie("auth", "token", {"path": "/", "httpOnly": true, "maxAge": 3600})
|
|
r5.body = "test"
|
|
var built2 = r5.build()
|
|
System.print(built2.contains("Path=/")) // expect: true
|
|
System.print(built2.contains("HttpOnly")) // expect: true
|
|
System.print(built2.contains("Max-Age=3600")) // expect: true
|
|
|
|
var r6 = Response.text("Hello World")
|
|
var httpResponse = r6.build()
|
|
System.print(httpResponse.contains("HTTP/1.1 200 OK")) // expect: true
|
|
System.print(httpResponse.contains("Content-Length:")) // expect: true
|
|
System.print(httpResponse.contains("Hello World")) // expect: true
|