Skip to content

Reimplement bindings #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2db7ca1
Add bindings to Incoming/OutgoingMessage
JordanMartinez Jul 29, 2023
4c8c880
add comments for which FFI is allowed
JordanMartinez Jul 29, 2023
3fbea8a
Use ty var to prevent incorrect usage
JordanMartinez Jul 29, 2023
aaa9180
Update exports
JordanMartinez Jul 29, 2023
f9674ac
Add bindings to ClientRequest & ServerResponse
JordanMartinez Jul 29, 2023
7da25fc
Add bindings to Server
JordanMartinez Jul 29, 2023
b94570c
Move current HTTP bindings to `old`
JordanMartinez Jul 29, 2023
b4c745b
Finish all but Agent for node:http bindings
JordanMartinez Jul 29, 2023
0d08fe3
Move Secure into old
JordanMartinez Jul 29, 2023
2230214
Fix FFI name
JordanMartinez Jul 29, 2023
c57994f
Implement bindings to `https`
JordanMartinez Jul 29, 2023
dd39a92
Remove old bindings
JordanMartinez Jul 29, 2023
b03db19
Fix FFI & export list for ClientRequest
JordanMartinez Jul 29, 2023
c1b6165
Update fn to match returned type
JordanMartinez Jul 29, 2023
46be9dd
Make things not effectful
JordanMartinez Jul 29, 2023
e51281e
Delineate between headers and cookies
JordanMartinez Jul 29, 2023
055a659
Add opts-only-arg version of request/get
JordanMartinez Jul 31, 2023
e2394d5
Add FFI: implicit set/get of status code/msg
JordanMartinez Jul 31, 2023
f15caa7
Drop duplicate API for https server
JordanMartinez Jul 31, 2023
9cc718b
Unify `http` and `https` server API
JordanMartinez Jul 31, 2023
2e57d01
Rename module to `Node.HTTPS`
JordanMartinez Jul 31, 2023
1afa9a8
Make tests compile and pass again
JordanMartinez Jul 31, 2023
bf0626c
Add docs
JordanMartinez Jul 31, 2023
e49ea49
Update url to 7.0.0
JordanMartinez Aug 1, 2023
35e7fca
Expose URL-variant of request/get
JordanMartinez Aug 1, 2023
13c4995
Update export lists: exclude FFI
JordanMartinez Aug 1, 2023
4dd5fc3
Add changelog entry
JordanMartinez Aug 1, 2023
08604f6
Update CI actions/node; add purs-tidy
JordanMartinez Aug 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "latest"

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: "14"
node-version: "lts/*"

- name: Install dependencies
run: |
Expand All @@ -33,3 +34,8 @@ jobs:
run: |
bower install
npm run-script test --if-present

- name: Check formatting
run: |
purs-tidy check src test

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Notable changes to this project are documented in this file. The format is based

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

New features:

Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"purescript-node-buffer": "^9.0.0",
"purescript-node-net": "^5.1.0",
"purescript-node-streams": "^9.0.0",
"purescript-node-url": "^6.0.0",
"purescript-node-tls": "https://github.com/JordanMartinez/purescript-node-tls.git#^0.3.0",
"purescript-node-url": "^7.0.0",
"purescript-nullable": "^6.0.0",
"purescript-options": "^7.0.0",
"purescript-prelude": "^6.0.0",
Expand Down
111 changes: 15 additions & 96 deletions src/Node/HTTP.js
Original file line number Diff line number Diff line change
@@ -1,101 +1,20 @@
import http from "http";
import http from "node:http";

export function createServer(handleRequest) {
return function () {
return http.createServer(function (req, res) {
handleRequest(req)(res)();
});
};
}
export const createServer = () => http.createServer();
export const createServerOptsImpl = (opts) => http.createServer(opts);

export function listenImpl(server) {
return function (port) {
return function (hostname) {
return function (backlog) {
return function (done) {
return function () {
if (backlog !== null) {
server.listen(port, hostname, backlog, done);
} else {
server.listen(port, hostname, done);
}
};
};
};
};
};
}
export const maxHeaderSize = http.maxHeaderSize;

export function closeImpl(server) {
return function (done) {
return function () {
server.close(done);
};
};
}
export const requestStrImpl = (url) => http.request(url);
export const requestStrOptsImpl = (url, opts) => http.request(url, opts);
export const requestUrlImpl = (url) => http.request(url);
export const requestUrlOptsImpl = (url, opts) => http.request(url, opts);
export const requestOptsImpl = (opts) => http.request(opts);

export function listenSocket(server) {
return function (path) {
return function (done) {
return function () {
server.listen(path, done);
};
};
};
}
export const getStrImpl = (url) => http.get(url);
export const getStrOptsImpl = (url, opts) => http.get(url, opts);
export const getUrlImpl = (url) => http.get(url);
export const getUrlOptsImpl = (url, opts) => http.get(url, opts);
export const getOptsImpl = (opts) => http.get(opts);

export function onConnect(server) {
return function (cb) {
return function () {
server.on("connect", function (req, socket, buffer) {
return cb(req)(socket)(buffer)();
});
};
};
}

export function onUpgrade(server) {
return function (cb) {
return function () {
server.on("upgrade", function (req, socket, buffer) {
return cb(req)(socket)(buffer)();
});
};
};
}

export function setHeader(res) {
return function (key) {
return function (value) {
return function () {
res.setHeader(key, value);
};
};
};
}

export function setHeaders(res) {
return function (key) {
return function (values) {
return function () {
res.setHeader(key, values);
};
};
};
}

export function setStatusCode(res) {
return function (code) {
return function () {
res.statusCode = code;
};
};
}

export function setStatusMessage(res) {
return function (message) {
return function () {
res.statusMessage = message;
};
};
}
export const setMaxIdleHttpParsersImpl = (i) => http.setMaxIdleHTTPParsers(i);
Loading