forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement(http_server source): Configurable http response code (vec…
…tordotdev#18208) * make http response code customizable for http-server source * fix tests * update docs * Apply suggestions from code review Co-authored-by: neuronull <neuronull@pm.me> * update generated docs * add unit test * fix clippy errors * update licenses * fix cue --------- Co-authored-by: neuronull <neuronull@pm.me>
- Loading branch information
1 parent
a6262cd
commit afdc66e
Showing
12 changed files
with
146 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,35 @@ | ||
use http::StatusCode; | ||
use serde_json::Value; | ||
use std::cell::RefCell; | ||
|
||
use crate::{ | ||
schema::{generate_number_schema, SchemaGenerator, SchemaObject}, | ||
Configurable, GenerateError, Metadata, ToValue, | ||
}; | ||
|
||
impl ToValue for StatusCode { | ||
fn to_value(&self) -> Value { | ||
serde_json::to_value(self.as_u16()).expect("Could not convert HTTP status code to JSON") | ||
} | ||
} | ||
|
||
impl Configurable for StatusCode { | ||
fn referenceable_name() -> Option<&'static str> { | ||
Some("http::StatusCode") | ||
} | ||
|
||
fn is_optional() -> bool { | ||
true | ||
} | ||
|
||
fn metadata() -> Metadata { | ||
let mut metadata = Metadata::default(); | ||
metadata.set_description("HTTP response status code"); | ||
metadata.set_default_value(StatusCode::OK); | ||
metadata | ||
} | ||
|
||
fn generate_schema(_: &RefCell<SchemaGenerator>) -> Result<SchemaObject, GenerateError> { | ||
Ok(generate_number_schema::<u16>()) | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.