Skip to content

Commit 6222389

Browse files
committed
Fixes
1 parent 7a4d461 commit 6222389

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

my-http-server-core/src/http_ok_result/http_ok_result.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use crate::{cookies::*, HttpFailResult, HttpOkResultBuilder, WebContentType};
3+
use crate::{cookies::*, HttpFailResult, HttpResultBuilder, WebContentType};
44
use hyper::Response;
55
use my_hyper_utils::*;
66
use rust_extensions::StrOrString;
@@ -31,8 +31,8 @@ pub enum HttpOutput {
3131
}
3232

3333
impl HttpOutput {
34-
pub fn from_builder() -> HttpOkResultBuilder {
35-
HttpOkResultBuilder::new()
34+
pub fn from_builder() -> HttpResultBuilder {
35+
HttpResultBuilder::new()
3636
}
3737

3838
pub fn into_ok_result(self, write_telemetry: bool) -> Result<HttpOkResult, HttpFailResult> {
@@ -151,32 +151,32 @@ impl HttpOutput {
151151
Err(result)
152152
}
153153

154-
pub fn as_text<'s>(text: impl Into<StrOrString<'s>>) -> HttpOkResultBuilder {
154+
pub fn as_text<'s>(text: impl Into<StrOrString<'s>>) -> HttpResultBuilder {
155155
let text = text.into().to_string();
156156

157-
HttpOkResultBuilder {
157+
HttpResultBuilder {
158158
headers: None,
159159
content_type: Some(WebContentType::Text),
160160
cookies: Default::default(),
161161
body: text.into_bytes(),
162162
}
163163
}
164164

165-
pub fn as_json<T: Serialize>(model: T) -> HttpOkResultBuilder {
165+
pub fn as_json<T: Serialize>(model: T) -> HttpResultBuilder {
166166
let json = serde_json::to_vec(&model).unwrap();
167167

168-
HttpOkResultBuilder {
168+
HttpResultBuilder {
169169
headers: None,
170170
content_type: Some(WebContentType::Json),
171171
cookies: Default::default(),
172172
body: json,
173173
}
174174
}
175175

176-
pub fn as_yaml<T: Serialize>(model: T) -> HttpOkResultBuilder {
176+
pub fn as_yaml<T: Serialize>(model: T) -> HttpResultBuilder {
177177
let yaml = serde_yaml::to_string(&model).unwrap();
178178

179-
HttpOkResultBuilder {
179+
HttpResultBuilder {
180180
headers: None,
181181
content_type: Some(WebContentType::Yaml),
182182
cookies: Default::default(),

my-http-server-core/src/http_ok_result/http_ok_result_builder.rs renamed to my-http-server-core/src/http_ok_result/http_result_builder.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use crate::{cookies::*, HttpFailResult, HttpOutput, WebContentType};
66

77
use super::HttpOkResult;
88

9-
pub struct HttpOkResultBuilder {
9+
pub struct HttpResultBuilder {
1010
pub(crate) headers: Option<HashMap<String, String>>,
1111
pub(crate) content_type: Option<WebContentType>,
1212
pub(crate) cookies: Option<CookieJar>,
1313
pub(crate) body: Vec<u8>,
1414
}
1515

16-
impl HttpOkResultBuilder {
16+
impl HttpResultBuilder {
1717
pub fn new() -> Self {
1818
Self {
1919
headers: None,
@@ -111,4 +111,19 @@ impl HttpOkResultBuilder {
111111
content,
112112
}
113113
}
114+
115+
pub fn into_fail_result(
116+
self,
117+
status_code: u16,
118+
write_telemetry: bool,
119+
) -> Result<HttpOkResult, HttpFailResult> {
120+
HttpFailResult {
121+
content_type: self.content_type.unwrap_or(WebContentType::Text),
122+
status_code,
123+
content: self.body,
124+
write_telemetry,
125+
write_to_log: true,
126+
}
127+
.into()
128+
}
114129
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod http_ok_result_builder;
2-
pub use http_ok_result_builder::*;
1+
mod http_result_builder;
2+
pub use http_result_builder::*;
33

44
mod http_ok_result;
55
pub use http_ok_result::*;

0 commit comments

Comments
 (0)