Skip to content

Commit de4883d

Browse files
committed
Created a record type for the 'headers' object
1 parent 28c1b85 commit de4883d

File tree

1 file changed

+73
-15
lines changed

1 file changed

+73
-15
lines changed

src/Http.re

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
type http = [ | `Http];
22

3+
module Headers = {
4+
type t = pri {
5+
accept: option(string),
6+
[@bs.as "accept-language"] acceptLanguage: option(string),
7+
[@bs.as "accept-patch"] acceptPatch: option(string),
8+
[@bs.as "accept-ranges"] acceptRanges: option(string),
9+
[@bs.as "access-control-allow-credentials"] accessControlAllowCredentials: option(string),
10+
[@bs.as "access-control-allow-headers"] accessControlAllowHeaders: option(string),
11+
[@bs.as "access-control-allow-methods"] accessControlAllowMethods: (string),
12+
[@bs.as "access-control-allow-origin"] accessControlAllowOrigin: option(string),
13+
[@bs.as "access-control-expose-headers"] accessControlExposeHeaders: option(string),
14+
[@bs.as "access-control-max-age"] accessControlMaxAge: option(string),
15+
age: option(string),
16+
allow: option(string),
17+
[@bs.as "alt-svc"] altSvc: option(string),
18+
authorization: option(string),
19+
[@bs.as "cache-control"] cacheControl: option(string),
20+
connection: option(string),
21+
[@bs.as "content-disposition"] contentDisposition: option(string),
22+
[@bs.as "content-encoding"] contentEncoding: option(string),
23+
[@bs.as "content-language"] contentLanguage: option(string),
24+
[@bs.as "content-length"] contentLenth: option(string),
25+
[@bs.as "content-location"] contentLocation: option(string),
26+
[@bs.as "content-range"] contentRange: option(string),
27+
[@bs.as "content-type"] contentType: option(string),
28+
cookie: option(string),
29+
date: option(string),
30+
expect: option(string),
31+
expires: option(string),
32+
forwarded: option(string),
33+
from: option(string),
34+
host: option(string),
35+
[@bs.as "if-match"] ifMatch: option(string),
36+
[@bs.as "if-modified-since"] ifModifiedSince: option(string),
37+
[@bs.as "if-none-match"] ifNoneMatch: option(string),
38+
[@bs.as "if-unmodified-since"] ifUnmodifiedSince: option(string),
39+
[@bs.as "last-modified"] lastModified: option(string),
40+
location: option(string),
41+
pragma: option(string),
42+
[@bs.as "proxy-authenticate"] proxyAuthenticate: option(string),
43+
[@bs.as "proxy-authorization"] proxyAuthorization: option(string),
44+
[@bs.as "public-key-pins"] publicKeyPins: option(string),
45+
range: option(string),
46+
referer: option(string),
47+
[@bs.as "retry-after"] retryAfter: option(string),
48+
[@bs.as "set-cookie"] setCookie: option(array(string)),
49+
[@bs.as "strict-transport-security"] strictTransportPolicy: option(string),
50+
tk: option(string),
51+
trailer: option(string),
52+
[@bs.as "transfer-encoding"] transferEncoding: option(string),
53+
upgrade: option(string),
54+
[@bs.as "user-agent"] userAgent: option(string),
55+
vary: option(string),
56+
via: option(string),
57+
warning: option(string),
58+
[@bs.as "www-authenticate"] wwwAuthenticate: option(string),
59+
};
60+
};
61+
362
module IncomingMessage = {
463
type kind = [ Stream.readable | `IncomingMessage];
564
type subtype('w, 'r, 'a) = Stream.subtype('w, 'r, [> kind] as 'a);
@@ -69,7 +128,7 @@ module IncomingMessage = {
69128
[@bs.get] external url: subtype('w, 'r, 'a) => string = "url";
70129
[@bs.get] external port: subtype('w, 'r, 'a) => int = "port";
71130
[@bs.get]
72-
external headers: subtype('w, 'r, 'a) => Js.Dict.t(string) = "headers";
131+
external headers: subtype('w, 'r, 'a) => Headers.t = "headers";
73132
[@bs.get]
74133
external rawHeaders: subtype('w, 'r, 'a) => array(string) = "rawHeaders";
75134
[@bs.get]
@@ -109,15 +168,14 @@ module ClientRequest = {
109168
type subtype('w, 'r, 'a) = Stream.subtype('w, 'r, [> kind] as 'a);
110169
type supertype('w, 'r, 'a) = Stream.subtype('w, 'r, [< kind] as 'a);
111170
type t = subtype(Buffer.t, Buffer.t, [ kind]);
112-
type information('a) = {
113-
.
114-
"httpVersion": string,
115-
"httpVersionMajor": int,
116-
"httpVersionMinor": int,
117-
"statusCode": int,
118-
"statusMessage": string,
119-
"headers": Js.t({..} as 'a),
120-
"rawHeaders": array(string),
171+
type information = {
172+
httpVersion: string,
173+
httpVersionMajor: int,
174+
httpVersionMinor: int,
175+
statusCode: int,
176+
statusMessage: string,
177+
headers: Headers.t,
178+
rawHeaders: array(string),
121179
};
122180
module Events = {
123181
include Stream.Duplex.Events;
@@ -158,7 +216,7 @@ module ClientRequest = {
158216
(
159217
subtype('w, 'r, 'a),
160218
[@bs.as "information"] _,
161-
[@bs.uncurry] (information('b) => unit)
219+
[@bs.uncurry] (information => unit)
162220
) =>
163221
subtype('w, 'r, 'a) =
164222
"on";
@@ -239,7 +297,7 @@ module ClientRequest = {
239297
(
240298
subtype('w, 'r, 'a),
241299
[@bs.as "information"] _,
242-
[@bs.uncurry] (information('b) => unit)
300+
[@bs.uncurry] (information => unit)
243301
) =>
244302
subtype('w, 'r, 'a) =
245303
"off";
@@ -320,7 +378,7 @@ module ClientRequest = {
320378
(
321379
subtype('w, 'r, 'a),
322380
[@bs.as "information"] _,
323-
[@bs.uncurry] (information('b) => unit)
381+
[@bs.uncurry] (information => unit)
324382
) =>
325383
subtype('w, 'r, 'a) =
326384
"once";
@@ -521,7 +579,7 @@ module ServerResponse = {
521579
external getHeaderNames: subtype('w, 'r, 'a) => array(string) =
522580
"getHeaderNames";
523581
[@bs.send]
524-
external getHeaders: subtype('w, 'r, 'a) => Js.t({..}) = "getHeaders";
582+
external getHeaders: subtype('w, 'r, 'a) => Headers.t = "getHeaders";
525583
[@bs.send]
526584
external hasHeader: (subtype('w, 'r, 'a), string) => bool = "hasHeader";
527585
[@bs.get]
@@ -852,7 +910,7 @@ external requestOptions:
852910
~createConnection: unit => Net.TcpSocket.t=?,
853911
~defaultPort: int=?,
854912
~family: int=?,
855-
~headers: Js.t({..})=?,
913+
~headers: Headers.t=?,
856914
~host: string=?,
857915
~hostName: string=?,
858916
~localAddress: string=?,

0 commit comments

Comments
 (0)