-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpData.fs
More file actions
59 lines (47 loc) · 1.27 KB
/
HttpData.fs
File metadata and controls
59 lines (47 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module HttpData
open System.IO
open System.Net
open System.Text
open HttpHeaders
type http_version =
| HTTPV_10
| HTTPV_11
| HTTPV_Other of string
let httpversion_of_string =
function
| "1.0" -> HTTPV_10
| "1.1" -> HTTPV_11
| version -> HTTPV_Other version
let string_of_httpversion =
function
| HTTPV_10 -> "1.0"
| HTTPV_11 -> "1.1"
| HTTPV_Other v -> v
type HttpServerConfig =
{ docroot: string
mimesmap: Mime.MimeMap
localaddr: IPEndPoint
servname: string }
type HttpBody =
| HB_Raw of byte[]
| HB_Stream of Stream * int64
let http_body_length =
function
| HB_Raw bytes -> int64 bytes.Length
| HB_Stream(_, length) -> length
type HttpResponse =
{ code: HttpCode.httpcode
headers: HttpHeaders
body: HttpBody }
type HttpRequest =
{ version: http_version
mthod: string
path: string
headers: HttpHeaders }
let http_response_of_code =
fun code ->
let message = HB_Raw(Encoding.ASCII.GetBytes(HttpCode.http_message code)) in
let headers = HttpHeaders.OfList [ ("Content-Type", "text/plain;charset=US-ASCII") ] in
{ code = code
headers = headers
body = message }