Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Nov 23, 2024
1 parent 36c250d commit df63952
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions vlib/net/http/server_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,31 @@ fn test_my_counting_handler_on_random_port() {
}
assert true
}

//

struct MyCustomHttpHostHandler {}

fn (mut handler MyCustomHttpHostHandler) handle(req http.Request) http.Response {
dump(req.header)
return http.Response{
body: 'Host was: ${req.header.get(.host) or { '-' }}'
}
}

fn test_host_header_sent_to_server() {
port := 54671
log.warn('${@FN} started')
defer { log.warn('${@FN} finished') }
mut server := &http.Server{
handler: MyCustomHttpHostHandler{}
addr: ':${port}'
}
t := spawn server.listen_and_serve()
server.wait_till_running()!
defer { server.stop() }
dump(server.addr)
x := http.get('http://${server.addr}/')!
dump(x)
assert x.body.ends_with(':${port}')
}

1 comment on commit df63952

@spytheman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result on Ubuntu:
Image

Please sign in to comment.