Skip to content

Commit 3850128

Browse files
committed
refactor: moved HeaderMap into MessageHead
1 parent 6fd2f1c commit 3850128

File tree

18 files changed

+147
-178
lines changed

18 files changed

+147
-178
lines changed

header-plz/src/body_headers/encoding_info.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::body_headers::content_encoding::ContentEncoding;
33
#[cfg_attr(any(test, debug_assertions), derive(Debug, PartialEq, Eq, Clone))]
44
pub struct EncodingInfo {
55
header_index: usize,
6-
pub encoding: ContentEncoding,
6+
encoding: ContentEncoding,
77
}
88

99
impl From<(usize, ContentEncoding)> for EncodingInfo {
@@ -23,6 +23,10 @@ impl EncodingInfo {
2323
}
2424
}
2525

26+
pub fn encoding(&self) -> &ContentEncoding {
27+
&self.encoding
28+
}
29+
2630
pub fn iter_from_str(index: usize, val: &str) -> impl Iterator<Item = EncodingInfo> {
2731
val.split(',')
2832
.map(str::trim)

header-plz/src/body_headers/from_header_map.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,7 @@
11
use mime_plz::ContentType;
22

33
use super::{BodyHeader, transfer_types::TransferType};
4-
use crate::{
5-
body_headers::encoding_info::EncodingInfo,
6-
const_headers::*,
7-
header_map::{HeaderMap, header::Header},
8-
};
9-
10-
/* Steps:
11-
* 3. If header.key "Content-Length", and if body_headers.transfer_type is
12-
* not set then convert content length to TransferType by calling
13-
* cl_to_transfer_type()
14-
*
15-
* 4. If header.key is "te" or "Transfer-Encoding",
16-
* a. build Vec<TransferEncoding> by calling match_compression() with
17-
* header.value_as_str().
18-
*
19-
* b. If chunked value is present, remove it and set transfer_type to
20-
* TansferType of chunked
21-
*
22-
* 5. If header.key is "ce" or "Content-Encoding", set
23-
* body_header.content_encoding to vec built by calling
24-
* match_compression() with header.value_as_str().
25-
*
26-
* 6. If header.key is "ct" or "Content-Type", split at "/" to get
27-
* main content type. Use From<&str> for ContentType to create
28-
* ContentType from string. Assign to body_header.content_type.
29-
*
30-
* 7. If TransferType is Unknown, and if content_encoding or
31-
* transfer_encoding or content_type is present, then set TransferType
32-
* to Close
33-
*
34-
* 8. Call sanitize() on BodyHeader to remove empty values.
35-
*/
4+
use crate::{Header, HeaderMap, body_headers::encoding_info::EncodingInfo, const_headers::*};
365

376
impl From<&HeaderMap> for Option<BodyHeader> {
387
fn from(header_map: &HeaderMap) -> Self {

header-plz/src/body_headers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl BodyHeader {
4141
.as_ref()
4242
.map(|list| {
4343
list.iter()
44-
.any(|ei| ei.encoding == ContentEncoding::Chunked)
44+
.any(|ei| *ei.encoding() == ContentEncoding::Chunked)
4545
})
4646
.unwrap_or(false)
4747
}

header-plz/src/body_headers/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use tracing::error;
22

33
use crate::{
4-
info_line::{request::Request, response::Response},
4+
Request, Response,
55
message_head::MessageHead,
66
methods::{METHODS_WITH_BODY, Method},
77
};

header-plz/src/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::info_line::error::InfoLineError;
21
use std::fmt::Debug;
32
use thiserror::Error;
43

4+
use crate::message_head::info_line::error::InfoLineError;
5+
56
#[derive(Debug, Error)]
67
pub enum HeaderReadError {
78
#[error("infoline| {0}")]

header-plz/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ pub mod abnf;
44
pub mod body_headers;
55
pub mod const_headers;
66
pub mod error;
7-
pub mod header_map;
8-
pub mod info_line;
97
pub mod message_head;
108
pub mod methods;
11-
pub mod reader;
9+
10+
pub use message_head::header_map::HeaderMap;
11+
pub use message_head::header_map::header::Header;
12+
pub use message_head::info_line::{request::Request, response::Response};
File renamed without changes.

header-plz/src/header_map/header/from_bytes.rs renamed to header-plz/src/message_head/header_map/header/from_bytes.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ pub fn find_header_fs(input: &str) -> usize {
1818

1919
/* Description:
2020
* Contains atleast CRLF.
21-
*
22-
* Steps:
23-
* 1. Find ": " index.
24-
* 2. If no ": " found, split at index 1 as atleast CRLF if
25-
* present.
26-
* 2. Split to key and value.
2721
*/
2822
impl From<BytesMut> for Header {
2923
fn from(mut input: BytesMut) -> Self {

header-plz/src/header_map/header/from_str.rs renamed to header-plz/src/message_head/header_map/header/from_str.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
use super::*;
22
use crate::{
33
abnf::{CRLF, HEADER_FS},
4-
header_map::header::from_bytes::find_header_fs,
4+
message_head::header_map::header::from_bytes::find_header_fs,
55
};
66

7-
/* Steps:
8-
* 1. Convert str to BytesMut
9-
* 2. Extend key with ": "
10-
* 3. Extend value with CRLF
11-
* 4. Return Header
12-
*/
13-
147
// (Content-Type, application/json)
158
impl From<(&str, &str)> for Header {
169
fn from((key, value): (&str, &str)) -> Self {
File renamed without changes.

0 commit comments

Comments
 (0)