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

rust: Add some convenience methods/impls to http types #1977

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

lann
Copy link
Collaborator

@lann lann commented Oct 27, 2023

This whole PR is summed up by this http-rust-outbound-http example diff.

Draft until #1975 merges.

And update rust outbound http examples to use "simple" types.

  • Add Request::{get,post} associated functions which cover the most common request types.
  • impl TryIntoOutgoingRequest for RequestBuilder to skip a boilerplate .build()
  • Add Response::into_builder to ease returning an updated response.
  • impl Debug for Response to fix examples

@lann lann force-pushed the enhance-http-types branch from 94d95a7 to c8e0961 Compare October 27, 2023 17:52
@lann lann mentioned this pull request Oct 27, 2023
9 tasks
Copy link
Member

@radu-matei radu-matei left a comment

Choose a reason for hiding this comment

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

I really appreciate the convenience these add.

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

Nice!

@lann lann force-pushed the enhance-http-types branch from c8e0961 to 70f50c9 Compare October 30, 2023 13:19
@lann lann marked this pull request as ready for review October 30, 2023 13:19
@lann lann changed the base branch from http-fix to main October 30, 2023 13:20
And update rust outbound http examples to use "simple" types.

- Add `Request::{get,post}` associated functions which cover the most
  common request types.
- `impl TryIntoOutgoingRequest for RequestBuilder` to skip a boilerplate
  `.build()`
- Add `Response::into_builder` to ease returning an updated response.
- `impl Debug for Response` to fix examples

Signed-off-by: Lann Martin <lann.martin@fermyon.com>
@lann lann force-pushed the enhance-http-types branch from 70f50c9 to 3821266 Compare October 30, 2023 17:11
@lann lann merged commit 561b3e1 into fermyon:main Oct 31, 2023
9 checks passed
@@ -528,6 +530,16 @@ impl TryIntoOutgoingRequest for Request {
}
}

impl TryIntoOutgoingRequest for RequestBuilder {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably do the same for IntoResponse for ResponseBuilder.

f.debug_struct("Response")
.field("status", &self.status)
.field("headers", &self.headers)
.field("body.len()", &self.body.len())
Copy link
Collaborator

@rylev rylev Oct 31, 2023

Choose a reason for hiding this comment

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

I wonder if this would be more useful:

.field("body.", String::from_utf8_lossy(&self.body[..self.body.len().min(50)]))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably!

@lann lann deleted the enhance-http-types branch October 31, 2023 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants