Skip to content
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

[RFC] HTTP Module #23

Closed
Redfire75369 opened this issue Sep 28, 2022 · 4 comments
Closed

[RFC] HTTP Module #23

Redfire75369 opened this issue Sep 28, 2022 · 4 comments
Assignees
Labels
Feature: Module Additional and Improvements to Standard Modules RFC Request for Comment

Comments

@Redfire75369
Copy link
Owner

Redfire75369 commented Sep 28, 2022

I've been working on a HTTP module for a while now. I'm just stuck on a few of the API decisions, specifically on how to use the Response to get the data.
If you have any other feedback on it, that'd be nice too.

Here's the current API in http.d.ts.
<Removed as it is outdated, See below hidden comment>

@Redfire75369 Redfire75369 added Feature: Module Additional and Improvements to Standard Modules RFC Request for Comment labels Sep 28, 2022
@Redfire75369 Redfire75369 self-assigned this Sep 28, 2022
@Redfire75369

This comment was marked as outdated.

@Redfire75369
Copy link
Owner Author

Redfire75369 commented Oct 2, 2022

I have just pushed the first implementation to the feature/http branch.

In some sense, it may be smarter to implement this as fetch first, but a lot of the options on fetch are quite useless for spiderfire, and only make sense on a browser.

As usual, the TypeScript bindings and API can be found here: https://github.com/Redfire75369/spiderfire/blob/feature/http/bindings/modules/typescript/http.d.ts.
The internal implementation in Rust can be found here: https://github.com/Redfire75369/spiderfire/tree/feature/http/modules/src/http.

@Redfire75369
Copy link
Owner Author

Redfire75369 commented Oct 12, 2022

Since the main features are complete now, I'll be merging this into master in a few days. The final-ish bindings are as above. The classes are Headers, Request and Response, and I've completed both redirects and timeouts, which are probably the most important subfeatures.

If anyone has any opinions or queries about the API or thinks I've missed out something important, please bring it up here. I'd like to hear about other's opinions on this.

Here's an example of usage with the API, so you can judge ergonomics:

import http, {Headers, Request} from "http";

const headers = new Headers([["Custom-Keep-Alive", "1000"], ["Custom-Cookies", "spider=fire"]]);
const request = new Request("http://www.example.com", { auth: "spider:fire", headers, signal: AbortSignal.timeout(150) });
const response = await http.request(request);
console.log(await response.text());

Here's a simpler example:

import http from "http";

const response = await http.get("http://www.example.com");
console.log(await response.text());

@Redfire75369
Copy link
Owner Author

The HTTP Client API for HTTP 0.9/1,0/1.1 has now been merged!
Adding HTTP 2.0 support and HTTP Server support will be worked on later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Module Additional and Improvements to Standard Modules RFC Request for Comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant