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

feat: Add JS resp-set-header and request-set-field bindings #272

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ospencer
Copy link
Contributor

No description provided.

@ospencer ospencer self-assigned this Jun 23, 2022
@flaki
Copy link

flaki commented Jun 23, 2022

Since this is generated, I don't think we care about the return undefined-s making the undefined return value explicit, other than that this looks great, thanks!

Copy link

@flaki flaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question regarding the respSetHeader API, looks good otherwise.

@@ -95,6 +103,8 @@ export class Env {
cacheSet(key: string, value: Uint8Array, ttl: number, ident: number): number;
cacheGet(key: string, ident: number): number;
requestGetField(fieldType: FieldType, key: string, ident: number): number;
requestSetField(fieldType: FieldType, key: string, value: Uint8Array, ident: number): number;
respSetHeader(key: string, value: Uint8Array, ident: number): void;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm any reason value does not simply take a string here? I would think that's more appropriate for header values 🤔

Rust seems to take also set_header(key: &str, val: &str).

@flaki
Copy link

flaki commented Jun 23, 2022

Hmm, I'm running the latest sat version (v0.1.4 with Reactr v0.15.1) and created a fork of the API to test this but for some reason there doesn't seem to be an resp-set-header function exported by the runtime. Super strange. These are all the _exports, note that there's a request-set-field, but no resp-set-header:

{"log_message":"(I) [\"log-msg\",\"fetch-url\",\"graphql-query\",\"cache-set\",\"cache-get\",\"request-get-field\",\"request-set-field\",\"get-static-file\",\"db-exec\",\"get-ffi-result\",\"add-ffi-var\",\"return-result\",\"return-error\",\"canonical_abi_realloc\",\"memory\"]","timestamp":"2022-06-24T00:57:26.413949269+03:00","level":3,"app":{"sat_version":"v0.1.4"},"scope":{"request_id":"a8e52ae8-4152-4be0-905f-82f7907f727f","ident":664900642}}

@ospencer
Copy link
Contributor Author

@flaki Sorry I wasn't more direct about it—suborbital/javy#16 is required to make this work. Running into some build issues over there but once that's resolved that'll be in.

@flaki
Copy link

flaki commented Jun 28, 2022

@flaki Sorry I wasn't more direct about it—suborbital/javy#16 is required to make this work. Running into some build issues over there but once that's resolved that'll be in.

Ah, right, it didn't even occur to me that this could be in Javy but ofc that makes perfect sense.

(also I somehow thought the backend bits of this are already in place because of Rust, but of course we are not using wit-bindgen for Rust so...)

@ospencer
Copy link
Contributor Author

ospencer commented Aug 1, 2022

@flaki Updated to use a string.

@flaki
Copy link

flaki commented Aug 1, 2022

@ospencer if I understand correctly #203 adds both get-field and set-field, alongside set-header but for now we only expose set-header and set-field and at some point we will be able to use getField to fix, among others suborbital / sat # 134

@ospencer
Copy link
Contributor Author

ospencer commented Aug 1, 2022

All of the getField stuff has already been implemented, so I'm not quite sure what you mean! The issue you linked is unrelated, since getField is used for accessing information about the inbound request rather than outbound ones.

@flaki
Copy link

flaki commented Aug 1, 2022

Riiight, sorry, so this is exposing the "middleware" API, a la #213 ?

@ospencer
Copy link
Contributor Author

ospencer commented Aug 1, 2022

Yeah, exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants