Skip to content

feat(p3): return owned request-options on consumption #160

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 1 commit into from
Mar 12, 2025

Conversation

rvolosatovs
Copy link
Contributor

Currently, there's no way to acquire the owned request-options from the request, return them as part of the into-parts along the other moved resources

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@lukewagner
Copy link
Member

Makes sense to me

@dicej dicej merged commit 9caa8b3 into WebAssembly:main Mar 12, 2025
1 check passed
@dicej
Copy link
Collaborator

dicej commented Mar 12, 2025

I've already merged this, but I just had one more thought. What if we did something like this:

record request-parts {
    method: method,
    path_with_query: option<string>,
    scheme: option<scheme>,
    authority: option<string>,
    headers: headers,
    options: option<request-options>,
    body: option<body>,
}

resource request {
    // ...

    into-parts: static func(this: request) -> request-parts;
    from-parts: static func(parts: request-parts) -> request;
}

(and likewise for response/response-parts)

That could make request/response-modifying middleware easier to write -- just call into-parts, tweak the fields you want to, and then call from-parts.

Thoughts?

@rvolosatovs
Copy link
Contributor Author

rvolosatovs commented Mar 12, 2025

I've already merged this, but I just had one more thought. What if we did something like this:

record request-parts {
    method: method,
    path_with_query: option<string>,
    scheme: option<scheme>,
    authority: option<string>,
    headers: headers,
    options: option<request-options>,
    body: option<body>,
}

resource request {
    // ...

    into-parts: static func(this: request) -> request-parts;
    from-parts: static func(parts: request-parts) -> request;
}

(and likewise for response/response-parts)

That could make request/response-modifying middleware easier to write -- just call into-parts, tweak the fields you want to, and then call from-parts.

Thoughts?

Assuming that the cost of moving the field values is negligible, I think that would work great - I was thinking about doing something similar, but opted for the most minimal, incremental change I could come up with.

@dicej
Copy link
Collaborator

dicej commented Mar 13, 2025

If we're concerned about the overhead of lifting and lowering all the fields, we could do something like this:

record request-parts {
    request: request, // Request with no headers, options, or body (i.e. just method, path-with-query, etc.)
    headers: headers,
    options: option<request-options>,
    body: option<body>,
}

resource request {
    // ...

    into-parts: static func(this: request) -> request-parts;
    from-parts: static func(parts: request-parts) -> request;
}

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.

3 participants