Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Grimm <dgrimm@redhat.com>
  • Loading branch information
dgn committed Nov 20, 2020
1 parent 5f0302c commit 9756371
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 6 additions & 9 deletions examples/http_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::str;
use proxy_wasm::traits::*;
use proxy_wasm::types::*;
use std::str;

#[no_mangle]
pub fn _start() {
proxy_wasm::set_log_level(LogLevel::Trace);
proxy_wasm::set_root_context(|_| -> Box<dyn RootContext> {
Box::new(HttpConfigHeaderRootContext{
Box::new(HttpConfigHeaderRootContext {
header_content: "".to_string(),
})
});
}

struct HttpConfigHeader{
header_content: String
struct HttpConfigHeader {
header_content: String,
}

impl Context for HttpConfigHeader {}

impl HttpContext for HttpConfigHeader {

fn on_http_response_headers(&mut self, _num_headers: usize) -> Action {
self.add_http_response_header("custom-header", self.header_content.as_str());

Expand All @@ -42,13 +41,12 @@ impl HttpContext for HttpConfigHeader {
}

struct HttpConfigHeaderRootContext {
header_content: String
header_content: String,
}

impl Context for HttpConfigHeaderRootContext {}

impl RootContext for HttpConfigHeaderRootContext {

fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool {
if let Some(config_bytes) = self.get_configuration() {
self.header_content = str::from_utf8(config_bytes.as_ref()).unwrap().to_owned()
Expand All @@ -57,13 +55,12 @@ impl RootContext for HttpConfigHeaderRootContext {
}

fn create_http_context(&self, _context_id: u32) -> Option<Box<dyn HttpContext>> {
Some(Box::new(HttpConfigHeader{
Some(Box::new(HttpConfigHeader {
header_content: self.header_content.clone(),
}))
}

fn get_type(&self) -> Option<ContextType> {
Some(ContextType::HttpContext)
}

}
8 changes: 6 additions & 2 deletions src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ impl Dispatcher {
self.create_stream_context(context_id, root_context_id);
} else if let Some(root_context) = self.roots.borrow().get(&root_context_id) {
match root_context.get_type() {
Some(ContextType::HttpContext) => self.create_http_context(context_id, root_context_id),
Some(ContextType::StreamContext) => self.create_stream_context(context_id, root_context_id),
Some(ContextType::HttpContext) => {
self.create_http_context(context_id, root_context_id)
}
Some(ContextType::StreamContext) => {
self.create_stream_context(context_id, root_context_id)
}
None => panic!("missing ContextType on root_context"),
}
} else {
Expand Down

0 comments on commit 9756371

Please sign in to comment.