-
Notifications
You must be signed in to change notification settings - Fork 61
Refactor runtime crates into feature-guarded modules #131
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
935234a
New feature: cloudevents-actix
jcrossley3 51b49f1
New feature: cloudevents-reqwest
jcrossley3 9055d71
New feature: cloudevents-rdkafka
jcrossley3 538b647
New feature: cloudevents-warp
jcrossley3 69f16a5
Fixed docs
jcrossley3 4979c44
Build/Test --all-features for action matrix
jcrossley3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,7 @@ authors = ["Francesco Guardiani <[email protected]>"] | |
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| cloudevents-sdk = { path = "../.." } | ||
| cloudevents-sdk-actix-web = { path = "../../cloudevents-sdk-actix-web" } | ||
| cloudevents-sdk = { path = "../..", features = ["cloudevents-actix"] } | ||
| actix-web = "^3" | ||
| actix-cors = "^0.5" | ||
| lazy_static = "1.4.0" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| use crate::event::SpecVersion; | ||
| use actix_web::http::header; | ||
| use actix_web::http::{HeaderName, HeaderValue}; | ||
| use lazy_static::lazy_static; | ||
| use std::collections::HashMap; | ||
| use std::str::FromStr; | ||
|
|
||
| macro_rules! unwrap_optional_header { | ||
| ($headers:expr, $name:expr) => { | ||
| $headers | ||
| .get::<&'static HeaderName>(&$name) | ||
| .map(|a| header_value_to_str!(a)) | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! header_value_to_str { | ||
| ($header_value:expr) => { | ||
| $header_value | ||
| .to_str() | ||
| .map_err(|e| crate::message::Error::Other { | ||
| source: Box::new(e), | ||
| }) | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! str_to_header_value { | ||
| ($header_value:expr) => { | ||
| HeaderValue::from_str($header_value).map_err(|e| crate::message::Error::Other { | ||
| source: Box::new(e), | ||
| }) | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! str_name_to_header { | ||
| ($attribute:expr) => { | ||
| HeaderName::from_str($attribute).map_err(|e| crate::message::Error::Other { | ||
| source: Box::new(e), | ||
| }) | ||
| }; | ||
| } | ||
|
|
||
| macro_rules! attribute_name_to_header { | ||
| ($attribute:expr) => { | ||
| str_name_to_header!(&["ce-", $attribute].concat()) | ||
| }; | ||
| } | ||
|
|
||
| fn attributes_to_headers( | ||
| it: impl Iterator<Item = &'static str>, | ||
| ) -> HashMap<&'static str, HeaderName> { | ||
| it.map(|s| { | ||
| if s == "datacontenttype" { | ||
| (s, header::CONTENT_TYPE) | ||
| } else { | ||
| (s, attribute_name_to_header!(s).unwrap()) | ||
| } | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| lazy_static! { | ||
| pub(crate) static ref ATTRIBUTES_TO_HEADERS: HashMap<&'static str, HeaderName> = | ||
| attributes_to_headers(SpecVersion::all_attribute_names()); | ||
| pub(crate) static ref SPEC_VERSION_HEADER: HeaderName = | ||
| HeaderName::from_static("ce-specversion"); | ||
| pub(crate) static ref CLOUDEVENTS_JSON_HEADER: HeaderValue = | ||
| HeaderValue::from_static("application/cloudevents+json"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //! This module integrates the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) with [Actix web](https://docs.rs/actix-web/) to easily send and receive CloudEvents. | ||
| //! | ||
| //! To deserialize an HTTP request as CloudEvent: | ||
| //! | ||
| //! ``` | ||
| //! use cloudevents::actix::HttpRequestExt; | ||
| //! use actix_web::{HttpRequest, web, post}; | ||
| //! | ||
| //! #[post("/")] | ||
| //! async fn post_event(req: HttpRequest, payload: web::Payload) -> Result<String, actix_web::Error> { | ||
| //! let event = req.to_event(payload).await?; | ||
| //! println!("Received Event: {:?}", event); | ||
| //! Ok(format!("{:?}", event)) | ||
| //! } | ||
| //! ``` | ||
| //! | ||
| //! To serialize a CloudEvent to an HTTP response: | ||
| //! | ||
| //! ``` | ||
| //! use cloudevents::actix::HttpResponseBuilderExt; | ||
| //! use actix_web::{HttpRequest, web, get, HttpResponse}; | ||
| //! use cloudevents::{EventBuilderV10, EventBuilder}; | ||
| //! use serde_json::json; | ||
| //! | ||
| //! #[get("/")] | ||
| //! async fn get_event() -> Result<HttpResponse, actix_web::Error> { | ||
| //! Ok(HttpResponse::Ok() | ||
| //! .event( | ||
| //! EventBuilderV10::new() | ||
| //! .id("0001") | ||
| //! .ty("example.test") | ||
| //! .source("http://localhost/") | ||
| //! .data("application/json", json!({"hello": "world"})) | ||
| //! .build() | ||
| //! .expect("No error while building the event"), | ||
| //! ) | ||
| //! .await? | ||
| //! ) | ||
| //! } | ||
| //! ``` | ||
|
|
||
| #![deny(broken_intra_doc_links)] | ||
|
|
||
| #[macro_use] | ||
| mod headers; | ||
| mod server_request; | ||
| mod server_response; | ||
|
|
||
| pub use server_request::request_to_event; | ||
| pub use server_request::HttpRequestDeserializer; | ||
| pub use server_request::HttpRequestExt; | ||
| pub use server_response::event_to_response; | ||
| pub use server_response::HttpResponseBuilderExt; | ||
| pub use server_response::HttpResponseSerializer; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but maybe for future refactorings: a lot of these macros are copy paste, because the APIs are practically the same even if their names are different, so it would be nice to find a way to unify them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #146