Skip to content

Commit

Permalink
Reimplement bindings (#49)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JordanMartinez authored Aug 1, 2023
1 parent cfd1a28 commit bdc4a82
Show file tree
Hide file tree
Showing 24 changed files with 1,270 additions and 833 deletions.
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

0 comments on commit bdc4a82

Please sign in to comment.