This is a crate which provides macros static_resources_initialize!
and static_response!
to static include files from your Rust project and make them be the HTTP response sources quickly.
```rust
extern crate rocketetagifnonematch;
extern crate rocket; extern crate crc; extern crate mime_guess;
staticresourcesinitialize!( "favicon", "included-static-resources/favicon.ico", "favicon-png", "included-static-resources/favicon-16.png" );
use rocketetagifnonematch::EtagIfNoneMatch;
use rocket::response::Response;
fn favicon(etagifnonematch: EtagIfNoneMatch) -> Response<'static> { staticresponse!(etagifnone_match, "favicon") }
fn faviconpng() -> Response<'static> { staticresponse!("favicon-png") } ```
static_resources_initialize!
is used for including files into your executable binary file. You need to specify each file's ID and its path. For instance, the above example uses favicon to represent the file included-static-resources/favicon.ico and favicon_png to represent the file included-static-resources/favicon.png. An ID cannot be repeating.static_response!
is used for retrieving the file you input through the macro static_resources_initialize!
as a Response instance into which three HTTP headers, Content-Type, Content-Length and Etag, will be automatically added.Refer to tests/favicon.rs
to see the example completely.