Skip to content

Commit bdc4a82

Browse files
Reimplement bindings (#49)
* Add bindings to Incoming/OutgoingMessage * Add bindings to ClientRequest & ServerResponse * Add bindings to Server * Implement bindings to `https` * Remove old bindings * Make tests compile and pass again * Add docs * Update url to 7.0.0 * Expose URL-variant of request/get * Add changelog entry * Update CI actions/node; add purs-tidy
1 parent cfd1a28 commit bdc4a82

24 files changed

+1270
-833
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414

1515
- uses: purescript-contrib/setup-purescript@main
1616
with:
1717
purescript: "unstable"
18+
purs-tidy: "latest"
1819

19-
- uses: actions/setup-node@v2
20+
- uses: actions/setup-node@v3
2021
with:
21-
node-version: "14"
22+
node-version: "lts/*"
2223

2324
- name: Install dependencies
2425
run: |
@@ -33,3 +34,8 @@ jobs:
3334
run: |
3435
bower install
3536
npm run-script test --if-present
37+
38+
- name: Check formatting
39+
run: |
40+
purs-tidy check src test
41+

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Notable changes to this project are documented in this file. The format is based
66

77
Breaking changes:
88
- Update node libraries to latest releases (#48 by @JordanMartinez)
9+
- Reimplement `http`/`https` bindings (#49 by @JordanMartinez)
910

1011
New features:
1112

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"purescript-node-buffer": "^9.0.0",
2525
"purescript-node-net": "^5.1.0",
2626
"purescript-node-streams": "^9.0.0",
27-
"purescript-node-url": "^6.0.0",
27+
"purescript-node-tls": "https://github.com/JordanMartinez/purescript-node-tls.git#^0.3.0",
28+
"purescript-node-url": "^7.0.0",
2829
"purescript-nullable": "^6.0.0",
2930
"purescript-options": "^7.0.0",
3031
"purescript-prelude": "^6.0.0",

src/Node/HTTP.js

Lines changed: 15 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,20 @@
1-
import http from "http";
1+
import http from "node:http";
22

3-
export function createServer(handleRequest) {
4-
return function () {
5-
return http.createServer(function (req, res) {
6-
handleRequest(req)(res)();
7-
});
8-
};
9-
}
3+
export const createServer = () => http.createServer();
4+
export const createServerOptsImpl = (opts) => http.createServer(opts);
105

11-
export function listenImpl(server) {
12-
return function (port) {
13-
return function (hostname) {
14-
return function (backlog) {
15-
return function (done) {
16-
return function () {
17-
if (backlog !== null) {
18-
server.listen(port, hostname, backlog, done);
19-
} else {
20-
server.listen(port, hostname, done);
21-
}
22-
};
23-
};
24-
};
25-
};
26-
};
27-
}
6+
export const maxHeaderSize = http.maxHeaderSize;
287

29-
export function closeImpl(server) {
30-
return function (done) {
31-
return function () {
32-
server.close(done);
33-
};
34-
};
35-
}
8+
export const requestStrImpl = (url) => http.request(url);
9+
export const requestStrOptsImpl = (url, opts) => http.request(url, opts);
10+
export const requestUrlImpl = (url) => http.request(url);
11+
export const requestUrlOptsImpl = (url, opts) => http.request(url, opts);
12+
export const requestOptsImpl = (opts) => http.request(opts);
3613

37-
export function listenSocket(server) {
38-
return function (path) {
39-
return function (done) {
40-
return function () {
41-
server.listen(path, done);
42-
};
43-
};
44-
};
45-
}
14+
export const getStrImpl = (url) => http.get(url);
15+
export const getStrOptsImpl = (url, opts) => http.get(url, opts);
16+
export const getUrlImpl = (url) => http.get(url);
17+
export const getUrlOptsImpl = (url, opts) => http.get(url, opts);
18+
export const getOptsImpl = (opts) => http.get(opts);
4619

47-
export function onConnect(server) {
48-
return function (cb) {
49-
return function () {
50-
server.on("connect", function (req, socket, buffer) {
51-
return cb(req)(socket)(buffer)();
52-
});
53-
};
54-
};
55-
}
56-
57-
export function onUpgrade(server) {
58-
return function (cb) {
59-
return function () {
60-
server.on("upgrade", function (req, socket, buffer) {
61-
return cb(req)(socket)(buffer)();
62-
});
63-
};
64-
};
65-
}
66-
67-
export function setHeader(res) {
68-
return function (key) {
69-
return function (value) {
70-
return function () {
71-
res.setHeader(key, value);
72-
};
73-
};
74-
};
75-
}
76-
77-
export function setHeaders(res) {
78-
return function (key) {
79-
return function (values) {
80-
return function () {
81-
res.setHeader(key, values);
82-
};
83-
};
84-
};
85-
}
86-
87-
export function setStatusCode(res) {
88-
return function (code) {
89-
return function () {
90-
res.statusCode = code;
91-
};
92-
};
93-
}
94-
95-
export function setStatusMessage(res) {
96-
return function (message) {
97-
return function () {
98-
res.statusMessage = message;
99-
};
100-
};
101-
}
20+
export const setMaxIdleHttpParsersImpl = (i) => http.setMaxIdleHTTPParsers(i);

0 commit comments

Comments
 (0)