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

Add HTMLStream #2725

Closed
2 tasks done
Myzel394 opened this issue Feb 13, 2024 · 5 comments
Closed
2 tasks done

Add HTMLStream #2725

Myzel394 opened this issue Feb 13, 2024 · 5 comments
Labels
request Request for new functionality

Comments

@Myzel394
Copy link

What's missing?

Rocket provides easy to use stream macros for

  • binary data ByteStream
  • textual data TextStream
  • server sent events EventStream

however, there is no implementation for HTML based streams. This should definitely be added as HTML can also be used to stream data.

Ideal Solution

Add a HTMLStream that return a stream using ContentType::HTML.

Why can't this be implemented outside of Rocket?

As there are other streams available, even some "exotic" ones, such as EventStream, basic HTML should definitely be supported by rocket.

Are there workarounds usable today?

Probably, I guess you could copy the code from https://api.rocket.rs/v0.5-rc/src/rocket/response/stream/text.rs.html#56 and replace it with HTML. I tried to do that, unfortunately I do not know near enough about Rust to make this to work :(

Alternative Solutions

No response

Additional Context

No response

System Checks

  • I do not believe that this feature can or should be implemented outside of Rocket.
  • I was unable to find a previous request for this feature.
@Myzel394 Myzel394 added the request Request for new functionality label Feb 13, 2024
@SergioBenitez
Copy link
Member

What exactly would you want HtmlStream to do? Does RawHtml(TextStream) not suffice?

@SergioBenitez
Copy link
Member

Closing for the above.

@SergioBenitez SergioBenitez closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
@Myzel394
Copy link
Author

Myzel394 commented Feb 16, 2024

What exactly would you want HtmlStream to do? Does RawHtml(TextStream) not suffice?

Unfortunately, it's too cumbersome to use (in my opinion). I'd expect rocket to contain a macro you can use like this:

HTMLStream! {
    yield "<html>";

    yield "<some><more>";

    yield "</html>";
}

Especially given that there are macros like TextStream and EventStream, basic html should also be supported.

@SergioBenitez
Copy link
Member

I'm suggesting that you can today do:

RawHtml(TextStream! {
    yield "<html>";

    yield "<some><more>";

    yield "</html>";
})

I don't believe this is too cumbersome.

@Myzel394
Copy link
Author

Oh I thought it was much harder to use this, thanks for the code snippet! I'm still new to Rust and things still look magical to me :D

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

No branches or pull requests

2 participants