├── examples
├── todo
│ ├── db
│ │ └── DB_LIVES_HERE
│ ├── migrations
│ │ ├── .gitkeep
│ │ └── 20160720150332_create_tasks_table
│ │ │ ├── down.sql
│ │ │ └── up.sql
│ ├── Rocket.toml
│ ├── static
│ │ ├── images
│ │ │ └── favicon.png
│ │ └── css
│ │ │ └── style.css
│ ├── bootstrap.sh
│ ├── README.md
│ ├── Cargo.toml
│ └── src
│ │ └── task.rs
├── fairings
│ ├── Rocket.toml
│ ├── Cargo.toml
│ └── src
│ │ └── tests.rs
├── manual_routes
│ ├── Rocket.toml
│ ├── Cargo.toml
│ └── src
│ │ └── tests.rs
├── static_files
│ ├── static
│ │ ├── hidden
│ │ │ └── hi.txt
│ │ ├── rocket-icon.jpg
│ │ └── index.html
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── session
│ ├── Rocket.toml
│ ├── Cargo.toml
│ └── templates
│ │ ├── index.html.hbs
│ │ └── login.html.hbs
├── handlebars_templates
│ ├── templates
│ │ ├── footer.hbs
│ │ ├── nav.hbs
│ │ ├── layout.hbs
│ │ ├── about.hbs
│ │ ├── error
│ │ │ └── 404.hbs
│ │ └── index.hbs
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── config
│ ├── src
│ │ └── main.rs
│ ├── Cargo.toml
│ ├── tests
│ │ ├── staging.rs
│ │ ├── development.rs
│ │ └── production.rs
│ └── Rocket.toml
├── errors
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── state
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── stream
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── ranking
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── redirect
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── testing
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── hello_world
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── raw_upload
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── hello_person
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── query_params
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── request_guard
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── tls
│ ├── Cargo.toml
│ ├── src
│ │ ├── main.rs
│ │ └── tests.rs
│ ├── Rocket.toml
│ └── private
│ │ ├── gen_cert.sh
│ │ ├── cert.pem
│ │ └── ca_cert.pem
├── form_validation
│ ├── Cargo.toml
│ ├── static
│ │ └── index.html
│ └── src
│ │ ├── files.rs
│ │ └── main.rs
├── form_kitchen_sink
│ ├── Cargo.toml
│ ├── static
│ │ └── index.html
│ └── src
│ │ └── main.rs
├── optional_redirect
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── request_local_state
│ ├── Cargo.toml
│ └── src
│ │ ├── tests.rs
│ │ └── main.rs
├── pastebin
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── paste_id.rs
├── hello_2018
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── raw_sqlite
│ ├── Cargo.toml
│ └── src
│ │ ├── tests.rs
│ │ └── main.rs
├── managed_queue
│ ├── Cargo.toml
│ └── src
│ │ ├── tests.rs
│ │ └── main.rs
├── tera_templates
│ ├── templates
│ │ ├── base.html.tera
│ │ ├── error
│ │ │ └── 404.html.tera
│ │ └── index.html.tera
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
├── content_types
│ ├── Cargo.toml
│ └── src
│ │ └── tests.rs
├── cookies
│ ├── Cargo.toml
│ ├── templates
│ │ └── index.html.hbs
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
├── uuid
│ ├── Cargo.toml
│ └── src
│ │ ├── tests.rs
│ │ └── main.rs
├── msgpack
│ ├── Cargo.toml
│ └── src
│ │ ├── main.rs
│ │ └── tests.rs
└── json
│ ├── Cargo.toml
│ └── src
│ └── main.rs
├── contrib
├── lib
│ ├── tests
│ │ ├── static
│ │ │ ├── .hidden
│ │ │ ├── other
│ │ │ │ └── hello.txt
│ │ │ ├── inner
│ │ │ │ ├── .hideme
│ │ │ │ ├── index.html
│ │ │ │ └── goodbye
│ │ │ └── index.html
│ │ ├── templates
│ │ │ ├── hbs
│ │ │ │ ├── reload.txt.hbs
│ │ │ │ ├── common
│ │ │ │ │ ├── footer.html.hbs
│ │ │ │ │ └── header.html.hbs
│ │ │ │ └── test.html.hbs
│ │ │ └── tera
│ │ │ │ ├── txt_test.txt.tera
│ │ │ │ ├── html_test.html.tera
│ │ │ │ └── base.txt.tera
│ │ └── databases.rs
│ └── src
│ │ └── templates
│ │ ├── handlebars_templates.rs
│ │ └── tera_templates.rs
└── codegen
│ ├── Cargo.toml
│ └── src
│ └── lib.rs
├── logo.png
├── core
├── codegen
│ ├── src
│ │ ├── attribute
│ │ │ └── mod.rs
│ │ ├── derive
│ │ │ ├── mod.rs
│ │ │ └── from_form_value.rs
│ │ ├── syn_ext.rs
│ │ ├── bang
│ │ │ └── mod.rs
│ │ └── proc_macro_ext.rs
│ ├── tests
│ │ ├── route-params.rs
│ │ ├── ui-fail
│ │ │ ├── routes.rs
│ │ │ ├── catchers.rs
│ │ │ ├── from_form_type_errors.rs
│ │ │ ├── routes.stderr
│ │ │ ├── catchers.stderr
│ │ │ ├── catch_type_errors.rs
│ │ │ ├── from_form_type_errors.stderr
│ │ │ ├── responder-types.rs
│ │ │ ├── typed-uris-invalid-syntax.rs
│ │ │ ├── route-type-errors.rs
│ │ │ ├── route-warnings.rs
│ │ │ ├── from_form_value.rs
│ │ │ ├── uri_display.rs
│ │ │ ├── uri_display_type_errors.rs
│ │ │ ├── catch.rs
│ │ │ ├── catch_type_errors.stderr
│ │ │ ├── route-warnings.stderr
│ │ │ ├── update-references.sh
│ │ │ ├── typed-uris-invalid-syntax.stderr
│ │ │ └── catch.stderr
│ │ ├── expansion.rs
│ │ ├── route-data.rs
│ │ ├── route-ranking.rs
│ │ └── from_form_value.rs
│ └── Cargo.toml
├── http
│ ├── src
│ │ ├── tls.rs
│ │ ├── parse
│ │ │ ├── mod.rs
│ │ │ ├── checkers.rs
│ │ │ └── uri
│ │ │ │ └── mod.rs
│ │ └── lib.rs
│ └── Cargo.toml
└── lib
│ ├── tests
│ ├── mount_point.rs
│ ├── redirect_from_catcher-issue-113.rs
│ ├── responder_lifetime-issue-345.rs
│ ├── absolute-uris-okay-issue-443.rs
│ ├── route_guard.rs
│ ├── form_method-issue-45.rs
│ ├── form_value_decoding-issue-82.rs
│ ├── local_request_private_cookie-issue-368.rs
│ ├── segments-issues-41-86.rs
│ ├── uri-percent-encoding-issue-808.rs
│ ├── nested-fairing-attaches.rs
│ ├── flash-lazy-removes-issue-466.rs
│ ├── limits.rs
│ ├── strict_and_lenient_forms.rs
│ ├── precise-content-type-matching.rs
│ └── head_handling.rs
│ ├── src
│ ├── data
│ │ ├── mod.rs
│ │ └── data_stream.rs
│ ├── request
│ │ ├── form
│ │ │ └── mod.rs
│ │ ├── mod.rs
│ │ └── tests.rs
│ ├── ext.rs
│ ├── codegen.rs
│ └── response
│ │ └── mod.rs
│ ├── Cargo.toml
│ ├── benches
│ ├── format-routing.rs
│ └── ranked-routing.rs
│ └── build.rs
├── .travis.yml
├── .gitignore
├── scripts
├── mk-docs.sh
├── bump_version.sh
└── publish.sh
├── LICENSE-MIT
├── Cargo.toml
├── site
├── guide
│ ├── 1-quickstart.md
│ ├── 11-conclusion.md
│ └── index.md
├── README.md
└── news
│ ├── 2018-10-31-version-0.4-rc.md
│ └── 2018-11-30-version-0.4-rc-2.md
└── .github
└── ISSUE_TEMPLATE.md
/examples/todo/db/DB_LIVES_HERE:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/todo/migrations/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/contrib/lib/tests/static/.hidden:
--------------------------------------------------------------------------------
1 | Peek-a-boo.
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/static/other/hello.txt:
--------------------------------------------------------------------------------
1 | Hi!
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/static/inner/.hideme:
--------------------------------------------------------------------------------
1 | Oh no!
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/hbs/reload.txt.hbs:
--------------------------------------------------------------------------------
1 | initial
--------------------------------------------------------------------------------
/contrib/lib/tests/static/inner/index.html:
--------------------------------------------------------------------------------
1 | Inner index.
2 |
--------------------------------------------------------------------------------
/examples/fairings/Rocket.toml:
--------------------------------------------------------------------------------
1 | [global]
2 | token = 123
3 |
--------------------------------------------------------------------------------
/contrib/lib/tests/static/inner/goodbye:
--------------------------------------------------------------------------------
1 | Thanks for coming!
2 |
--------------------------------------------------------------------------------
/examples/manual_routes/Rocket.toml:
--------------------------------------------------------------------------------
1 | [global]
2 | port = 8000
3 |
--------------------------------------------------------------------------------
/examples/static_files/static/hidden/hi.txt:
--------------------------------------------------------------------------------
1 | You found me! :o
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/hbs/common/footer.html.hbs:
--------------------------------------------------------------------------------
1 | Done.
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/static/index.html:
--------------------------------------------------------------------------------
1 | Just a file here: index.html.
2 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/hbs/common/header.html.hbs:
--------------------------------------------------------------------------------
1 | Hello {{ title }}!
2 |
--------------------------------------------------------------------------------
/examples/todo/migrations/20160720150332_create_tasks_table/down.sql:
--------------------------------------------------------------------------------
1 | DROP TABLE tasks
2 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stackblitz/template-rust-rocket/master/logo.png
--------------------------------------------------------------------------------
/core/codegen/src/attribute/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod catch;
2 | pub mod route;
3 | pub mod segments;
4 |
--------------------------------------------------------------------------------
/examples/session/Rocket.toml:
--------------------------------------------------------------------------------
1 | [global]
2 | secret_key = "itlYmFR2vYKrOmFhupMIn/hyB6lYCCTXz4yaQX89XVg="
3 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/footer.hbs:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/nav.hbs:
--------------------------------------------------------------------------------
1 | Hello | About
2 |
--------------------------------------------------------------------------------
/core/codegen/src/derive/mod.rs:
--------------------------------------------------------------------------------
1 | pub mod from_form;
2 | pub mod from_form_value;
3 | pub mod responder;
4 | pub mod uri_display;
5 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/hbs/test.html.hbs:
--------------------------------------------------------------------------------
1 | {{> hbs/common/header }}
2 | {{ content }}
3 | {{> hbs/common/footer }}
4 |
--------------------------------------------------------------------------------
/examples/todo/Rocket.toml:
--------------------------------------------------------------------------------
1 | [global]
2 | template_dir = "static"
3 |
4 | [global.databases.sqlite_database]
5 | url = "db/db.sqlite"
6 |
--------------------------------------------------------------------------------
/examples/todo/static/images/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stackblitz/template-rust-rocket/master/examples/todo/static/images/favicon.png
--------------------------------------------------------------------------------
/examples/static_files/static/rocket-icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stackblitz/template-rust-rocket/master/examples/static_files/static/rocket-icon.jpg
--------------------------------------------------------------------------------
/examples/config/src/main.rs:
--------------------------------------------------------------------------------
1 | extern crate rocket;
2 |
3 | // This example's illustration is the Rocket.toml file.
4 | fn main() {
5 | rocket::ignite().launch();
6 | }
7 |
--------------------------------------------------------------------------------
/examples/todo/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env bash
2 |
3 | SCRIPT_PATH=$(cd "$(dirname "$0")" ; pwd -P)
4 | DATABASE_URL="${SCRIPT_PATH}/db/db.sqlite"
5 |
6 | rm -f "${DATABASE_URL}"
7 |
--------------------------------------------------------------------------------
/examples/config/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "config"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/errors/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "errors"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/state/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "state"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/static_files/static/index.html:
--------------------------------------------------------------------------------
1 |
Hello, world!
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/examples/stream/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "stream"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/fairings/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "fairings"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/ranking/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "ranking"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/redirect/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "redirect"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/testing/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "testing"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/tera/txt_test.txt.tera:
--------------------------------------------------------------------------------
1 | {% extends "tera/base" %}
2 | {% block title %}{{ title }}{% endblock title %}
3 | {% block content %}
4 | {{ content }}
5 | {% endblock content %}
6 |
--------------------------------------------------------------------------------
/examples/hello_world/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "hello_world"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/raw_upload/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "raw_upload"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/tera/html_test.html.tera:
--------------------------------------------------------------------------------
1 | {% extends "tera/base" %}
2 | {% block title %}{{ title }}{% endblock title %}
3 | {% block content %}
4 | {{ content }}
5 | {% endblock content %}
6 |
--------------------------------------------------------------------------------
/examples/hello_person/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "hello_person"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/manual_routes/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "manual_routes"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/query_params/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "query_params"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/request_guard/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "request_guard"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/tls/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "tls"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib", features = ["tls"] }
9 |
--------------------------------------------------------------------------------
/examples/form_validation/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "form_validation"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/form_kitchen_sink/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "form_kitchen_sink"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/optional_redirect/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "optional_redirect"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/request_local_state/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "request_local_state"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
--------------------------------------------------------------------------------
/examples/pastebin/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "pastebin"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | rand = "0.6"
10 |
--------------------------------------------------------------------------------
/core/http/src/tls.rs:
--------------------------------------------------------------------------------
1 | extern crate rustls;
2 | extern crate hyper_sync_rustls;
3 |
4 | pub use self::hyper_sync_rustls::{util, WrappedStream, ServerSession, TlsServer};
5 | pub use self::rustls::{Certificate, PrivateKey};
6 |
--------------------------------------------------------------------------------
/examples/hello_2018/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "hello_2018"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 | edition = "2018"
7 |
8 | [dependencies]
9 | rocket = { path = "../../core/lib" }
10 |
--------------------------------------------------------------------------------
/examples/raw_sqlite/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "raw_sqlite"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | rusqlite = "0.14"
10 |
--------------------------------------------------------------------------------
/examples/managed_queue/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "managed_queue"
3 | version = "0.0.0"
4 | workspace = "../.."
5 | publish = false
6 |
7 | [dependencies]
8 | crossbeam = "0.5"
9 | rocket = { path = "../../core/lib" }
10 |
--------------------------------------------------------------------------------
/contrib/lib/tests/templates/tera/base.txt.tera:
--------------------------------------------------------------------------------
1 | {% block head %}
2 | h_start
3 | title: {% block title %}{% endblock title %}
4 | h_end
5 | {% endblock head %}
6 | {% block content %}{% endblock content %}
7 | {% block footer %}foot{% endblock footer %}
8 |
--------------------------------------------------------------------------------
/examples/static_files/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "static_files"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | rocket_contrib = { path = "../../contrib/lib" }
10 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/layout.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Rocket Example - {{ title }}
5 |
6 |
7 | {{> nav}}
8 | {{~> page}}
9 | {{> footer}}
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/tera_templates/templates/base.html.tera:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Tera Demo
6 |
7 |
8 | {% block content %}{% endblock content %}
9 |
10 |
11 |
--------------------------------------------------------------------------------
/core/http/src/parse/mod.rs:
--------------------------------------------------------------------------------
1 | mod media_type;
2 | mod accept;
3 | mod checkers;
4 | mod indexed;
5 |
6 | pub use self::media_type::*;
7 | pub use self::accept::*;
8 |
9 | pub mod uri;
10 |
11 | // Exposed for codegen.
12 | #[doc(hidden)] pub use self::indexed::*;
13 |
--------------------------------------------------------------------------------
/examples/config/tests/staging.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | mod common;
6 |
7 | #[test]
8 | fn test_staging_config() {
9 | common::test_config(rocket::config::Environment::Staging);
10 | }
11 |
--------------------------------------------------------------------------------
/examples/config/tests/development.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | mod common;
6 |
7 | #[test]
8 | fn test_development_config() {
9 | common::test_config(rocket::config::Environment::Development);
10 | }
11 |
--------------------------------------------------------------------------------
/examples/config/tests/production.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | mod common;
6 |
7 | #[test]
8 | fn test_production_config() {
9 | common::test_config(rocket::config::Environment::Production);
10 | }
11 |
--------------------------------------------------------------------------------
/examples/content_types/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "content_types"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_json = "1.0"
11 | serde_derive = "1.0"
12 |
--------------------------------------------------------------------------------
/core/lib/tests/mount_point.rs:
--------------------------------------------------------------------------------
1 | extern crate rocket;
2 |
3 | #[test]
4 | #[should_panic]
5 | fn bad_dynamic_mount() {
6 | rocket::ignite().mount("", vec![]);
7 | }
8 |
9 | #[test]
10 | fn good_static_mount() {
11 | rocket::ignite().mount("/abcdefghijkl_mno", vec![]);
12 | }
13 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/about.hbs:
--------------------------------------------------------------------------------
1 | {{#*inline "page"}}
2 |
3 |
4 | Here's another page!
5 |
6 | {{#each items}}
7 | - {{ this }}
8 | {{/each}}
9 |
10 |
11 |
12 | {{/inline}}
13 | {{~> (parent)~}}
14 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/error/404.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 404
6 |
7 |
8 | 404: Hey! There's nothing here.
9 | The page at {{ path }} does not exist!
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/raw_sqlite/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::rocket;
2 | use rocket::local::Client;
3 |
4 | #[test]
5 | fn hello() {
6 | let client = Client::new(rocket()).unwrap();
7 | let mut response = client.get("/").dispatch();
8 | assert_eq!(response.body_string(), Some("Rocketeer".into()));
9 | }
10 |
--------------------------------------------------------------------------------
/examples/tera_templates/templates/error/404.html.tera:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 404
6 |
7 |
8 | 404: Hey! There's nothing here.
9 | The page at {{ path }} does not exist!
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/tls/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | #[get("/")]
8 | fn hello() -> &'static str {
9 | "Hello, world!"
10 | }
11 |
12 | fn main() {
13 | rocket::ignite().mount("/", routes![hello]).launch();
14 | }
15 |
--------------------------------------------------------------------------------
/core/lib/src/data/mod.rs:
--------------------------------------------------------------------------------
1 | //! Types and traits for handling incoming body data.
2 |
3 | mod data;
4 | mod data_stream;
5 | mod net_stream;
6 | mod from_data;
7 |
8 | pub use self::data::Data;
9 | pub use self::data_stream::DataStream;
10 | pub use self::from_data::{FromData, FromDataSimple, Outcome, Transform, Transformed};
11 |
--------------------------------------------------------------------------------
/examples/form_validation/static/index.html:
--------------------------------------------------------------------------------
1 | Login
2 |
3 |
9 |
--------------------------------------------------------------------------------
/examples/hello_2018/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[cfg(test)] mod tests;
4 |
5 | use rocket::{get, routes};
6 |
7 | #[get("/")]
8 | fn hello() -> &'static str {
9 | "Hello, Rust 2018!"
10 | }
11 |
12 | fn main() {
13 | rocket::ignite().mount("/", routes![hello]).launch();
14 | }
15 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: rust
2 | sudo: required # so we get a VM with higher specs
3 | dist: trusty # so we get a VM with higher specs
4 | cache: cargo
5 | env:
6 | - TEST_FLAGS=
7 | - TEST_FLAGS=--release
8 | - TEST_FLAGS=--contrib
9 | - TEST_FLAGS=--core
10 | rust:
11 | - nightly
12 | script: ./scripts/test.sh $TEST_FLAGS
13 |
--------------------------------------------------------------------------------
/examples/cookies/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "cookies"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 |
10 | [dependencies.rocket_contrib]
11 | path = "../../contrib/lib"
12 | default-features = false
13 | features = ["handlebars_templates"]
14 |
--------------------------------------------------------------------------------
/examples/hello_world/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | #[get("/")]
8 | fn hello() -> &'static str {
9 | "Hello, world!"
10 | }
11 |
12 | fn main() {
13 | rocket::ignite().mount("/", routes![hello]).launch();
14 | }
15 |
--------------------------------------------------------------------------------
/examples/todo/migrations/20160720150332_create_tasks_table/up.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE tasks (
2 | id INTEGER PRIMARY KEY AUTOINCREMENT,
3 | description VARCHAR NOT NULL,
4 | completed BOOLEAN NOT NULL DEFAULT 0
5 | );
6 |
7 | INSERT INTO tasks (description) VALUES ("demo task");
8 | INSERT INTO tasks (description) VALUES ("demo task2");
9 |
--------------------------------------------------------------------------------
/core/codegen/tests/route-params.rs:
--------------------------------------------------------------------------------
1 | // #[post("/<_name>?<_query>", format = "application/json", data = "", rank = 2)]
2 | // fn get(
3 | // _name: &RawStr,
4 | // _query: User,
5 | // user: Form,
6 | // _cookies: Cookies
7 | // ) -> String {
8 | // format!("{}:{}", user.name, user.nickname)
9 | // }
10 |
11 |
--------------------------------------------------------------------------------
/examples/todo/README.md:
--------------------------------------------------------------------------------
1 | # Rocket Todo Example
2 |
3 | This example makes use of a SQLite database via `diesel` to store todo tasks. As
4 | a result, you'll need to have `sqlite3` and its headers installed:
5 |
6 | * **OS X:** `brew install sqlite`
7 | * **Debian/Ubuntu:** `apt-get install libsqlite3-dev`
8 | * **Arch:** `pacman -S sqlite`
9 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/routes.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | fn main() {
6 | let _ = routes![a b]; //~ ERROR expected `,`
7 | let _ = routes![];
8 | let _ = routes![a::, ]; //~ ERROR expected identifier
9 | let _ = routes![a::]; //~ ERROR expected identifier
10 | }
11 |
--------------------------------------------------------------------------------
/examples/static_files/src/main.rs:
--------------------------------------------------------------------------------
1 | extern crate rocket;
2 | extern crate rocket_contrib;
3 |
4 | #[cfg(test)] mod tests;
5 |
6 | use rocket_contrib::serve::StaticFiles;
7 |
8 | fn rocket() -> rocket::Rocket {
9 | rocket::ignite().mount("/", StaticFiles::from("static"))
10 | }
11 |
12 | fn main() {
13 | rocket().launch();
14 | }
15 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/catchers.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | fn main() {
6 | let _ = catchers![a b]; //~ ERROR expected
7 | let _ = catchers![];
8 | let _ = catchers![a::, ]; //~ ERROR expected identifier
9 | let _ = catchers![a::]; //~ ERROR expected identifier
10 | }
11 |
--------------------------------------------------------------------------------
/examples/uuid/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "uuid"
3 | version = "0.1.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | lazy_static = "1.0"
10 | uuid = "0.7"
11 |
12 | [dependencies.rocket_contrib]
13 | default-features = false
14 | path = "../../contrib/lib"
15 | features = ["uuid"]
16 |
--------------------------------------------------------------------------------
/examples/msgpack/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "msgpack"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_derive = "1.0"
11 |
12 | [dependencies.rocket_contrib]
13 | path = "../../contrib/lib"
14 | default-features = false
15 | features = ["msgpack"]
16 |
--------------------------------------------------------------------------------
/examples/session/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "session"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib", features = ["private-cookies"] }
9 |
10 | [dependencies.rocket_contrib]
11 | path = "../../contrib/lib"
12 | default-features = false
13 | features = ["handlebars_templates"]
14 |
--------------------------------------------------------------------------------
/core/http/src/parse/checkers.rs:
--------------------------------------------------------------------------------
1 | #[inline(always)]
2 | pub fn is_whitespace(byte: char) -> bool {
3 | byte == ' ' || byte == '\t'
4 | }
5 |
6 | #[inline]
7 | pub fn is_valid_token(c: char) -> bool {
8 | match c {
9 | '0'...'9' | 'A'...'Z' | '^'...'~' | '#'...'\''
10 | | '!' | '*' | '+' | '-' | '.' => true,
11 | _ => false
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/examples/tls/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::rocket;
2 | use rocket::local::Client;
3 |
4 | #[test]
5 | fn hello_world() {
6 | let rocket = rocket::ignite().mount("/", routes![super::hello]);
7 | let client = Client::new(rocket).unwrap();
8 | let mut response = client.get("/").dispatch();
9 | assert_eq!(response.body_string(), Some("Hello, world!".into()));
10 | }
11 |
--------------------------------------------------------------------------------
/examples/hello_world/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::rocket;
2 | use rocket::local::Client;
3 |
4 | #[test]
5 | fn hello_world() {
6 | let rocket = rocket::ignite().mount("/", routes![super::hello]);
7 | let client = Client::new(rocket).unwrap();
8 | let mut response = client.get("/").dispatch();
9 | assert_eq!(response.body_string(), Some("Hello, world!".into()));
10 | }
11 |
--------------------------------------------------------------------------------
/examples/json/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "json"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_json = "1.0"
11 | serde_derive = "1.0"
12 |
13 | [dependencies.rocket_contrib]
14 | path = "../../contrib/lib"
15 | default-features = false
16 | features = ["json"]
17 |
--------------------------------------------------------------------------------
/examples/tera_templates/templates/index.html.tera:
--------------------------------------------------------------------------------
1 | {% extends "base" %}
2 |
3 | {% block content %}
4 | Hi {{name}}
5 | Here are your items:
6 |
7 | {% for s in items %}
8 | - {{ s }}
9 | {% endfor %}
10 |
11 |
12 | Try going to /hello/YourName
13 | {% endblock content %}
14 |
--------------------------------------------------------------------------------
/examples/form_validation/src/files.rs:
--------------------------------------------------------------------------------
1 | use rocket::response::NamedFile;
2 |
3 | use std::io;
4 | use std::path::{Path, PathBuf};
5 |
6 | #[get("/")]
7 | pub fn index() -> io::Result {
8 | NamedFile::open("static/index.html")
9 | }
10 |
11 | #[get("/", rank = 2)]
12 | pub fn files(file: PathBuf) -> io::Result {
13 | NamedFile::open(Path::new("static/").join(file))
14 | }
15 |
--------------------------------------------------------------------------------
/examples/tera_templates/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "tera_templates"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_derive = "1.0"
11 | serde_json = "1.0"
12 |
13 | [dependencies.rocket_contrib]
14 | path = "../../contrib/lib"
15 | default-features = false
16 | features = ["tera_templates"]
17 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/from_form_type_errors.rs:
--------------------------------------------------------------------------------
1 | #[macro_use] extern crate rocket;
2 |
3 | struct Unknown;
4 |
5 | #[derive(FromForm)]
6 | struct BadType3 {
7 | field: Unknown,
8 | //~^ rocket::request::FromFormValue
9 | }
10 |
11 | struct Foo(T);
12 |
13 | #[derive(FromForm)]
14 | struct Other {
15 | field: Foo,
16 | //~^ rocket::request::FromFormValue
17 | }
18 |
19 | fn main() { }
20 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "handlebars_templates"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_derive = "1.0"
11 | serde_json = "1.0"
12 |
13 | [dependencies.rocket_contrib]
14 | path = "../../contrib/lib"
15 | default-features = false
16 | features = ["handlebars_templates"]
17 |
--------------------------------------------------------------------------------
/contrib/lib/tests/databases.rs:
--------------------------------------------------------------------------------
1 | extern crate rocket;
2 | extern crate rocket_contrib;
3 |
4 | #[cfg(all(feature = "diesel_sqlite_pool", feature = "diesel_postgres_pool"))]
5 | mod databases_tests {
6 | use rocket_contrib::databases::{database, diesel};
7 |
8 | #[database("foo")]
9 | struct TempStorage(diesel::SqliteConnection);
10 |
11 | #[database("bar")]
12 | struct PrimaryDb(diesel::PgConnection);
13 | }
14 |
--------------------------------------------------------------------------------
/examples/managed_queue/src/tests.rs:
--------------------------------------------------------------------------------
1 | use rocket::local::Client;
2 | use rocket::http::Status;
3 |
4 | #[test]
5 | fn test_push_pop() {
6 | let client = Client::new(super::rocket()).unwrap();
7 |
8 | let response = client.put("/push?event=test1").dispatch();
9 | assert_eq!(response.status(), Status::Ok);
10 |
11 | let mut response = client.get("/pop").dispatch();
12 | assert_eq!(response.body_string(), Some("test1".to_string()));
13 | }
14 |
--------------------------------------------------------------------------------
/examples/request_local_state/src/tests.rs:
--------------------------------------------------------------------------------
1 | use std::sync::atomic::{Ordering};
2 |
3 | use super::{rocket, Atomics};
4 | use rocket::local::Client;
5 |
6 | #[test]
7 | fn test() {
8 | let client = Client::new(rocket()).unwrap();
9 | client.get("/").dispatch();
10 |
11 | let atomics = client.rocket().state::().unwrap();
12 | assert_eq!(atomics.uncached.load(Ordering::Relaxed), 2);
13 | assert_eq!(atomics.cached.load(Ordering::Relaxed), 1);
14 | }
15 |
--------------------------------------------------------------------------------
/core/lib/src/request/form/mod.rs:
--------------------------------------------------------------------------------
1 | //! Types and traits for form processing.
2 |
3 | mod form_items;
4 | mod from_form;
5 | mod from_form_value;
6 | mod lenient;
7 | mod error;
8 | mod form;
9 |
10 | pub use self::form_items::{FormItems, FormItem};
11 | pub use self::from_form::FromForm;
12 | pub use self::from_form_value::FromFormValue;
13 | pub use self::form::Form;
14 | pub use self::lenient::LenientForm;
15 | pub use self::error::{FormError, FormParseError, FormDataError};
16 |
--------------------------------------------------------------------------------
/examples/hello_person/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | #[get("/hello//")]
8 | fn hello(name: String, age: u8) -> String {
9 | format!("Hello, {} year old named {}!", age, name)
10 | }
11 |
12 | #[get("/hello/")]
13 | fn hi(name: String) -> String {
14 | name
15 | }
16 |
17 | fn main() {
18 | rocket::ignite().mount("/", routes![hello, hi]).launch();
19 | }
20 |
--------------------------------------------------------------------------------
/examples/redirect/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use rocket::response::Redirect;
8 |
9 | #[get("/")]
10 | fn root() -> Redirect {
11 | Redirect::to(uri!(login))
12 | }
13 |
14 | #[get("/login")]
15 | fn login() -> &'static str {
16 | "Hi! Please log in before continuing."
17 | }
18 |
19 | fn main() {
20 | rocket::ignite().mount("/", routes![root, login]).launch();
21 | }
22 |
--------------------------------------------------------------------------------
/examples/tls/Rocket.toml:
--------------------------------------------------------------------------------
1 | # The certificate/private key pair used here was generated via openssl using the
2 | # `gen_cert.sh` script located in the `private/` subdirectory.
3 | #
4 | # The certificate is self-signed. As such, you will need to trust it directly
5 | # for your browser to refer to the connection as secure. You should NEVER use
6 | # this certificate/key pair. It is here for DEMONSTRATION PURPOSES ONLY.
7 | [global.tls]
8 | certs = "private/cert.pem"
9 | key = "private/key.pem"
10 |
--------------------------------------------------------------------------------
/examples/handlebars_templates/templates/index.hbs:
--------------------------------------------------------------------------------
1 | {{#*inline "page"}}
2 |
3 |
4 | Hi {{ name }}!
5 | Here are your items:
6 |
7 | {{#each items}}
8 | - {{ this }}
9 | {{/each}}
10 |
11 |
12 |
13 |
14 | Try going to /hello/YourName.
15 | Also, check {{ wow "this" }} (custom helper) out!
16 |
17 |
18 | {{/inline}}
19 | {{~> (parent)~}}
20 |
--------------------------------------------------------------------------------
/examples/session/templates/index.html.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Rocket: Session Example
7 |
8 |
9 | Rocket Session Example
10 | Logged in with user ID {{ user_id }}.
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled files
2 | *.o
3 | *.so
4 | *.rlib
5 | *.dll
6 |
7 | # Executables
8 | *.exe
9 |
10 | # Generated by Cargo
11 | target
12 |
13 | # Generated databases
14 | db.sqlite
15 |
16 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
17 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
18 | Cargo.lock
19 |
20 | # The upload script, for now.
21 | scripts/upload-docs.sh
22 | scripts/redirect.html
23 |
24 | # Backup files.
25 | *.bak
26 |
27 | # Uploads in pastebin example.
28 | examples/pastebin/upload/*
29 |
--------------------------------------------------------------------------------
/examples/ranking/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | use rocket::http::RawStr;
6 |
7 | #[cfg(test)] mod tests;
8 |
9 | #[get("/hello//")]
10 | fn hello(name: String, age: i8) -> String {
11 | format!("Hello, {} year old named {}!", age, name)
12 | }
13 |
14 | #[get("/hello//", rank = 2)]
15 | fn hi(name: String, age: &RawStr) -> String {
16 | format!("Hi {}! Your age ({}) is kind of funky.", name, age)
17 | }
18 |
19 | fn main() {
20 | rocket::ignite().mount("/", routes![hi, hello]).launch();
21 | }
22 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/routes.stderr:
--------------------------------------------------------------------------------
1 | error: expected `,`
2 | --> $DIR/routes.rs:6:23
3 | |
4 | 6 | let _ = routes![a b]; //~ ERROR expected `,`
5 | | ^
6 |
7 | error: expected identifier
8 | --> $DIR/routes.rs:8:24
9 | |
10 | 8 | let _ = routes![a::, ]; //~ ERROR expected identifier
11 | | ^
12 |
13 | error: unexpected end of input, expected identifier
14 | --> $DIR/routes.rs:9:13
15 | |
16 | 9 | let _ = routes![a::]; //~ ERROR expected identifier
17 | | ^^^^^^^^^^^^
18 |
19 | error: aborting due to 3 previous errors
20 |
21 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/catchers.stderr:
--------------------------------------------------------------------------------
1 | error: expected `,`
2 | --> $DIR/catchers.rs:6:25
3 | |
4 | 6 | let _ = catchers![a b]; //~ ERROR expected
5 | | ^
6 |
7 | error: expected identifier
8 | --> $DIR/catchers.rs:8:26
9 | |
10 | 8 | let _ = catchers![a::, ]; //~ ERROR expected identifier
11 | | ^
12 |
13 | error: unexpected end of input, expected identifier
14 | --> $DIR/catchers.rs:9:13
15 | |
16 | 9 | let _ = catchers![a::]; //~ ERROR expected identifier
17 | | ^^^^^^^^^^^^^^
18 |
19 | error: aborting due to 3 previous errors
20 |
21 |
--------------------------------------------------------------------------------
/core/lib/src/ext.rs:
--------------------------------------------------------------------------------
1 | use std::io;
2 |
3 | pub trait ReadExt: io::Read {
4 | fn read_max(&mut self, mut buf: &mut [u8]) -> io::Result {
5 | let start_len = buf.len();
6 | while !buf.is_empty() {
7 | match self.read(buf) {
8 | Ok(0) => break,
9 | Ok(n) => { let tmp = buf; buf = &mut tmp[n..]; }
10 | Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
11 | Err(e) => return Err(e),
12 | }
13 | }
14 |
15 | Ok(start_len - buf.len())
16 | }
17 | }
18 |
19 | impl ReadExt for T { }
20 |
--------------------------------------------------------------------------------
/examples/todo/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "todo"
3 | version = "0.0.0"
4 | workspace = "../../"
5 | publish = false
6 |
7 | [dependencies]
8 | rocket = { path = "../../core/lib" }
9 | serde = "1.0"
10 | serde_json = "1.0"
11 | serde_derive = "1.0"
12 | diesel = { version = "1.3", features = ["sqlite", "r2d2"] }
13 | diesel_migrations = "1.3"
14 | log = "0.4"
15 |
16 | [dev-dependencies]
17 | parking_lot = { version = "0.6", features = ["nightly"] }
18 | rand = "0.6"
19 |
20 | [dependencies.rocket_contrib]
21 | path = "../../contrib/lib"
22 | default_features = false
23 | features = ["tera_templates", "diesel_sqlite_pool", "serve"]
24 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/catch_type_errors.rs:
--------------------------------------------------------------------------------
1 | #[macro_use] extern crate rocket;
2 |
3 | use rocket::Request;
4 |
5 | #[catch(404)]
6 | fn f1(_request: &Request) -> usize {
7 | //~^ ERROR usize: rocket::response::Responder
8 | 10
9 | }
10 |
11 | #[catch(404)]
12 | fn f2(_request: &Request) -> bool {
13 | //~^ ERROR bool: rocket::response::Responder
14 | false
15 | }
16 |
17 | #[catch(404)]
18 | fn f3(_request: bool) -> usize {
19 | //~^ ERROR mismatched types
20 | 10
21 | }
22 |
23 | #[catch(404)]
24 | fn f4() -> usize {
25 | //~^ ERROR usize: rocket::response::Responder
26 | 10
27 | }
28 |
29 | fn main() { }
30 |
--------------------------------------------------------------------------------
/examples/raw_upload/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use std::{io, env};
8 | use rocket::Data;
9 |
10 | #[post("/upload", format = "plain", data = "")]
11 | fn upload(data: Data) -> io::Result {
12 | data.stream_to_file(env::temp_dir().join("upload.txt")).map(|n| n.to_string())
13 | }
14 |
15 | #[get("/")]
16 | fn index() -> &'static str {
17 | "Upload your text files by POSTing them to /upload."
18 | }
19 |
20 | fn rocket() -> rocket::Rocket {
21 | rocket::ignite().mount("/", routes![index, upload])
22 | }
23 |
24 | fn main() {
25 | rocket().launch();
26 | }
27 |
--------------------------------------------------------------------------------
/core/lib/src/request/mod.rs:
--------------------------------------------------------------------------------
1 | //! Types and traits for request parsing and handling.
2 |
3 | mod request;
4 | mod param;
5 | mod form;
6 | mod from_request;
7 | mod state;
8 | mod query;
9 |
10 | #[cfg(test)]
11 | mod tests;
12 |
13 | pub use self::request::Request;
14 | pub use self::from_request::{FromRequest, Outcome};
15 | pub use self::param::{FromParam, FromSegments};
16 | pub use self::form::{FromForm, FromFormValue};
17 | pub use self::form::{Form, LenientForm, FormItems, FormItem};
18 | pub use self::form::{FormError, FormParseError, FormDataError};
19 | pub use self::state::State;
20 | pub use self::query::{Query, FromQuery};
21 |
22 | #[doc(inline)]
23 | pub use response::flash::FlashMessage;
24 |
--------------------------------------------------------------------------------
/examples/cookies/templates/index.html.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Rocket: Cookie Examples
7 |
8 |
9 | Rocket Cookie Examples
10 | {{#if message }}
11 | {{message}}
12 | {{else}}
13 | No message yet.
14 | {{/if}}
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/managed_queue/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 | extern crate crossbeam;
5 |
6 | #[cfg(test)] mod tests;
7 |
8 | use rocket::State;
9 | use crossbeam::queue::MsQueue;
10 |
11 | struct LogChannel(MsQueue);
12 |
13 | #[put("/push?")]
14 | fn push(event: String, queue: State) {
15 | queue.0.push(event);
16 | }
17 |
18 | #[get("/pop")]
19 | fn pop(queue: State) -> String {
20 | queue.0.pop()
21 | }
22 |
23 | fn rocket() -> rocket::Rocket {
24 | rocket::ignite()
25 | .mount("/", routes![push, pop])
26 | .manage(LogChannel(MsQueue::new()))
27 | }
28 |
29 | fn main() {
30 | rocket().launch();
31 | }
32 |
--------------------------------------------------------------------------------
/contrib/codegen/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rocket_contrib_codegen"
3 | version = "0.4.0"
4 | authors = ["Sergio Benitez "]
5 | description = "Procedural macros for the Rocket contrib libraries."
6 | documentation = "https://api.rocket.rs/v0.4/rocket_contrib/"
7 | homepage = "https://rocket.rs"
8 | repository = "https://github.com/SergioBenitez/Rocket"
9 | readme = "../../README.md"
10 | keywords = ["rocket", "contrib", "code", "generation", "proc-macro"]
11 | license = "MIT/Apache-2.0"
12 | build = "build.rs"
13 |
14 | [features]
15 | database_attribute = []
16 |
17 | [lib]
18 | proc-macro = true
19 |
20 | [dependencies]
21 | devise = "0.2"
22 | quote = "0.6"
23 |
24 | [build-dependencies]
25 | yansi = "0.5"
26 | version_check = "0.1.3"
27 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/from_form_type_errors.stderr:
--------------------------------------------------------------------------------
1 | error[E0277]: the trait bound `Unknown: rocket::request::FromFormValue<'_>` is not satisfied
2 | --> $DIR/from_form_type_errors.rs:7:5
3 | |
4 | 7 | field: Unknown,
5 | | ^^^^^^^^^^^^^^ the trait `rocket::request::FromFormValue<'_>` is not implemented for `Unknown`
6 |
7 | error[E0277]: the trait bound `Foo: rocket::request::FromFormValue<'_>` is not satisfied
8 | --> $DIR/from_form_type_errors.rs:15:5
9 | |
10 | 15 | field: Foo,
11 | | ^^^^^^^^^^^^^^^^^ the trait `rocket::request::FromFormValue<'_>` is not implemented for `Foo`
12 |
13 | error: aborting due to 2 previous errors
14 |
15 | For more information about this error, try `rustc --explain E0277`.
16 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/responder-types.rs:
--------------------------------------------------------------------------------
1 | // normalize-stderr-test: "<(.*) as (.*)>" -> "$1 as $$TRAIT"
2 | // normalize-stderr-test: "and \d+ others" -> "and $$N others"
3 |
4 | #[macro_use] extern crate rocket;
5 |
6 | #[derive(Responder)]
7 | struct Thing1 {
8 | thing: u8,
9 | //~^ ERROR Responder
10 | }
11 |
12 | #[derive(Responder)]
13 | struct Thing2 {
14 | thing: String,
15 | other: u8,
16 | //~^ ERROR Header
17 | }
18 |
19 | #[derive(Responder)]
20 | struct Thing3 {
21 | thing: u8,
22 | //~^ ERROR Responder
23 | other: u8,
24 | //~^ ERROR Header
25 | }
26 |
27 | #[derive(Responder)]
28 | struct Thing4 {
29 | thing: String,
30 | other: ::rocket::http::ContentType,
31 | then: String,
32 | //~^ ERROR Header
33 | }
34 |
35 | fn main() { }
36 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/typed-uris-invalid-syntax.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[post("//")]
6 | fn simple(id: i32, name: String) -> &'static str { "" }
7 |
8 | fn main() {
9 | uri!(simple: id = 100, "Hello"); //~ ERROR named and unnamed
10 | uri!(simple: "Hello", id = 100); //~ ERROR named and unnamed
11 | uri!(simple,); //~ ERROR expected `:`
12 | uri!(simple:); //~ ERROR argument list
13 | uri!("/mount"); //~ ERROR route path
14 | uri!("/mount",); //~ ERROR expected identifier
15 | uri!("mount", simple); //~ invalid mount point
16 | uri!("/mount/", simple); //~ invalid mount point
17 | uri!(); //~ unexpected end of input
18 | uri!(simple: id = ); //~ expected expression
19 | }
20 |
--------------------------------------------------------------------------------
/examples/testing/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[get("/")]
6 | fn hello() -> &'static str {
7 | "Hello, world!"
8 | }
9 |
10 | fn rocket() -> rocket::Rocket {
11 | rocket::ignite().mount("/", routes![hello])
12 | }
13 |
14 | fn main() {
15 | rocket().launch();
16 | }
17 |
18 | #[cfg(test)]
19 | mod test {
20 | use super::rocket;
21 | use rocket::local::Client;
22 | use rocket::http::Status;
23 |
24 | #[test]
25 | fn test_hello() {
26 | let client = Client::new(rocket()).unwrap();
27 | let mut response = client.get("/").dispatch();
28 | assert_eq!(response.status(), Status::Ok);
29 | assert_eq!(response.body_string(), Some("Hello, world!".into()));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/examples/optional_redirect/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)]
6 | mod tests;
7 |
8 | use rocket::response::Redirect;
9 | use rocket::http::RawStr;
10 |
11 | #[get("/")]
12 | fn root() -> Redirect {
13 | Redirect::to("/users/login")
14 | }
15 |
16 | #[get("/users/")]
17 | fn user(name: &RawStr) -> Result<&'static str, Redirect> {
18 | match name.as_str() {
19 | "Sergio" => Ok("Hello, Sergio!"),
20 | _ => Err(Redirect::to("/users/login")),
21 | }
22 | }
23 |
24 | #[get("/users/login")]
25 | fn login() -> &'static str {
26 | "Hi! That user doesn't exist. Maybe you need to log in?"
27 | }
28 |
29 | fn main() {
30 | rocket::ignite().mount("/", routes![root, user, login]).launch();
31 | }
32 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/route-type-errors.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | struct Q;
6 |
7 | #[get("/")]
8 | fn f0(foo: Q) {} //~ ERROR FromParam
9 |
10 | #[get("/")]
11 | fn f1(foo: Q) {} //~ ERROR FromSegments
12 |
13 | #[get("/?")]
14 | fn f2(foo: Q) {} //~ ERROR FromFormValue
15 |
16 | #[get("/?")]
17 | fn f3(foo: Q) {} //~ ERROR FromQuery
18 |
19 | #[post("/", data = "")]
20 | fn f4(foo: Q) {} //~ ERROR FromData
21 |
22 | #[get("/")]
23 | fn f5(a: Q, foo: Q) {}
24 | //~^ ERROR FromParam
25 | //~^^ ERROR FromRequest
26 |
27 | #[get("//other///okay")]
28 | fn f6(a: Q, foo: Q, good: usize, bar: Q) {}
29 | //~^ ERROR FromParam
30 | //~^^ ERROR FromParam
31 | //~^^^ ERROR FromRequest
32 |
33 | fn main() { }
34 |
--------------------------------------------------------------------------------
/core/lib/tests/redirect_from_catcher-issue-113.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | use rocket::response::Redirect;
6 |
7 | #[catch(404)]
8 | fn not_found() -> Redirect {
9 | Redirect::to("/")
10 | }
11 |
12 | mod tests {
13 | use super::*;
14 | use rocket::local::Client;
15 | use rocket::http::Status;
16 |
17 | #[test]
18 | fn error_catcher_redirect() {
19 | let client = Client::new(rocket::ignite().register(catchers![not_found])).unwrap();
20 | let response = client.get("/unknown").dispatch();
21 | println!("Response:\n{:?}", response);
22 |
23 | let location: Vec<_> = response.headers().get("location").collect();
24 | assert_eq!(response.status(), Status::SeeOther);
25 | assert_eq!(location, vec!["/"]);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/examples/session/templates/login.html.hbs:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Rocket: Sessions
7 |
8 |
9 | Rocket Session: Please Login
10 |
11 | Please login to continue.
12 |
13 | {{#if flash}}
14 | Error: {{ flash }}
15 | {{/if}}
16 |
17 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/core/codegen/src/syn_ext.rs:
--------------------------------------------------------------------------------
1 | //! Extensions to `syn` types.
2 |
3 | use devise::syn;
4 | use proc_macro::Diagnostic;
5 |
6 | pub fn syn_to_diag(error: syn::parse::Error) -> Diagnostic {
7 | error.span().unstable().error(error.to_string())
8 | }
9 |
10 | pub trait IdentExt {
11 | fn prepend(&self, string: &str) -> syn::Ident;
12 | }
13 |
14 | impl IdentExt for syn::Ident {
15 | fn prepend(&self, string: &str) -> syn::Ident {
16 | syn::Ident::new(&format!("{}{}", string, self), self.span())
17 | }
18 | }
19 |
20 | pub trait ReturnTypeExt {
21 | fn ty(&self) -> Option<&syn::Type>;
22 | }
23 |
24 | impl ReturnTypeExt for syn::ReturnType {
25 | fn ty(&self) -> Option<&syn::Type> {
26 | match self {
27 | syn::ReturnType::Default => None,
28 | syn::ReturnType::Type(_, ty) => Some(ty),
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/route-warnings.rs:
--------------------------------------------------------------------------------
1 | // must-compile-successfully
2 |
3 | #![feature(proc_macro_hygiene, decl_macro)]
4 |
5 | #[macro_use] extern crate rocket;
6 |
7 | // Check for unknown media types.
8 |
9 | #[get("/", format = "application/x-custom")] //~ WARNING not a known media type
10 | fn f0() {}
11 |
12 | #[get("/", format = "x-custom/plain")] //~ WARNING not a known media type
13 | fn f1() {}
14 |
15 | #[get("/", format = "x-custom/x-custom")] //~ WARNING not a known media type
16 | fn f2() {}
17 |
18 | // Check if a data argument is used with a usually non-payload bearing method.
19 |
20 | #[get("/", data = "<_foo>")] //~ WARNING used with non-payload-supporting method
21 | fn g0(_foo: rocket::Data) {}
22 |
23 | #[head("/", data = "<_foo>")] //~ WARNING used with non-payload-supporting method
24 | fn g1(_foo: rocket::Data) {}
25 |
26 | fn main() { }
27 |
--------------------------------------------------------------------------------
/examples/msgpack/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 | #[macro_use] extern crate serde_derive;
5 | extern crate rocket_contrib;
6 |
7 | #[cfg(test)] mod tests;
8 |
9 | use rocket_contrib::msgpack::MsgPack;
10 |
11 | #[derive(Serialize, Deserialize)]
12 | struct Message<'r> {
13 | id: usize,
14 | contents: &'r str
15 | }
16 |
17 | #[get("/", format = "msgpack")]
18 | fn get(id: usize) -> MsgPack> {
19 | MsgPack(Message { id: id, contents: "Hello, world!", })
20 | }
21 |
22 | #[post("/", data = "", format = "msgpack")]
23 | fn create(data: MsgPack) -> String {
24 | data.contents.to_string()
25 | }
26 |
27 | fn rocket() -> rocket::Rocket {
28 | rocket::ignite().mount("/message", routes![get, create])
29 | }
30 |
31 | fn main() {
32 | rocket().launch();
33 | }
34 |
--------------------------------------------------------------------------------
/examples/stream/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use rocket::response::{content, Stream};
8 |
9 | use std::io::{self, repeat, Repeat, Read, Take};
10 | use std::fs::File;
11 |
12 | type LimitedRepeat = Take;
13 |
14 | // Generate this file using: head -c BYTES /dev/random > big_file.dat
15 | const FILENAME: &str = "big_file.dat";
16 |
17 | #[get("/")]
18 | fn root() -> content::Plain> {
19 | content::Plain(Stream::from(repeat('a' as u8).take(25000)))
20 | }
21 |
22 | #[get("/big_file")]
23 | fn file() -> io::Result> {
24 | File::open(FILENAME).map(|file| Stream::from(file))
25 | }
26 |
27 | fn rocket() -> rocket::Rocket {
28 | rocket::ignite().mount("/", routes![root, file])
29 | }
30 |
31 | fn main() {
32 | rocket().launch();
33 | }
34 |
--------------------------------------------------------------------------------
/core/codegen/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "rocket_codegen"
3 | version = "0.4.0"
4 | authors = ["Sergio Benitez "]
5 | description = "Procedural macros for the Rocket web framework."
6 | documentation = "https://api.rocket.rs/v0.4/rocket_codegen/"
7 | homepage = "https://rocket.rs"
8 | repository = "https://github.com/SergioBenitez/Rocket"
9 | readme = "../../README.md"
10 | keywords = ["rocket", "web", "framework", "code", "generation"]
11 | license = "MIT/Apache-2.0"
12 | build = "build.rs"
13 |
14 | [lib]
15 | proc-macro = true
16 |
17 | [dependencies]
18 | indexmap = "1.0"
19 | quote = "0.6.1"
20 | rocket_http = { version = "0.4.0", path = "../http/" }
21 | devise = "0.2"
22 |
23 | [build-dependencies]
24 | yansi = "0.5"
25 | version_check = "0.1.3"
26 |
27 | [dev-dependencies]
28 | rocket = { version = "0.4.0", path = "../lib" }
29 | compiletest_rs = { version = "0.3", features = ["stable"] }
30 |
--------------------------------------------------------------------------------
/scripts/mk-docs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | #
5 | # Builds the rustdocs for all of the libraries.
6 | #
7 |
8 | # Brings in: PROJECT_ROOT, EXAMPLES_DIR, LIB_DIR, CODEGEN_DIR, CONTRIB_DIR, DOC_DIR
9 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
10 | source "${SCRIPT_DIR}/config.sh"
11 |
12 | if [ "${1}" != "-d" ]; then
13 | # We need to clean-up beforehand so we don't get all of the dependencies.
14 | echo ":::: Cleaning up before documenting..."
15 | cargo clean
16 | cargo update
17 | fi
18 |
19 | # Generate the rustdocs for all of the crates.
20 | echo ":::: Generating the docs..."
21 | pushd "${PROJECT_ROOT}" > /dev/null 2>&1
22 | RUSTDOCFLAGS="-Z unstable-options --crate-version ${ROCKET_VERSION}" \
23 | cargo doc -p rocket -p rocket_contrib -p rocket_codegen --no-deps --all-features
24 | popd > /dev/null 2>&1
25 |
26 | # Blank index, for redirection.
27 | touch "${DOC_DIR}/index.html"
28 |
--------------------------------------------------------------------------------
/core/codegen/tests/ui-fail/from_form_value.rs:
--------------------------------------------------------------------------------
1 | #[macro_use] extern crate rocket;
2 |
3 | #[derive(FromFormValue)]
4 | struct Foo1;
5 | //~^ ERROR not supported
6 |
7 | #[derive(FromFormValue)]
8 | struct Foo2(usize);
9 | //~^ ERROR not supported
10 |
11 | #[derive(FromFormValue)]
12 | struct Foo3 {
13 | //~^ ERROR not supported
14 | foo: usize,
15 | }
16 |
17 | #[derive(FromFormValue)]
18 | enum Foo4 {
19 | A(usize),
20 | //~^ ERROR cannot have fields
21 | }
22 |
23 | #[derive(FromFormValue)]
24 | enum Foo5 { }
25 | //~^ WARNING empty enum
26 |
27 | #[derive(FromFormValue)]
28 | enum Foo6 {
29 | //~^ ERROR type generics are not supported
30 | A(T),
31 | }
32 |
33 | #[derive(FromFormValue)]
34 | enum Bar1 {
35 | #[form(value = 123)]
36 | //~^ ERROR invalid value: expected string
37 | A,
38 | }
39 |
40 | #[derive(FromFormValue)]
41 | enum Bar2 {
42 | #[form(value)]
43 | //~^ ERROR expected literal or key/value
44 | A,
45 | }
46 |
--------------------------------------------------------------------------------
/examples/errors/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use rocket::response::content;
8 |
9 | #[get("/hello//")]
10 | fn hello(name: String, age: i8) -> String {
11 | format!("Hello, {} year old named {}!", age, name)
12 | }
13 |
14 | #[catch(404)]
15 | fn not_found(req: &rocket::Request) -> content::Html {
16 | content::Html(format!("Sorry, but '{}' is not a valid path!
17 | Try visiting /hello/<name>/<age> instead.
",
18 | req.uri()))
19 | }
20 |
21 | fn main() {
22 | let e = rocket::ignite()
23 | // .mount("/", routes![hello, hello]) // uncoment this to get an error
24 | .mount("/", routes![hello])
25 | .register(catchers![not_found])
26 | .launch();
27 |
28 | println!("Whoops! Rocket didn't launch!");
29 | println!("This went wrong: {}", e);
30 | }
31 |
--------------------------------------------------------------------------------
/core/lib/tests/responder_lifetime-issue-345.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 | #![allow(dead_code)] // This test is only here so that we can ensure it compiles.
3 |
4 | #[macro_use] extern crate rocket;
5 |
6 | use rocket::State;
7 | use rocket::response::{self, Responder};
8 |
9 | struct SomeState;
10 |
11 | pub struct CustomResponder<'r, R> {
12 | responder: R,
13 | state: &'r SomeState,
14 | }
15 |
16 | impl<'r, R: Responder<'r>> Responder<'r> for CustomResponder<'r, R> {
17 | fn respond_to(self, _: &rocket::Request) -> response::Result<'r> {
18 | unimplemented!()
19 | }
20 | }
21 |
22 | #[get("/unit_state")]
23 | fn unit_state(state: State) -> CustomResponder<()> {
24 | CustomResponder { responder: (), state: state.inner() }
25 | }
26 |
27 | #[get("/string_state")]
28 | fn string_state(state: State) -> CustomResponder {
29 | CustomResponder { responder: "".to_string(), state: state.inner() }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/uuid/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::rocket;
2 | use rocket::local::Client;
3 | use rocket::http::Status;
4 |
5 | fn test(uri: &str, expected: &str) {
6 | let client = Client::new(rocket()).unwrap();
7 | let mut res = client.get(uri).dispatch();
8 | assert_eq!(res.body_string(), Some(expected.into()));
9 | }
10 |
11 | fn test_404(uri: &str) {
12 | let client = Client::new(rocket()).unwrap();
13 | let res = client.get(uri).dispatch();
14 | assert_eq!(res.status(), Status::NotFound);
15 | }
16 |
17 | #[test]
18 | fn test_people() {
19 | test("/people/7f205202-7ba1-4c39-b2fc-3e630722bf9f", "We found: Lacy");
20 | test("/people/4da34121-bc7d-4fc1-aee6-bf8de0795333", "We found: Bob");
21 | test("/people/ad962969-4e3d-4de7-ac4a-2d86d6d10839", "We found: George");
22 | test("/people/e18b3a5c-488f-4159-a240-2101e0da19fd",
23 | "Person not found for UUID: e18b3a5c-488f-4159-a240-2101e0da19fd");
24 | test_404("/people/invalid_uuid");
25 | }
26 |
--------------------------------------------------------------------------------
/examples/state/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use std::sync::atomic::{AtomicUsize, Ordering};
8 |
9 | use rocket::State;
10 | use rocket::response::content;
11 |
12 | struct HitCount(AtomicUsize);
13 |
14 | #[get("/")]
15 | fn index(hit_count: State) -> content::Html {
16 | hit_count.0.fetch_add(1, Ordering::Relaxed);
17 | let msg = "Your visit has been recorded!";
18 | let count = format!("Visits: {}", count(hit_count));
19 | content::Html(format!("{}
{}", msg, count))
20 | }
21 |
22 | #[get("/count")]
23 | fn count(hit_count: State) -> String {
24 | hit_count.0.load(Ordering::Relaxed).to_string()
25 | }
26 |
27 | fn rocket() -> rocket::Rocket {
28 | rocket::ignite()
29 | .mount("/", routes![index, count])
30 | .manage(HitCount(AtomicUsize::new(0)))
31 | }
32 |
33 | fn main() {
34 | rocket().launch();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/redirect/src/tests.rs:
--------------------------------------------------------------------------------
1 | use super::rocket;
2 | use rocket::local::Client;
3 | use rocket::http::Status;
4 |
5 | fn client() -> Client {
6 | let rocket = rocket::ignite().mount("/", routes![super::root, super::login]);
7 | Client::new(rocket).unwrap()
8 | }
9 |
10 | #[test]
11 | fn test_root() {
12 | let client = client();
13 | let mut response = client.get("/").dispatch();
14 |
15 | assert!(response.body().is_none());
16 | assert_eq!(response.status(), Status::SeeOther);
17 | for h in response.headers().iter() {
18 | match h.name.as_str() {
19 | "Location" => assert_eq!(h.value, "/login"),
20 | "Content-Length" => assert_eq!(h.value.parse::().unwrap(), 0),
21 | _ => { /* let these through */ }
22 | }
23 | }
24 | }
25 |
26 | #[test]
27 | fn test_login() {
28 | let client = client();
29 | let mut r = client.get("/login").dispatch();
30 | assert_eq!(r.body_string(), Some("Hi! Please log in before continuing.".into()));
31 | }
32 |
--------------------------------------------------------------------------------
/examples/tls/private/gen_cert.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | # TODO: `rustls` (really, `webpki`) doesn't currently use the CN in the subject
4 | # to check if a certificate is valid for a server name sent via SNI. It's not
5 | # clear if this is intended, since certificates _should_ have a `subjectAltName`
6 | # with a DNS name, or if it simply hasn't been implemented yet. See
7 | # https://bugzilla.mozilla.org/show_bug.cgi?id=552346 for a bit more info.
8 |
9 | CA_SUBJECT="/C=US/ST=CA/O=Rocket CA/CN=Rocket Root CA"
10 | SUBJECT="/C=US/ST=CA/O=Rocket/CN=localhost"
11 | ALT="DNS:localhost"
12 |
13 | openssl genrsa -out ca_key.pem 4096
14 | openssl req -new -x509 -days 3650 -key ca_key.pem -subj "${CA_SUBJECT}" -out ca_cert.pem
15 |
16 | openssl req -newkey rsa:4096 -nodes -sha256 -keyout key.pem -subj "${SUBJECT}" -out server.csr
17 | openssl x509 -req -sha256 -extfile <(printf "subjectAltName=${ALT}") -days 3650 \
18 | -CA ca_cert.pem -CAkey ca_key.pem -CAcreateserial \
19 | -in server.csr -out cert.pem
20 |
21 | rm ca_cert.srl server.csr
22 |
--------------------------------------------------------------------------------
/examples/query_params/src/main.rs:
--------------------------------------------------------------------------------
1 | #![feature(proc_macro_hygiene, decl_macro)]
2 |
3 | #[macro_use] extern crate rocket;
4 |
5 | #[cfg(test)] mod tests;
6 |
7 | use rocket::request::{Form, LenientForm};
8 |
9 | #[derive(FromForm)]
10 | struct Person {
11 | name: String,
12 | age: Option
13 | }
14 |
15 | #[get("/hello?")]
16 | fn hello(person: Option