rwf2 / Rocket

A web framework for Rust.

Home Page:https://rocket.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add HTMLStream

Myzel394 opened this issue · comments

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.

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

Closing for the above.

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.

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.

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