| 1 | use craterust-analyzer cargo railway-core 0.3.0 crate/::{Requesterrust-analyzer cargo railway-core 0.3.0 requester/Requester#, RequesterBuilderrust-analyzer cargo railway-core 0.3.0 requester/RequesterBuilder#}; |
| 2 | use async_traitrust-analyzer cargo async-trait 0.1.85 crate/::async_traitrust-analyzer cargo async-trait 0.1.85 async_trait:; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#; |
| 4 | |
| 5 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 6 | pub struct ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester#(reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Clientrust-analyzer cargo reqwest 0.12.12 async_impl/client/Client#); |
| 7 | |
| 8 | impl ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester# { |
| 9 | pub fn innerrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]inner().(&self) -> &reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Clientrust-analyzer cargo reqwest 0.12.12 async_impl/client/Client# { |
| 10 | &self.0rust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester#0. |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | #[cfg_attr(feature = "rt-multi-thread", async_trait)] |
| 15 | #[cfg_attr(not(feature = "rt-multi-thread"), async_trait(?Send))] |
| 16 | impl Requesterrust-analyzer cargo railway-core 0.3.0 requester/Requester# for ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester# { |
| 17 | type Errorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Requester]Error# = ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#; |
| 18 | |
| 19 | async fn getrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Requester]get().( |
| 20 | &self, |
| 21 | url: &urlrust-analyzer cargo url 2.5.7 crate/::Urlrust-analyzer cargo url 2.5.7 Url#, |
| 22 | body: &[u8], |
| 23 | headers: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&str, &str>, |
| 24 | ) -> 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#<u8>, Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Requester]::Errorrust-analyzer cargo railway-core 0.3.0 requester/Requester#Error#> { |
| 25 | selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/.requestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]request().(reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Methodrust-analyzer cargo http 1.3.1 method/Method#::GETrust-analyzer cargo http 1.3.1 method/impl#[Method]GET., url, body, headers).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll(). |
| 26 | } |
| 27 | |
| 28 | async fn postrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Requester]post().( |
| 29 | &self, |
| 30 | url: &urlrust-analyzer cargo url 2.5.7 crate/::Urlrust-analyzer cargo url 2.5.7 Url#, |
| 31 | body: &[u8], |
| 32 | headers: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&str, &str>, |
| 33 | ) -> 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#<u8>, Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Requester]::Errorrust-analyzer cargo railway-core 0.3.0 requester/Requester#Error#> { |
| 34 | selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/.requestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]request().(reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Methodrust-analyzer cargo http 1.3.1 method/Method#::POSTrust-analyzer cargo http 1.3.1 method/impl#[Method]POST., url, body, headers) |
| 35 | .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll(). |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | pub struct ReqwestRequesterBuilderrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder#(reqwestrust-analyzer cargo reqwest 0.12.12 crate/::ClientBuilderrust-analyzer cargo reqwest 0.12.12 async_impl/client/ClientBuilder#); |
| 40 | |
| 41 | impl RequesterBuilderrust-analyzer cargo railway-core 0.3.0 requester/RequesterBuilder# for ReqwestRequesterBuilderrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder# { |
| 42 | type Requesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][RequesterBuilder]Requester# = ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester#; |
| 43 | |
| 44 | fn with_pem_bundlerust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][RequesterBuilder]with_pem_bundle().(mut self, bytes: &[u8]) -> Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][RequesterBuilder] { |
| 45 | // TODO: Error when certificate parsing failed? |
| 46 | let certificates = reqwestrust-analyzer cargo reqwest 0.12.12 crate/::tlsrust-analyzer cargo reqwest 0.12.12 tls/::Certificaterust-analyzer cargo reqwest 0.12.12 tls/Certificate#::from_pem_bundlerust-analyzer cargo reqwest 0.12.12 tls/impl#[Certificate]from_pem_bundle().(bytes).unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().(); |
| 47 | for c in certificates { |
| 48 | self.0rust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder#0. = self.0rust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder#0..add_root_certificaterust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[ClientBuilder]add_root_certificate().(c); |
| 49 | } |
| 50 | self |
| 51 | } |
| 52 | |
| 53 | fn buildrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][RequesterBuilder]build().(self) -> Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][RequesterBuilder]::Requesterrust-analyzer cargo railway-core 0.3.0 requester/RequesterBuilder#Requester# { |
| 54 | // TODO: Fail when not able to build? |
| 55 | ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester#(self.0rust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder#0..buildrust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[ClientBuilder]build().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_default().()) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ReqwestRequesterBuilderrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterBuilder# { |
| 60 | fn defaultrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][Default]default().() -> Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][Default] { |
| 61 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterBuilder][Default](reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Clientrust-analyzer cargo reqwest 0.12.12 async_impl/client/Client#::builderrust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[Client]builder().()) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | impl ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester# { |
| 66 | pub fn newrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]new().() -> Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester] { |
| 67 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester](reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Clientrust-analyzer cargo reqwest 0.12.12 async_impl/client/Client#::newrust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[Client]new().()) |
| 68 | } |
| 69 | |
| 70 | async fn requestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]request().( |
| 71 | &self, |
| 72 | method: reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Methodrust-analyzer cargo http 1.3.1 method/Method#, |
| 73 | url: &urlrust-analyzer cargo url 2.5.7 crate/::Urlrust-analyzer cargo url 2.5.7 Url#, |
| 74 | body: &[u8], |
| 75 | headers: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<&str, &str>, |
| 76 | ) -> 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#<u8>, ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#> { |
| 77 | logrust-analyzer cargo log 0.4.28 crate/::tracerust-analyzer cargo log 0.4.28 macros/trace!!( |
| 78 | "{}: URL: {}, Body: {}, Headers: {:?}", |
| 79 | method, |
| 80 | url, |
| 81 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(body), |
| 82 | headers |
| 83 | ); |
| 84 | let body = body.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(); |
| 85 | // TODO: Fail on parsing header. |
| 86 | let mut req = self.0rust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester#0..requestrust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[Client]request().(method, url.clonerust-analyzer cargo url 2.5.7 impl#[Url][Clone]clone().()).bodyrust-analyzer cargo reqwest 0.12.12 async_impl/request/impl#[RequestBuilder]body().(body); |
| 87 | |
| 88 | for (key, value) in headers { |
| 89 | req = req.headerrust-analyzer cargo reqwest 0.12.12 async_impl/request/impl#[RequestBuilder]header().(key, value); |
| 90 | } |
| 91 | |
| 92 | let response = req.sendrust-analyzer cargo reqwest 0.12.12 async_impl/request/impl#[RequestBuilder]send().().rust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[Pending][Future]poll().awaitrust-analyzer cargo reqwest 0.12.12 async_impl/client/impl#[Pending][Future]poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 93 | |
| 94 | let status = response.statusrust-analyzer cargo reqwest 0.12.12 async_impl/response/impl#[Response]status().(); |
| 95 | let bytes = response.bytesrust-analyzer cargo reqwest 0.12.12 async_impl/response/impl#[Response]bytes().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 96 | |
| 97 | if status.is_successrust-analyzer cargo http 1.3.1 status/impl#[StatusCode]is_success().() { |
| 98 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()) |
| 99 | } else { |
| 100 | logrust-analyzer cargo log 0.4.28 crate/::errorrust-analyzer cargo log 0.4.28 macros/error!!( |
| 101 | "Request was not successfull; returned body: {}", |
| 102 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&bytes) |
| 103 | ); |
| 104 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#::NoSuccessStatusCoderust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#NoSuccessStatusCode#( |
| 105 | status.as_u16rust-analyzer cargo http 1.3.1 status/impl#[StatusCode]as_u16().(), |
| 106 | status.canonical_reasonrust-analyzer cargo http 1.3.1 status/impl#[StatusCode]canonical_reason().(), |
| 107 | bytes.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().(), |
| 108 | )) |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ReqwestRequesterrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequester# { |
| 114 | fn defaultrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Default]default().() -> Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Default] { |
| 115 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester][Default]::newrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequester]new().() |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 120 | pub enum ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError# { |
| 121 | /// reqwest failed. |
| 122 | Reqwestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#Reqwest#(reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Errorrust-analyzer cargo reqwest 0.12.12 error/Error#), |
| 123 | /// Got a status code which is no success. |
| 124 | /// Contains the status code, the "canonical reason" and the body bytes. |
| 125 | NoSuccessStatusCoderust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#NoSuccessStatusCode#(u16, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static str>, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>), |
| 126 | } |
| 127 | |
| 128 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError# { |
| 129 | fn fmtrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][Display]fmt().(&self, fmt: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 130 | match self { |
| 131 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][Display]::Reqwestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#Reqwest#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(fmt, "reqwest error: {}", e), |
| 132 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][Display]::NoSuccessStatusCoderust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#NoSuccessStatusCode#(code, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reason), _) => { |
| 133 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(fmt, "unsuccessful status code {} ({})", code, reason) |
| 134 | } |
| 135 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][Display]::NoSuccessStatusCoderust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#NoSuccessStatusCode#(code, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, _) => { |
| 136 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(fmt, "unsuccessful status code {}", code) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError# {} |
| 143 | |
| 144 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Errorrust-analyzer cargo reqwest 0.12.12 error/Error#> for ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError# { |
| 145 | fn fromrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][`From<reqwest::Error>`]from().(e: reqwestrust-analyzer cargo reqwest 0.12.12 crate/::Errorrust-analyzer cargo reqwest 0.12.12 error/Error#) -> ReqwestRequesterErrorrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError# { |
| 146 | Selfrust-analyzer cargo railway-core 0.3.0 requester/reqwest/impl#[ReqwestRequesterError][`From<reqwest::Error>`]::Reqwestrust-analyzer cargo railway-core 0.3.0 requester/reqwest/ReqwestRequesterError#Reqwest#(e) |
| 147 | } |
| 148 | } |