| 1 | // Copyright (c) 2021 Parity Technologies (UK) Ltd. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 |
| 4 | // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
| 5 | // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. All files in the project carrying such notice may not be copied, |
| 7 | // modified, or distributed except according to those terms. |
| 8 | |
| 9 | /*! |
| 10 | This module somewhat mirrors [`crate::handshake::server`], except it's focus is on working |
| 11 | with [`http::Request`] and [`http::Response`] types, making it easier to integrate with |
| 12 | external web servers such as Hyper. |
| 13 | |
| 14 | See `examples/hyper_server.rs` from this crate's repository for example usage. |
| 15 | */ |
| 16 | |
| 17 | use superrust-analyzer cargo soketto 0.8.1 handshake/::{WebSocketKeyrust-analyzer cargo soketto 0.8.1 handshake/WebSocketKey#, SEC_WEBSOCKET_EXTENSIONSrust-analyzer cargo soketto 0.8.1 handshake/SEC_WEBSOCKET_EXTENSIONS.}; |
| 18 | use craterust-analyzer cargo soketto 0.8.1 crate/::connectionrust-analyzer cargo soketto 0.8.1 connection/::{selfrust-analyzer cargo soketto 0.8.1 connection/, Moderust-analyzer cargo soketto 0.8.1 connection/Mode#}; |
| 19 | use craterust-analyzer cargo soketto 0.8.1 crate/::extensionrust-analyzer cargo soketto 0.8.1 extension/::Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension#; |
| 20 | use craterust-analyzer cargo soketto 0.8.1 crate/::handshakerust-analyzer cargo soketto 0.8.1 handshake/; |
| 21 | use bytesrust-analyzer cargo bytes 1.12.1 crate/::BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#; |
| 22 | use futuresrust-analyzer cargo futures 0.3.34 crate/::preluderust-analyzer cargo futures 0.3.34 prelude/::*; |
| 23 | use httprust-analyzer cargo http 1.5.0 crate/::{headerrust-analyzer cargo http 1.5.0 header/, HeaderMaprust-analyzer cargo http 1.5.0 header/map/HeaderMap#, Responserust-analyzer cargo http 1.5.0 response/Response#}; |
| 24 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 25 | |
| 26 | /// A re-export of [`handshake::Error`]. |
| 27 | pub type Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error# = handshakerust-analyzer cargo soketto 0.8.1 handshake/::Errorrust-analyzer cargo soketto 0.8.1 handshake/Error#; |
| 28 | |
| 29 | /// Websocket handshake server. This is similar to [`handshake::Server`], but it is |
| 30 | /// focused on performing the WebSocket handshake using a provided [`http::Request`], as opposed |
| 31 | /// to decoding the request internally. |
| 32 | pub struct Serverrust-analyzer cargo soketto 0.8.1 handshake/http/Server# { |
| 33 | // Extensions the server supports. |
| 34 | extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>>, |
| 35 | // Encoding/decoding buffer. |
| 36 | bufferrust-analyzer cargo soketto 0.8.1 handshake/http/Server#buffer.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#, |
| 37 | } |
| 38 | |
| 39 | impl Serverrust-analyzer cargo soketto 0.8.1 handshake/http/Server# { |
| 40 | /// Create a new server handshake. |
| 41 | pub fn newrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]new().() -> Selfrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server] { |
| 42 | Serverrust-analyzer cargo soketto 0.8.1 handshake/http/Server# { extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), bufferrust-analyzer cargo soketto 0.8.1 handshake/http/Server#buffer.: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::newrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]new().() } |
| 43 | } |
| 44 | |
| 45 | /// Override the buffer to use for request/response handling. |
| 46 | pub fn set_bufferrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]set_buffer().(&mut self, b: BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#) -> &mut Selfrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server] { |
| 47 | self.bufferrust-analyzer cargo soketto 0.8.1 handshake/http/Server#buffer. = b; |
| 48 | self |
| 49 | } |
| 50 | |
| 51 | /// Extract the buffer. |
| 52 | pub fn take_bufferrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]take_buffer().(&mut self) -> BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut# { |
| 53 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.bufferrust-analyzer cargo soketto 0.8.1 handshake/http/Server#buffer.) |
| 54 | } |
| 55 | |
| 56 | /// Add an extension the server supports. |
| 57 | pub fn add_extensionrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]add_extension().(&mut self, e: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>) -> &mut Selfrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server] { |
| 58 | self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(e); |
| 59 | self |
| 60 | } |
| 61 | |
| 62 | /// Get back all extensions. |
| 63 | pub fn drain_extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]drain_extensions().(&mut self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>> + '_ { |
| 64 | self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#) |
| 65 | } |
| 66 | |
| 67 | /// Attempt to interpret the provided [`http::Request`] as a WebSocket Upgrade request. If successful, this |
| 68 | /// returns an [`http::Response`] that should be returned to the client to complete the handshake. |
| 69 | pub fn receive_requestrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]receive_request().<B>(&mut self, req: &httprust-analyzer cargo http 1.5.0 crate/::Requestrust-analyzer cargo http 1.5.0 request/Request#<B>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<httprust-analyzer cargo http 1.5.0 crate/::Responserust-analyzer cargo http 1.5.0 response/Response#<()>, Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#> { |
| 70 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_upgrade_requestrust-analyzer cargo soketto 0.8.1 handshake/http/is_upgrade_request().(&req) { |
| 71 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#::InvalidSecWebSocketAcceptrust-analyzer cargo soketto 0.8.1 handshake/Error#InvalidSecWebSocketAccept#); |
| 72 | } |
| 73 | |
| 74 | let key = match req.headersrust-analyzer cargo http 1.5.0 request/impl#[`Request<T>`]headers().().getrust-analyzer cargo http 1.5.0 header/map/impl#[`HeaderMap<T>`]get().("Sec-WebSocket-Key") { |
| 75 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(key) => key, |
| 76 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 77 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#::HeaderNotFoundrust-analyzer cargo soketto 0.8.1 handshake/Error#HeaderNotFound#("Sec-WebSocket-Key".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | if req.headersrust-analyzer cargo http 1.5.0 request/impl#[`Request<T>`]headers().().getrust-analyzer cargo http 1.5.0 header/map/impl#[`HeaderMap<T>`]get().("Sec-WebSocket-Version").maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|v| v.as_bytesrust-analyzer cargo http 1.5.0 header/value/impl#[HeaderValue]as_bytes().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b"13") { |
| 82 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#::HeaderNotFoundrust-analyzer cargo soketto 0.8.1 handshake/Error#HeaderNotFound#("Sec-WebSocket-Version".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 83 | } |
| 84 | |
| 85 | // Pull out the Sec-WebSocket-Key and generate the appropriate response to it. |
| 86 | let key: &WebSocketKeyrust-analyzer cargo soketto 0.8.1 handshake/WebSocketKey# = match key.as_bytesrust-analyzer cargo http 1.5.0 header/value/impl#[HeaderValue]as_bytes().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().() { |
| 87 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(key) => key, |
| 88 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#::InvalidSecWebSocketAcceptrust-analyzer cargo soketto 0.8.1 handshake/Error#InvalidSecWebSocketAccept#), |
| 89 | }; |
| 90 | let accept_key = handshakerust-analyzer cargo soketto 0.8.1 handshake/::generate_accept_keyrust-analyzer cargo soketto 0.8.1 handshake/generate_accept_key().(key); |
| 91 | |
| 92 | // Get extension information out of the request as we'll need this as well. |
| 93 | let extension_config = req |
| 94 | .headersrust-analyzer cargo http 1.5.0 request/impl#[`Request<T>`]headers().() |
| 95 | .iterrust-analyzer cargo http 1.5.0 header/map/impl#[`HeaderMap<T>`]iter().() |
| 96 | .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|&(name, _)| name.as_strrust-analyzer cargo http 1.5.0 header/name/impl#[HeaderName]as_str().().eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]eq_ignore_ascii_case().(SEC_WEBSOCKET_EXTENSIONSrust-analyzer cargo soketto 0.8.1 handshake/SEC_WEBSOCKET_EXTENSIONS.)) |
| 97 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(_, value)| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(value.as_bytesrust-analyzer cargo http 1.5.0 header/value/impl#[HeaderValue]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())) |
| 98 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>, Errorrust-analyzer cargo soketto 0.8.1 handshake/http/Error#>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 99 | |
| 100 | // Attempt to set the extension configuration params that the client requested. |
| 101 | for config_str in &extension_config { |
| 102 | handshakerust-analyzer cargo soketto 0.8.1 handshake/::configure_extensionsrust-analyzer cargo soketto 0.8.1 handshake/configure_extensions().(&mut self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions., &config_str)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 103 | } |
| 104 | |
| 105 | // Build a response that should be sent back to the client to acknowledge the upgrade. |
| 106 | let mut response = Responserust-analyzer cargo http 1.5.0 response/Response#::builderrust-analyzer cargo http 1.5.0 response/impl#[`Response<()>`]builder().() |
| 107 | .statusrust-analyzer cargo http 1.5.0 response/impl#[Builder]status().(httprust-analyzer cargo http 1.5.0 crate/::StatusCoderust-analyzer cargo http 1.5.0 status/StatusCode#::SWITCHING_PROTOCOLSrust-analyzer cargo http 1.5.0 status/impl#[StatusCode]SWITCHING_PROTOCOLS.) |
| 108 | .headerrust-analyzer cargo http 1.5.0 response/impl#[Builder]header().(httprust-analyzer cargo http 1.5.0 crate/::headerrust-analyzer cargo http 1.5.0 header/::CONNECTIONrust-analyzer cargo http 1.5.0 header/name/CONNECTION., "upgrade") |
| 109 | .headerrust-analyzer cargo http 1.5.0 response/impl#[Builder]header().(httprust-analyzer cargo http 1.5.0 crate/::headerrust-analyzer cargo http 1.5.0 header/::UPGRADErust-analyzer cargo http 1.5.0 header/name/UPGRADE., "websocket") |
| 110 | .headerrust-analyzer cargo http 1.5.0 response/impl#[Builder]header().("Sec-WebSocket-Accept", &accept_key[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().); |
| 111 | |
| 112 | // Tell the client about the agreed-upon extension configuration. We reuse code to build up the |
| 113 | // extension header value, but that does make this a little more clunky. |
| 114 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 115 | let mut buf = bytesrust-analyzer cargo bytes 1.12.1 crate/::BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#::newrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]new().(); |
| 116 | let enabled_extensions = self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|e| e.is_enabledrust-analyzer cargo soketto 0.8.1 extension/impl#[`Box<E>`][Extension]is_enabled().()).peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(); |
| 117 | handshakerust-analyzer cargo soketto 0.8.1 handshake/::append_extension_header_valuerust-analyzer cargo soketto 0.8.1 handshake/append_extension_header_value().(enabled_extensions, &mut buf); |
| 118 | response = response.headerrust-analyzer cargo http 1.5.0 response/impl#[Builder]header().("Sec-WebSocket-Extensions", buf.as_refrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut][`AsRef<[u8]>`]as_ref().()); |
| 119 | } |
| 120 | |
| 121 | let response = response.bodyrust-analyzer cargo http 1.5.0 response/impl#[Builder]body().(()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("bug: failed to build response"); |
| 122 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(response) |
| 123 | } |
| 124 | |
| 125 | /// Turn this handshake into a [`connection::Builder`]. |
| 126 | pub fn into_builderrust-analyzer cargo soketto 0.8.1 handshake/http/impl#[Server]into_builder().<T: AsyncReadrust-analyzer cargo futures-io 0.3.34 if_std/AsyncRead# + AsyncWriterust-analyzer cargo futures-io 0.3.34 if_std/AsyncWrite# + Unpinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Unpin#>(mut self, socket: T) -> connectionrust-analyzer cargo soketto 0.8.1 connection/::Builderrust-analyzer cargo soketto 0.8.1 connection/Builder#<T> { |
| 127 | let mut builder = connectionrust-analyzer cargo soketto 0.8.1 connection/::Builderrust-analyzer cargo soketto 0.8.1 connection/Builder#::newrust-analyzer cargo soketto 0.8.1 connection/impl#[`Builder<T>`]new().(socket, Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Serverrust-analyzer cargo soketto 0.8.1 connection/Mode#Server#); |
| 128 | builder.set_bufferrust-analyzer cargo soketto 0.8.1 connection/impl#[`Builder<T>`]set_buffer().(self.bufferrust-analyzer cargo soketto 0.8.1 handshake/http/Server#buffer.); |
| 129 | builder.add_extensionsrust-analyzer cargo soketto 0.8.1 connection/impl#[`Builder<T>`]add_extensions().(self.extensionsrust-analyzer cargo soketto 0.8.1 handshake/http/Server#extensions..drainrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#)); |
| 130 | builder |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | /// Check if an [`http::Request`] looks like a valid websocket upgrade request. |
| 135 | pub fn is_upgrade_requestrust-analyzer cargo soketto 0.8.1 handshake/http/is_upgrade_request().<B>(request: &httprust-analyzer cargo http 1.5.0 crate/::Requestrust-analyzer cargo http 1.5.0 request/Request#<B>) -> bool { |
| 136 | header_contains_valuerust-analyzer cargo soketto 0.8.1 handshake/http/header_contains_value().(request.headersrust-analyzer cargo http 1.5.0 request/impl#[`Request<T>`]headers().(), headerrust-analyzer cargo http 1.5.0 header/::CONNECTIONrust-analyzer cargo http 1.5.0 header/name/CONNECTION., b"upgrade") |
| 137 | && header_contains_valuerust-analyzer cargo soketto 0.8.1 handshake/http/header_contains_value().(request.headersrust-analyzer cargo http 1.5.0 request/impl#[`Request<T>`]headers().(), headerrust-analyzer cargo http 1.5.0 header/::UPGRADErust-analyzer cargo http 1.5.0 header/name/UPGRADE., b"websocket") |
| 138 | } |
| 139 | |
| 140 | // Check if there is a header of the given name containing the wanted value. |
| 141 | fn header_contains_valuerust-analyzer cargo soketto 0.8.1 handshake/http/header_contains_value().(headers: &HeaderMaprust-analyzer cargo http 1.5.0 header/map/HeaderMap#, header: headerrust-analyzer cargo http 1.5.0 header/::HeaderNamerust-analyzer cargo http 1.5.0 header/name/HeaderName#, value: &[u8]) -> bool { |
| 142 | pub fn trimrust-analyzer cargo soketto 0.8.1 handshake/http/trim().(x: &[u8]) -> &[u8] { |
| 143 | let from = match x.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|x| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().x.is_ascii_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_whitespace().()) { |
| 144 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i) => i, |
| 145 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return &[], |
| 146 | }; |
| 147 | let to = x.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().rpositionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]rposition().(|x| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().x.is_ascii_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_whitespace().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 148 | &x[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().from..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#to]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 149 | } |
| 150 | |
| 151 | for header in headers.get_allrust-analyzer cargo http 1.5.0 header/map/impl#[`HeaderMap<T>`]get_all().(header) { |
| 152 | if header.as_bytesrust-analyzer cargo http 1.5.0 header/value/impl#[HeaderValue]as_bytes().().splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split().(|&c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b',').anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|x| trimrust-analyzer cargo soketto 0.8.1 handshake/http/trim().(x).eq_ignore_ascii_caserust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/ascii/impl#[`[u8]`]eq_ignore_ascii_case().(value)) { |
| 153 | return true; |
| 154 | } |
| 155 | } |
| 156 | false |
| 157 | } |