-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathHttp.fs
More file actions
2414 lines (2053 loc) · 95.6 KB
/
Http.fs
File metadata and controls
2414 lines (2053 loc) · 95.6 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// --------------------------------------------------------------------------------------
// Utilities for working with network, downloading resources with specified headers etc.
// --------------------------------------------------------------------------------------
namespace FSharp.Data
open System
open System.Globalization
open System.IO
open System.Net
open System.Text
open System.Text.RegularExpressions
open System.Threading
open System.Runtime.CompilerServices
open System.Runtime.ExceptionServices
open System.Runtime.InteropServices
/// The method to use in an HTTP request
module HttpMethod =
// RFC 2626 specifies 8 methods
/// Request information about the communication options available on the request/response chain identified by the URI
let Options = "OPTIONS"
/// Retrieve whatever information (in the form of an entity) is identified by the URI
let Get = "GET"
/// Identical to GET except that the server MUST NOT return a message-body in the response
let Head = "HEAD"
/// Requests that the server accepts the entity enclosed in the request as a
/// new subordinate of the resource identified by the Request-URI in the Request-Line
let Post = "POST"
/// Requests that the enclosed entity be stored under the supplied Request-URI
let Put = "PUT"
/// Requests that the origin server deletes the resource identified by the Request-URI
let Delete = "DELETE"
/// Used to invoke a remote, application-layer loop- back of the request message
let Trace = "TRACE"
/// Reserved for use with a proxy that can dynamically switch to being a tunnel
let Connect = "CONNECT"
// RFC 4918 (WebDAV) adds 7 methods
/// Retrieves properties defined on the resource identified by the request URI
let PropFind = "PROPFIND"
/// Processes instructions specified in the request body to set and/or remove properties defined on the resource identified by the request URI
let PropPatch = "PROPPATCH"
/// Creates a new collection resource at the location specified by the Request URI
let MkCol = "MKCOL"
/// Creates a duplicate of the source resource, identified by the Request-URI, in the destination resource, identified by the URI in the Destination header
let Copy = "COPY"
/// Logical equivalent of a copy, followed by consistency maintenance processing, followed by a delete of the source where all three actions are performed atomically
let Move = "MOVE"
/// Used to take out a lock of any access type on the resource identified by the request URI.
let Lock = "LOCK"
/// Removes the lock identified by the lock token from the request URI, and all other resources included in the lock
let Unlock = "UNLOCK"
// RFC 5789 adds one more
/// Requests that the origin server applies partial modifications contained in the entity enclosed in the request to the resource identified by the request URI
let Patch = "PATCH"
/// Headers that can be sent in an HTTP request
module HttpRequestHeaders =
/// Content-Types that are acceptable for the response
let Accept (contentType: string) = "Accept", contentType
/// Character sets that are acceptable
let AcceptCharset (characterSets: string) = "Accept-Charset", characterSets
/// Acceptable version in time
let AcceptDatetime (dateTime: DateTime) =
"Accept-Datetime", dateTime.ToString("R", CultureInfo.InvariantCulture)
/// List of acceptable encodings. See HTTP compression.
let AcceptEncoding (encoding: string) = "Accept-Encoding", encoding
/// List of acceptable human languages for response
let AcceptLanguage (language: string) = "Accept-Language", language
/// The Allow header, which specifies the set of HTTP methods supported.
let Allow (methods: string) = "Allow", methods
/// Authentication credentials for HTTP authentication
let Authorization (credentials: string) = "Authorization", credentials
/// Authentication header using Basic Auth encoding
let BasicAuth (username: string) (password: string) =
let base64Encode (s: string) =
let bytes = Encoding.UTF8.GetBytes(s)
Convert.ToBase64String(bytes)
sprintf "%s:%s" username password
|> base64Encode
|> sprintf "Basic %s"
|> Authorization
/// Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain
let CacheControl (control: string) = "Cache-Control", control
/// What type of connection the user-agent would prefer
let Connection (connection: string) = "Connection", connection
/// Describes the placement of the content. Valid dispositions are: inline, attachment, form-data
let ContentDisposition (placement: string, name: string option, fileName: string option) =
let namePart =
match name with
| Some n -> sprintf "; name=\"%s\"" n
| None -> ""
let fileNamePart =
match fileName with
| Some n -> sprintf "; filename=\"%s\"" n
| None -> ""
"Content-Disposition", sprintf "%s%s%s" placement namePart fileNamePart
/// The type of encoding used on the data
let ContentEncoding (encoding: string) = "Content-Encoding", encoding
/// The language the content is in
let ContentLanguage (language: string) = "Content-Language", language
/// An alternate location for the returned data
let ContentLocation (location: string) = "Content-Location", location
/// A Base64-encoded binary MD5 sum of the content of the request body
let ContentMD5 (md5sum: string) = "Content-MD5", md5sum
/// Where in a full body message this partial message belongs
let ContentRange (range: string) = "Content-Range", range
/// The MIME type of the body of the request (used with POST and PUT requests)
let ContentType (contentType: string) = "Content-Type", contentType
/// The MIME type of the body of the request (used with POST and PUT requests) with an explicit encoding
let ContentTypeWithEncoding (contentType, charset: Encoding) =
"Content-Type", sprintf "%s; charset=%s" contentType (charset.WebName)
/// The date and time that the message was sent
let Date (date: DateTime) =
"Date", date.ToString("R", CultureInfo.InvariantCulture)
/// Indicates that particular server behaviors are required by the client
let Expect (behaviors: string) = "Expect", behaviors
/// Gives the date/time after which the response is considered stale
let Expires (dateTime: DateTime) =
"Expires", dateTime.ToString("R", CultureInfo.InvariantCulture)
/// The email address of the user making the request
let From (email: string) = "From", email
/// The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening.
/// The port number may be omitted if the port is the standard port for the service requested.
let Host (host: string) = "Host", host
/// Only perform the action if the client supplied entity matches the same entity on the server.
/// This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it. If-Match: "737060cd8c284d8af7ad3082f209582d" Permanent
let IfMatch (entity: string) = "If-Match", entity
/// Allows a 304 Not Modified to be returned if content is unchanged
let IfModifiedSince (dateTime: DateTime) =
"If-Modified-Since", dateTime.ToString("R", CultureInfo.InvariantCulture)
/// Allows a 304 Not Modified to be returned if content is unchanged
let IfNoneMatch (etag: string) = "If-None-Match", etag
/// If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity
let IfRange (range: string) = "If-Range", range
/// Only send the response if the entity has not been modified since a specific time
let IfUnmodifiedSince (dateTime: DateTime) =
"If-Unmodified-Since", dateTime.ToString("R", CultureInfo.InvariantCulture)
/// Specifies a parameter used into order to maintain a persistent connection
let KeepAlive (keepAlive: string) = "Keep-Alive", keepAlive
/// Specifies the date and time at which the accompanying body data was last modified
let LastModified (dateTime: DateTime) =
"Last-Modified", dateTime.ToString("R", CultureInfo.InvariantCulture)
/// Limit the number of times the message can be forwarded through proxies or gateways
let MaxForwards (count: int) = "Max-Forwards", count.ToString()
/// Initiates a request for cross-origin resource sharing (asks server for an 'Access-Control-Allow-Origin' response header)
let Origin (origin: string) = "Origin", origin
/// Implementation-specific headers that may have various effects anywhere along the request-response chain.
let Pragma (pragma: string) = "Pragma", pragma
/// Optional instructions to the server to control request processing. See RFC https://tools.ietf.org/html/rfc7240 for more details
let Prefer (prefer: string) = "Prefer", prefer
/// Authorization credentials for connecting to a proxy.
let ProxyAuthorization (credentials: string) = "Proxy-Authorization", credentials
/// Request only part of an entity. Bytes are numbered from 0
let Range (start: int64, finish: int64) =
"Range", sprintf "bytes=%d-%d" start finish
/// This is the address of the previous web page from which a link to the currently requested page was followed. (The word "referrer" is misspelled in the RFC as well as in most implementations.)
let Referer (referer: string) = "Referer", referer
/// The transfer encodings the user agent is willing to accept: the same values as for the response header
/// Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to
/// notify the server it expects to receive additional headers (the trailers) after the last, zero-sized, chunk.
let TE (te: string) = "TE", te
/// The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding
let Trailer (trailer: string) = "Trailer", trailer
/// The TransferEncoding header indicates the form of encoding used to safely transfer the entity to the user. The valid directives are one of: chunked, compress, deflate, gzip, or identity.
let TransferEncoding (directive: string) = "Transfer-Encoding", directive
/// Microsoft extension to the HTTP specification used in conjunction with WebDAV functionality.
let Translate (translate: string) = "Translate", translate
/// Specifies additional communications protocols that the client supports.
let Upgrade (upgrade: string) = "Upgrade", upgrade
/// The user agent string of the user agent
let UserAgent (userAgent: string) = "User-Agent", userAgent
/// Informs the server of proxies through which the request was sent
let Via (server: string) = "Via", server
/// A general warning about possible problems with the entity body
let Warning (message: string) = "Warning", message
/// Override HTTP method.
let XHTTPMethodOverride (httpMethod: string) = "X-HTTP-Method-Override", httpMethod
/// Headers that can be received in an HTTP response
module HttpResponseHeaders =
/// Specifying which web sites can participate in cross-origin resource sharing
[<Literal>]
let AccessControlAllowOrigin = "Access-Control-Allow-Origin"
/// What partial content range types this server supports
[<Literal>]
let AcceptRanges = "Accept-Ranges"
/// The age the object has been in a proxy cache in seconds
[<Literal>]
let Age = "Age"
/// Valid actions for a specified resource. To be used for a 405 Method not allowed
[<Literal>]
let Allow = "Allow"
/// Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds
[<Literal>]
let CacheControl = "Cache-Control"
/// Options that are desired for the connection
[<Literal>]
let Connection = "Connection"
/// The type of encoding used on the data. See HTTP compression.
[<Literal>]
let ContentEncoding = "Content-Encoding"
/// The language the content is in
[<Literal>]
let ContentLanguage = "Content-Language"
/// The length of the response body in octets (8-bit bytes)
[<Literal>]
let ContentLength = "Content-Length"
/// An alternate location for the returned data
[<Literal>]
let ContentLocation = "Content-Location"
/// A Base64-encoded binary MD5 sum of the content of the response
[<Literal>]
let ContentMD5 = "Content-MD5"
/// An opportunity to raise a "File Download" dialogue box for a known MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.
[<Literal>]
let ContentDisposition = "Content-Disposition"
/// Where in a full body message this partial message belongs
[<Literal>]
let ContentRange = "Content-Range"
/// The MIME type of this content
[<Literal>]
let ContentType = "Content-Type"
/// The date and time that the message was sent (in "HTTP-date" format as defined by RFC 2616)
[<Literal>]
let Date = "Date"
/// An identifier for a specific version of a resource, often a message digest
[<Literal>]
let ETag = "ETag"
/// Gives the date/time after which the response is considered stale
[<Literal>]
let Expires = "Expires"
/// The last modified date for the requested object
[<Literal>]
let LastModified = "Last-Modified"
/// Used to express a typed relationship with another resource, where the relation type is defined by RFC 5988
[<Literal>]
let Link = "Link"
/// Used in redirection, or when a new resource has been created.
[<Literal>]
let Location = "Location"
/// This header is supposed to set P3P policy
[<Literal>]
let P3P = "P3P"
/// Implementation-specific headers that may have various effects anywhere along the request-response chain.
[<Literal>]
let Pragma = "Pragma"
/// Request authentication to access the proxy.
[<Literal>]
let ProxyAuthenticate = "Proxy-Authenticate"
/// Used in redirection, or when a new resource has been created. This refresh redirects after 5 seconds.
[<Literal>]
let Refresh = "Refresh"
/// If an entity is temporarily unavailable, this instructs the client to try again later. Value could be a specified period of time (in seconds) or a HTTP-date.[28]
[<Literal>]
let RetryAfter = "Retry-After"
/// A name for the server
[<Literal>]
let Server = "Server"
/// An HTTP cookie
[<Literal>]
let SetCookie = "Set-Cookie"
/// The HTTP status of the response
[<Literal>]
let Status = "Status"
/// A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.
[<Literal>]
let StrictTransportSecurity = "Strict-Transport-Security"
/// The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding.
[<Literal>]
let Trailer = "Trailer"
/// The form of encoding used to safely transfer the entity to the user. Currently defined methods are: chunked, compress, deflate, gzip, identity.
[<Literal>]
let TransferEncoding = "Transfer-Encoding"
/// Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.
[<Literal>]
let Vary = "Vary"
/// Informs the client of proxies through which the response was sent.
[<Literal>]
let Via = "Via"
/// A general warning about possible problems with the entity body.
[<Literal>]
let Warning = "Warning"
/// Indicates the authentication scheme that should be used to access the requested entity.
[<Literal>]
let WWWAuthenticate = "WWW-Authenticate"
/// Status codes that can be received in an HTTP response
module HttpStatusCodes =
/// The server has received the request headers and the client should proceed to send the request body.
[<Literal>]
let Continue = 100
/// The requester has asked the server to switch protocols and the server has agreed to do so.
[<Literal>]
let SwitchingProtocols = 101
/// This code indicates that the server has received and is processing the request, but no response is available yet.
[<Literal>]
let Processing = 102
/// Used to return some response headers before final HTTP message.
[<Literal>]
let EarlyHints = 103
/// Standard response for successful HTTP requests.
[<Literal>]
let OK = 200
/// The request has been fulfilled, resulting in the creation of a new resource.
[<Literal>]
let Created = 201
/// The request has been accepted for processing, but the processing has not been completed.
[<Literal>]
let Accepted = 202
/// The server is a transforming proxy (e.g. a Web accelerator) that received a 200 OK from its origin, but is returning a modified version of the origin's response.
[<Literal>]
let NonAuthoritativeInformation = 203
/// The server successfully processed the request and is not returning any content.
[<Literal>]
let NoContent = 204
/// The server successfully processed the request, but is not returning any content.
[<Literal>]
let ResetContent = 205
/// The server is delivering only part of the resource (byte serving) due to a range header sent by the client.
[<Literal>]
let PartialContent = 206
/// The message body that follows is by default an XML message and can contain a number of separate response codes, depending on how many sub-requests were made.
[<Literal>]
let MultiStatus = 207
/// The members of a DAV binding have already been enumerated in a preceding part of the (multistatus) response, and are not being included again.
[<Literal>]
let AlreadyReported = 208
/// The server has fulfilled a request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.
[<Literal>]
let IMUsed = 226
/// Indicates multiple options for the resource from which the client may choose (via agent-driven content negotiation).
[<Literal>]
let MultipleChoices = 300
/// This and all future requests should be directed to the given URI.
[<Literal>]
let MovedPermanently = 301
/// Tells the client to look at (browse to) another url. 302 has been superseded by 303 and 307.
[<Literal>]
let Found = 302
/// The response to the request can be found under another URI using the GET method.
[<Literal>]
let SeeOther = 303
/// Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match.
[<Literal>]
let NotModified = 304
/// The requested resource is available only through a proxy, the address for which is provided in the response.
[<Literal>]
let UseProxy = 305
/// No longer used. Originally meant "Subsequent requests should use the specified proxy."
[<Literal>]
let SwitchProxy = 306
/// In this case, the request should be repeated with another URI; however, future requests should still use the original URI.
[<Literal>]
let TemporaryRedirect = 307
/// The request and all future requests should be repeated using another URI.
[<Literal>]
let PermanentRedirect = 308
/// The server cannot or will not process the request due to an apparent client error.
[<Literal>]
let BadRequest = 400
/// Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided.
[<Literal>]
let Unauthorized = 401
/// Reserved for future use.
[<Literal>]
let PaymentRequired = 402
/// The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account of some sort.
[<Literal>]
let Forbidden = 403
/// The requested resource could not be found but may be available in the future. Subsequent requests by the client are permissible.
[<Literal>]
let NotFound = 404
/// A request method is not supported for the requested resource.
[<Literal>]
let MethodNotAllowed = 405
/// The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request.
[<Literal>]
let NotAcceptable = 406
/// The client must first authenticate itself with the proxy.
[<Literal>]
let ProxyAuthenticationRequired = 407
/// The server timed out waiting for the request.
[<Literal>]
let RequestTimeout = 408
/// Indicates that the request could not be processed because of conflict in the request, such as an edit conflict between multiple simultaneous updates.
[<Literal>]
let Conflict = 409
/// Indicates that the resource requested is no longer available and will not be available again.
[<Literal>]
let Gone = 410
/// The request did not specify the length of its content, which is required by the requested resource.
[<Literal>]
let LengthRequired = 411
/// The server does not meet one of the preconditions that the requester put on the request.
[<Literal>]
let PreconditionFailed = 412
/// The request is larger than the server is willing or able to process.
[<Literal>]
let PayloadTooLarge = 413
/// The URI provided was too long for the server to process.
[<Literal>]
let URITooLong = 414
/// The request entity has a media type which the server or resource does not support.
[<Literal>]
let UnsupportedMediaType = 415
/// The client has asked for a portion of the file (byte serving), but the server cannot supply that portion.
[<Literal>]
let RangeNotSatisfiable = 416
/// The server cannot meet the requirements of the Expect request-header field.
[<Literal>]
let ExpectationFailed = 417
/// The request was directed at a server that is not able to produce a response.
[<Literal>]
let MisdirectedRequest = 421
/// The request was well-formed but was unable to be followed due to semantic errors.
[<Literal>]
let UnprocessableEntity = 422
/// The resource that is being accessed is locked.
[<Literal>]
let Locked = 423
/// The request failed because it depended on another request and that request failed (e.g., a PROPPATCH).
[<Literal>]
let FailedDependency = 424
/// The client should switch to a different protocol such as TLS/1.0, given in the Upgrade header field.
[<Literal>]
let UpgradeRequired = 426
/// The origin server requires the request to be conditional.
[<Literal>]
let PreconditionRequired = 428
/// The user has sent too many requests in a given amount of time.
[<Literal>]
let TooManyRequests = 429
/// The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large.
[<Literal>]
let RequestHeaderFieldsTooLarge = 431
/// A server operator has received a legal demand to deny access to a resource or to a set of resources that includes the requested resource.
[<Literal>]
let UnavailableForLegalReasons = 451
/// A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
[<Literal>]
let InternalServerError = 500
/// The server either does not recognize the request method, or it lacks the ability to fulfil the request.
[<Literal>]
let NotImplemented = 501
/// The server was acting as a gateway or proxy and received an invalid response from the upstream server.
[<Literal>]
let BadGateway = 502
/// The server is currently unavailable (because it is overloaded or down for maintenance).
[<Literal>]
let ServiceUnavailable = 503
/// The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
[<Literal>]
let GatewayTimeout = 504
/// The server does not support the HTTP protocol version used in the request.
[<Literal>]
let HTTPVersionNotSupported = 505
/// Transparent content negotiation for the request results in a circular reference.
[<Literal>]
let VariantAlsoNegotiates = 506
/// The server is unable to store the representation needed to complete the request.
[<Literal>]
let InsufficientStorage = 507
/// The server detected an infinite loop while processing the request.
[<Literal>]
let LoopDetected = 508
/// Further extensions to the request are required for the server to fulfil it.
[<Literal>]
let NotExtended = 510
/// The client needs to authenticate to gain network access.
[<Literal>]
let NetworkAuthenticationRequired = 511
type MultipartItem = MultipartItem of formField: string * filename: string * content: Stream
type MultipartFileItem =
| MultipartFileItem of formField: string * filename: string option * contentType: string option * content: Stream
type MultipartFormDataItem =
| FileValue of MultipartFileItem
| FormValue of string * string
/// The body to send in an HTTP request
type HttpRequestBody =
| TextRequest of string
| BinaryUpload of byte[]
| FormValues of seq<string * string>
/// A sequence of formParamName * fileName * fileContent groups
| Multipart of boundary: string * parts: seq<MultipartItem>
/// A sequence of formParamName * fileName * fileContent groups
| MultipartFormData of boundary: string * parts: seq<MultipartFormDataItem>
/// The response body returned by an HTTP request
type HttpResponseBody =
| Text of string
| Binary of byte[]
/// The response returned by an HTTP request
type HttpResponse =
{
Body: HttpResponseBody
StatusCode: int
ResponseUrl: string
/// If the same header is present multiple times, the values will be concatenated with comma as the separator
Headers: Map<string, string>
Cookies: Map<string, string>
}
/// The response returned by an HTTP request with direct access to the response stream
type HttpResponseWithStream =
{
ResponseStream: Stream
StatusCode: int
ResponseUrl: string
/// If the same header is present multiple times, the values will be concatenated with comma as the separator
Headers: Map<string, string>
Cookies: Map<string, string>
}
/// Constants for common HTTP content types
module HttpContentTypes =
/// */*
[<Literal>]
let Any = "*/*"
/// plain/text
[<Literal>]
let Text = "text/plain"
/// application/octet-stream
[<Literal>]
let Binary = "application/octet-stream"
/// application/octet-stream
[<Literal>]
let Zip = "application/zip"
/// application/octet-stream
[<Literal>]
let GZip = "application/gzip"
/// application/x-www-form-urlencoded
[<Literal>]
let FormValues = "application/x-www-form-urlencoded"
/// application/json
[<Literal>]
let Json = "application/json"
/// application/javascript
[<Literal>]
let JavaScript = "application/javascript"
/// application/xml
[<Literal>]
let Xml = "application/xml"
/// application/rss+xml
[<Literal>]
let Rss = "application/rss+xml"
/// application/atom+xml
[<Literal>]
let Atom = "application/atom+xml"
/// application/rdf+xml
[<Literal>]
let Rdf = "application/rdf+xml"
/// text/html
[<Literal>]
let Html = "text/html"
/// application/xhtml+xml
[<Literal>]
let XHtml = "application/xhtml+xml"
/// application/soap+xml
[<Literal>]
let Soap = "application/soap+xml"
/// text/csv
[<Literal>]
let Csv = "text/csv"
/// application/json-rpc
[<Literal>]
let JsonRpc = "application/json-rpc"
/// multipart/form-data
let Multipart boundary =
sprintf "multipart/form-data; boundary=%s" boundary
type private HeaderEnum = System.Net.HttpRequestHeader
module MimeTypes =
open System.Collections.Generic
let private pairs =
[| (".323", "text/h323")
(".3g2", "video/3gpp2")
(".3gp", "video/3gpp")
(".3gp2", "video/3gpp2")
(".3gpp", "video/3gpp")
(".7z", "application/x-7z-compressed")
(".aa", "audio/audible")
(".AAC", "audio/aac")
(".aaf", "application/octet-stream")
(".aax", "audio/vnd.audible.aax")
(".ac3", "audio/ac3")
(".aca", "application/octet-stream")
(".accda", "application/msaccess.addin")
(".accdb", "application/msaccess")
(".accdc", "application/msaccess.cab")
(".accde", "application/msaccess")
(".accdr", "application/msaccess.runtime")
(".accdt", "application/msaccess")
(".accdw", "application/msaccess.webapplication")
(".accft", "application/msaccess.ftemplate")
(".acx", "application/internet-property-stream")
(".AddIn", "text/xml")
(".ade", "application/msaccess")
(".adobebridge", "application/x-bridge-url")
(".adp", "application/msaccess")
(".ADT", "audio/vnd.dlna.adts")
(".ADTS", "audio/aac")
(".afm", "application/octet-stream")
(".ai", "application/postscript")
(".aif", "audio/aiff")
(".aifc", "audio/aiff")
(".aiff", "audio/aiff")
(".air", "application/vnd.adobe.air-application-installer-package+zip")
(".amc", "application/mpeg")
(".anx", "application/annodex")
(".apk", "application/vnd.android.package-archive")
(".application", "application/x-ms-application")
(".art", "image/x-jg")
(".asa", "application/xml")
(".asax", "application/xml")
(".ascx", "application/xml")
(".asd", "application/octet-stream")
(".asf", "video/x-ms-asf")
(".ashx", "application/xml")
(".asi", "application/octet-stream")
(".asm", "text/plain")
(".asmx", "application/xml")
(".aspx", "application/xml")
(".asr", "video/x-ms-asf")
(".asx", "video/x-ms-asf")
(".atom", "application/atom+xml")
(".au", "audio/basic")
(".avi", "video/x-msvideo")
(".axa", "audio/annodex")
(".axs", "application/olescript")
(".axv", "video/annodex")
(".bas", "text/plain")
(".bcpio", "application/x-bcpio")
(".bin", "application/octet-stream")
(".bmp", "image/bmp")
(".c", "text/plain")
(".cab", "application/octet-stream")
(".caf", "audio/x-caf")
(".calx", "application/vnd.ms-office.calx")
(".cat", "application/vnd.ms-pki.seccat")
(".cc", "text/plain")
(".cd", "text/plain")
(".cdda", "audio/aiff")
(".cdf", "application/x-cdf")
(".cer", "application/x-x509-ca-cert")
(".cfg", "text/plain")
(".chm", "application/octet-stream")
(".class", "application/x-java-applet")
(".clp", "application/x-msclip")
(".cmd", "text/plain")
(".cmx", "image/x-cmx")
(".cnf", "text/plain")
(".cod", "image/cis-cod")
(".config", "application/xml")
(".contact", "text/x-ms-contact")
(".coverage", "application/xml")
(".cpio", "application/x-cpio")
(".cpp", "text/plain")
(".crd", "application/x-mscardfile")
(".crl", "application/pkix-crl")
(".crt", "application/x-x509-ca-cert")
(".cs", "text/plain")
(".csdproj", "text/plain")
(".csh", "application/x-csh")
(".csproj", "text/plain")
(".css", "text/css")
(".csv", "text/csv")
(".cur", "application/octet-stream")
(".cxx", "text/plain")
(".dat", "application/octet-stream")
(".datasource", "application/xml")
(".dbproj", "text/plain")
(".dcr", "application/x-director")
(".def", "text/plain")
(".deploy", "application/octet-stream")
(".der", "application/x-x509-ca-cert")
(".dgml", "application/xml")
(".dib", "image/bmp")
(".dif", "video/x-dv")
(".dir", "application/x-director")
(".disco", "text/xml")
(".divx", "video/divx")
(".dll", "application/x-msdownload")
(".dll.config", "text/xml")
(".dlm", "text/dlm")
(".doc", "application/msword")
(".docm", "application/vnd.ms-word.document.macroEnabled.12")
(".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
(".dot", "application/msword")
(".dotm", "application/vnd.ms-word.template.macroEnabled.12")
(".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template")
(".dsp", "application/octet-stream")
(".dsw", "text/plain")
(".dtd", "text/xml")
(".dtsConfig", "text/xml")
(".dv", "video/x-dv")
(".dvi", "application/x-dvi")
(".dwf", "drawing/x-dwf")
(".dwp", "application/octet-stream")
(".dxr", "application/x-director")
(".eml", "message/rfc822")
(".emz", "application/octet-stream")
(".eot", "application/vnd.ms-fontobject")
(".eps", "application/postscript")
(".etl", "application/etl")
(".etx", "text/x-setext")
(".evy", "application/envoy")
(".exe", "application/octet-stream")
(".exe.config", "text/xml")
(".fdf", "application/vnd.fdf")
(".fif", "application/fractals")
(".filters", "application/xml")
(".fla", "application/octet-stream")
(".flac", "audio/flac")
(".flr", "x-world/x-vrml")
(".flv", "video/x-flv")
(".fsscript", "application/fsharp-script")
(".fsx", "application/fsharp-script")
(".generictest", "application/xml")
(".gif", "image/gif")
(".gpx", "application/gpx+xml")
(".group", "text/x-ms-group")
(".gsm", "audio/x-gsm")
(".gtar", "application/x-gtar")
(".gz", "application/x-gzip")
(".h", "text/plain")
(".hdf", "application/x-hdf")
(".hdml", "text/x-hdml")
(".hhc", "application/x-oleobject")
(".hhk", "application/octet-stream")
(".hhp", "application/octet-stream")
(".hlp", "application/winhlp")
(".hpp", "text/plain")
(".hqx", "application/mac-binhex40")
(".hta", "application/hta")
(".htc", "text/x-component")
(".htm", "text/html")
(".html", "text/html")
(".htt", "text/webviewhtml")
(".hxa", "application/xml")
(".hxc", "application/xml")
(".hxd", "application/octet-stream")
(".hxe", "application/xml")
(".hxf", "application/xml")
(".hxh", "application/octet-stream")
(".hxi", "application/octet-stream")
(".hxk", "application/xml")
(".hxq", "application/octet-stream")
(".hxr", "application/octet-stream")
(".hxs", "application/octet-stream")
(".hxt", "text/html")
(".hxv", "application/xml")
(".hxw", "application/octet-stream")
(".hxx", "text/plain")
(".i", "text/plain")
(".ico", "image/x-icon")
(".ics", "application/octet-stream")
(".idl", "text/plain")
(".ief", "image/ief")
(".iii", "application/x-iphone")
(".inc", "text/plain")
(".inf", "application/octet-stream")
(".ini", "text/plain")
(".inl", "text/plain")
(".ins", "application/x-internet-signup")
(".ipa", "application/x-itunes-ipa")
(".ipg", "application/x-itunes-ipg")
(".ipproj", "text/plain")
(".ipsw", "application/x-itunes-ipsw")
(".iqy", "text/x-ms-iqy")
(".isp", "application/x-internet-signup")
(".ite", "application/x-itunes-ite")
(".itlp", "application/x-itunes-itlp")
(".itms", "application/x-itunes-itms")
(".itpc", "application/x-itunes-itpc")
(".IVF", "video/x-ivf")
(".jar", "application/java-archive")
(".java", "application/octet-stream")
(".jck", "application/liquidmotion")
(".jcz", "application/liquidmotion")
(".jfif", "image/pjpeg")
(".jnlp", "application/x-java-jnlp-file")
(".jpb", "application/octet-stream")
(".jpe", "image/jpeg")
(".jpeg", "image/jpeg")
(".jpg", "image/jpeg")
(".js", "application/javascript")
(".json", "application/json")
(".jsx", "text/jscript")
(".jsxbin", "text/plain")
(".latex", "application/x-latex")
(".library-ms", "application/windows-library+xml")
(".lit", "application/x-ms-reader")
(".loadtest", "application/xml")
(".lpk", "application/octet-stream")
(".lsf", "video/x-la-asf")
(".lst", "text/plain")
(".lsx", "video/x-la-asf")
(".lzh", "application/octet-stream")
(".m13", "application/x-msmediaview")
(".m14", "application/x-msmediaview")
(".m1v", "video/mpeg")
(".m2t", "video/vnd.dlna.mpeg-tts")
(".m2ts", "video/vnd.dlna.mpeg-tts")
(".m2v", "video/mpeg")
(".m3u", "audio/x-mpegurl")