headers_ext/common/
content_location.rs

1use ::HeaderValue;
2
3/// `Content-Location` header, defined in
4/// [RFC7231](https://tools.ietf.org/html/rfc7231#section-3.1.4.2)
5///
6/// The header can be used by both the client in requests and the server
7/// in responses with different semantics. Client sets `Content-Location`
8/// to refer to the URI where original representation of the body was
9/// obtained.
10///
11/// In responses `Content-Location` represents URI for the representation
12/// that was content negotiated, created or for the response payload.
13///
14/// # ABNF
15///
16/// ```text
17/// Content-Location = absolute-URI / partial-URI
18/// ```
19///
20/// # Example values
21///
22/// * `/hypertext/Overview.html`
23/// * `http://www.example.org/hypertext/Overview.html`
24///
25/// # Examples
26///
27//TODO: make this a `Uri`?
28#[derive(Clone, Debug, PartialEq, Header)]
29pub struct ContentLocation(HeaderValue);
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34    use super::super::test_decode;
35
36    #[test]
37    fn absolute_uri() {
38        let s = "http://www.example.net/index.html";
39        let loc = test_decode::<ContentLocation>(&[s]).unwrap();
40
41        assert_eq!(loc, ContentLocation(HeaderValue::from_static(s)));
42    }
43
44    #[test]
45    fn relative_uri_with_fragment() {
46        let s = "/People.html#tim";
47        let loc = test_decode::<ContentLocation>(&[s]).unwrap();
48
49        assert_eq!(loc, ContentLocation(HeaderValue::from_static(s)));
50    }
51}