Skip to content

Instantly share code, notes, and snippets.

@fasterthanlime
Created March 15, 2015 21:58
Show Gist options
  • Save fasterthanlime/4054068d7c640c72c45f to your computer and use it in GitHub Desktop.
Save fasterthanlime/4054068d7c640c72c45f to your computer and use it in GitHub Desktop.
use microhttpd
import microhttpd/microhttpd
handleRequest: func (
cls: Pointer,
connection: MHDConnection,
url: CString, method: CString,
_version: CString,
uploadData: CString,
uploadDataSize: SizeT,
conCls: Pointer) -> Int {
page := "<html><body>Hello, browser!</body></html>"
response := MHDResponse createFromBuffer(page size, page toCString(),
MHDResponseMemoryMode persistent)
ret := connection queueResponse(200, response)
response destroy()
ret
}
main: func {
port := 4141
daemon := MHDDaemon start(
MHDFlag selectInternally, port,
null, null,
handleRequest&, null,
MHDOption end)
"Listening on port #{port}" println()
stdin readLine()
daemon stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment