Skip to main content

feedparser_rs/http/
response.rs

1use std::collections::HashMap;
2
3/// HTTP response from feed fetch
4#[derive(Debug, Clone)]
5#[non_exhaustive]
6pub struct FeedHttpResponse {
7    /// HTTP status code
8    pub status: u16,
9    /// Final URL after redirects
10    pub url: String,
11    /// Response headers
12    pub headers: HashMap<String, String>,
13    /// Response body
14    pub body: Vec<u8>,
15    /// `ETag` header value
16    pub etag: Option<String>,
17    /// Last-Modified header value
18    pub last_modified: Option<String>,
19    /// Content-Type header value
20    pub content_type: Option<String>,
21}
22
23impl FeedHttpResponse {
24    /// Creates a response for `status` and the final `url`, with no headers or body.
25    ///
26    /// # Examples
27    ///
28    /// ```
29    /// use feedparser_rs::http::FeedHttpResponse;
30    ///
31    /// let response = FeedHttpResponse::new(200, "https://example.com/feed.xml");
32    /// assert!(response.body.is_empty());
33    /// ```
34    #[must_use]
35    pub fn new(status: u16, url: impl Into<String>) -> Self {
36        Self {
37            status,
38            url: url.into(),
39            headers: HashMap::new(),
40            body: Vec::new(),
41            etag: None,
42            last_modified: None,
43            content_type: None,
44        }
45    }
46}