1#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct HeadObject;
6impl HeadObject {
7 pub fn new() -> Self {
9 Self
10 }
11 pub(crate) async fn orchestrate(
12 runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
13 input: crate::operation::head_object::HeadObjectInput,
14 ) -> ::std::result::Result<
15 crate::operation::head_object::HeadObjectOutput,
16 ::aws_smithy_runtime_api::client::result::SdkError<
17 crate::operation::head_object::HeadObjectError,
18 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
19 >,
20 > {
21 let map_err = |err: ::aws_smithy_runtime_api::client::result::SdkError<
22 ::aws_smithy_runtime_api::client::interceptors::context::Error,
23 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
24 >| {
25 err.map_service_error(|err| {
26 err.downcast::<crate::operation::head_object::HeadObjectError>()
27 .expect("correct error type")
28 })
29 };
30 let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
31 .await
32 .map_err(map_err)?;
33 let output = context.finalize().map_err(map_err)?;
34 ::std::result::Result::Ok(
35 output
36 .downcast::<crate::operation::head_object::HeadObjectOutput>()
37 .expect("correct output type"),
38 )
39 }
40
41 pub(crate) async fn orchestrate_with_stop_point(
42 runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
43 input: crate::operation::head_object::HeadObjectInput,
44 stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
45 ) -> ::std::result::Result<
46 ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
47 ::aws_smithy_runtime_api::client::result::SdkError<
48 ::aws_smithy_runtime_api::client::interceptors::context::Error,
49 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
50 >,
51 > {
52 let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
53 ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("s3", "HeadObject", input, runtime_plugins, stop_point).await
54 }
55
56 pub(crate) fn operation_runtime_plugins(
57 client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
58 client_config: &crate::config::Config,
59 config_override: ::std::option::Option<crate::config::Builder>,
60 ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
61 let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
62 runtime_plugins = runtime_plugins.with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
63 ::aws_runtime::auth::sigv4::SCHEME_ID,
64 #[cfg(feature = "sigv4a")]
65 {
66 ::aws_runtime::auth::sigv4a::SCHEME_ID
67 },
68 crate::s3_express::auth::SCHEME_ID,
69 ::aws_smithy_runtime::client::auth::no_auth::NO_AUTH_SCHEME_ID,
70 ]));
71 if let ::std::option::Option::Some(config_override) = config_override {
72 for plugin in config_override.runtime_plugins.iter().cloned() {
73 runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
74 }
75 runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
76 config_override,
77 client_config.config.clone(),
78 &client_config.runtime_components,
79 ));
80 }
81 runtime_plugins
82 }
83}
84impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for HeadObject {
85 fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
86 let mut cfg = ::aws_smithy_types::config_bag::Layer::new("HeadObject");
87
88 cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
89 HeadObjectRequestSerializer,
90 ));
91 cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
92 HeadObjectResponseDeserializer,
93 ));
94
95 cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
96 ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolverParams::new(),
97 ));
98
99 cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::SensitiveOutput);
100 cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new("HeadObject", "s3"));
101 let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
102 signing_options.double_uri_encode = false;
103 signing_options.content_sha256_header = true;
104 signing_options.normalize_uri_path = false;
105 signing_options.payload_override = None;
106
107 cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
108 signing_options,
109 ..::std::default::Default::default()
110 });
111
112 ::std::option::Option::Some(cfg.freeze())
113 }
114
115 fn runtime_components(
116 &self,
117 _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
118 ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
119 #[allow(unused_mut)]
120 let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("HeadObject")
121 .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
122 .with_interceptor(HeadObjectEndpointParamsInterceptor)
123 .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
124 crate::operation::head_object::HeadObjectError,
125 >::new())
126 .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
127 crate::operation::head_object::HeadObjectError,
128 >::new())
129 .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
130 crate::operation::head_object::HeadObjectError,
131 >::new());
132
133 ::std::borrow::Cow::Owned(rcb)
134 }
135}
136
137#[derive(Debug)]
138struct HeadObjectResponseDeserializer;
139impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for HeadObjectResponseDeserializer {
140 fn deserialize_nonstreaming(
141 &self,
142 response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
143 ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
144 let (success, status) = (response.status().is_success(), response.status().as_u16());
145 let headers = response.headers();
146 let body = response.body().bytes().expect("body loaded");
147 #[allow(unused_mut)]
148 let mut force_error = false;
149 ::tracing::debug!(extended_request_id = ?crate::s3_request_id::RequestIdExt::extended_request_id(response));
150 if matches!(crate::rest_xml_unwrapped_errors::body_is_error(body), Ok(true)) {
151 force_error = true;
152 }
153 ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
154 let parse_result = if !success && status != 200 || force_error {
155 crate::protocol_serde::shape_head_object::de_head_object_http_error(status, headers, body)
156 } else {
157 crate::protocol_serde::shape_head_object::de_head_object_http_response(status, headers, body)
158 };
159 crate::protocol_serde::type_erase_result(parse_result)
160 }
161}
162#[derive(Debug)]
163struct HeadObjectRequestSerializer;
164impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for HeadObjectRequestSerializer {
165 #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
166 fn serialize_input(
167 &self,
168 input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
169 _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
170 ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
171 let input = input.downcast::<crate::operation::head_object::HeadObjectInput>().expect("correct type");
172 let _header_serialization_settings = _cfg
173 .load::<crate::serialization_settings::HeaderSerializationSettings>()
174 .cloned()
175 .unwrap_or_default();
176 let mut request_builder = {
177 fn uri_base(
178 _input: &crate::operation::head_object::HeadObjectInput,
179 output: &mut ::std::string::String,
180 ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
181 use ::std::fmt::Write as _;
182 let input_1 = &_input.key;
183 let input_1 = input_1
184 .as_ref()
185 .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("key", "cannot be empty or unset"))?;
186 let key = ::aws_smithy_http::label::fmt_string(input_1, ::aws_smithy_http::label::EncodingStrategy::Greedy);
187 if key.is_empty() {
188 return ::std::result::Result::Err(::aws_smithy_types::error::operation::BuildError::missing_field(
189 "key",
190 "cannot be empty or unset",
191 ));
192 }
193 ::std::write!(output, "/{Key}", Key = key).expect("formatting should succeed");
194 ::std::result::Result::Ok(())
195 }
196 fn uri_query(
197 _input: &crate::operation::head_object::HeadObjectInput,
198 mut output: &mut ::std::string::String,
199 ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
200 let mut query = ::aws_smithy_http::query::Writer::new(output);
201 if let ::std::option::Option::Some(inner_2) = &_input.version_id {
202 {
203 query.push_kv("versionId", &::aws_smithy_http::query::fmt_string(inner_2));
204 }
205 }
206 if let ::std::option::Option::Some(inner_3) = &_input.part_number {
207 {
208 query.push_kv("partNumber", ::aws_smithy_types::primitive::Encoder::from(*inner_3).encode());
209 }
210 }
211 ::std::result::Result::Ok(())
212 }
213 #[allow(clippy::unnecessary_wraps)]
214 fn update_http_builder(
215 input: &crate::operation::head_object::HeadObjectInput,
216 builder: ::http::request::Builder,
217 ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
218 let mut uri = ::std::string::String::new();
219 uri_base(input, &mut uri)?;
220 uri_query(input, &mut uri)?;
221 let builder = crate::protocol_serde::shape_head_object::ser_head_object_headers(input, builder)?;
222 ::std::result::Result::Ok(builder.method("HEAD").uri(uri))
223 }
224 let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
225 builder
226 };
227 let body = ::aws_smithy_types::body::SdkBody::from("");
228
229 ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
230 }
231}
232#[derive(Debug)]
233struct HeadObjectEndpointParamsInterceptor;
234
235impl ::aws_smithy_runtime_api::client::interceptors::Intercept for HeadObjectEndpointParamsInterceptor {
236 fn name(&self) -> &'static str {
237 "HeadObjectEndpointParamsInterceptor"
238 }
239
240 fn read_before_execution(
241 &self,
242 context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
243 '_,
244 ::aws_smithy_runtime_api::client::interceptors::context::Input,
245 ::aws_smithy_runtime_api::client::interceptors::context::Output,
246 ::aws_smithy_runtime_api::client::interceptors::context::Error,
247 >,
248 cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
249 ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
250 let _input = context
251 .input()
252 .downcast_ref::<HeadObjectInput>()
253 .ok_or("failed to downcast to HeadObjectInput")?;
254
255 let params = crate::config::endpoint::Params::builder()
256 .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
257 .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
258 .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
259 .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
260 .set_force_path_style(cfg.load::<crate::config::ForcePathStyle>().map(|ty| ty.0))
261 .set_use_arn_region(cfg.load::<crate::config::UseArnRegion>().map(|ty| ty.0))
262 .set_disable_multi_region_access_points(cfg.load::<crate::config::DisableMultiRegionAccessPoints>().map(|ty| ty.0))
263 .set_accelerate(cfg.load::<crate::config::Accelerate>().map(|ty| ty.0))
264 .set_disable_s3_express_session_auth(cfg.load::<crate::config::DisableS3ExpressSessionAuth>().map(|ty| ty.0))
265 .set_bucket(Some(
266 _input
267 .bucket
268 .clone()
269 .filter(|f| !AsRef::<str>::as_ref(f).trim().is_empty())
270 .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("bucket", "A required field was not set"))?,
271 ))
272 .set_key(Some(
273 _input
274 .key
275 .clone()
276 .filter(|f| !AsRef::<str>::as_ref(f).trim().is_empty())
277 .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("key", "A required field was not set"))?,
278 ))
279 .build()
280 .map_err(|err| {
281 ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
282 })?;
283 cfg.interceptor_state()
284 .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
285 ::std::result::Result::Ok(())
286 }
287}
288#[allow(unreachable_code, unused_variables)]
289#[cfg(test)]
290mod head_object_request_test {
291 #[::tokio::test]
294 #[allow(unused_mut)]
295 async fn head_object_uri_encoding_request() {
296 let (http_client, request_receiver) = ::aws_smithy_runtime::client::http::test_util::capture_request(None);
297 let config_builder = crate::config::Config::builder().with_test_defaults().endpoint_url("https://example.com");
298 let config_builder = config_builder.region(::aws_types::region::Region::new("us-east-1"));
299 let mut config_builder = config_builder;
300 config_builder.set_region(Some(crate::config::Region::new("us-east-1")));
301
302 let config = config_builder.http_client(http_client).build();
303 let client = crate::Client::from_conf(config);
304 let result = client
305 .head_object()
306 .set_bucket(::std::option::Option::Some("test-bucket".to_owned()))
307 .set_key(::std::option::Option::Some("<> `?🐱".to_owned()))
308 .send()
309 .await;
310 let _ = dbg!(result);
311 let http_request = request_receiver.expect_request();
312 let uri: ::http::Uri = http_request.uri().parse().expect("invalid URI sent");
313 ::pretty_assertions::assert_eq!(http_request.method(), "HEAD", "method was incorrect");
314 ::pretty_assertions::assert_eq!(uri.path(), "/%3C%3E%20%60%3F%F0%9F%90%B1", "path was incorrect");
315 }
316 #[::tokio::test]
319 #[allow(unused_mut)]
320 async fn head_object_empty_body_response() {
321 let expected_output = crate::types::error::NotFound::builder().build();
322 let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
323 ::http::response::Builder::new()
324 .header("content-type", "application/xml")
325 .header("date", "Thu, 03 Jun 2021 04:05:52 GMT")
326 .header("server", "AmazonS3")
327 .header(
328 "x-amz-id-2",
329 "UTniwu6QmCIjVeuK2ZfeWBOnu7SqMQOS3Vac6B/K4H2ZCawYUl+nDbhGTImuyhZ5DFiojR3Kcz4=",
330 )
331 .header("x-amz-request-id", "GRZ6BZ468DF52F2E")
332 .status(404)
333 .body(::aws_smithy_types::body::SdkBody::from(""))
334 .unwrap(),
335 )
336 .unwrap();
337 use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
338 use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
339
340 let op = crate::operation::head_object::HeadObject::new();
341 let config = op.config().expect("the operation has config");
342 let de = config
343 .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
344 .expect("the config must have a deserializer");
345
346 let parsed = de.deserialize_streaming(&mut http_response);
347 let parsed = parsed.unwrap_or_else(|| {
348 let http_response =
349 http_response.map(|body| ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(body.bytes().unwrap())));
350 de.deserialize_nonstreaming(&http_response)
351 });
352 let parsed = parsed.expect_err("should be error response");
353 let parsed: &crate::operation::head_object::HeadObjectError = parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
354 if let crate::operation::head_object::HeadObjectError::NotFound(parsed) = parsed {
355 ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
356 } else {
357 panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
358 }
359 }
360}
361
362#[non_exhaustive]
364#[derive(::std::fmt::Debug)]
365pub enum HeadObjectError {
366 NotFound(crate::types::error::NotFound),
368 #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
370 variable wildcard pattern and check `.code()`:
371 \
372 `err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
373 \
374 See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-HeadObjectError) for what information is available for the error.")]
375 Unhandled(crate::error::sealed_unhandled::Unhandled),
376}
377impl HeadObjectError {
378 pub fn unhandled(
380 err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
381 ) -> Self {
382 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
383 source: err.into(),
384 meta: ::std::default::Default::default(),
385 })
386 }
387
388 pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
390 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
391 source: err.clone().into(),
392 meta: err,
393 })
394 }
395 pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
400 match self {
401 Self::NotFound(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
402 Self::Unhandled(e) => &e.meta,
403 }
404 }
405 pub fn is_not_found(&self) -> bool {
407 matches!(self, Self::NotFound(_))
408 }
409}
410impl ::std::error::Error for HeadObjectError {
411 fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
412 match self {
413 Self::NotFound(_inner) => ::std::option::Option::Some(_inner),
414 Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
415 }
416 }
417}
418impl ::std::fmt::Display for HeadObjectError {
419 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
420 match self {
421 Self::NotFound(_inner) => _inner.fmt(f),
422 Self::Unhandled(_inner) => {
423 if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
424 write!(f, "unhandled error ({code})")
425 } else {
426 f.write_str("unhandled error")
427 }
428 }
429 }
430 }
431}
432impl ::aws_smithy_types::retry::ProvideErrorKind for HeadObjectError {
433 fn code(&self) -> ::std::option::Option<&str> {
434 ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
435 }
436 fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
437 ::std::option::Option::None
438 }
439}
440impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for HeadObjectError {
441 fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
442 match self {
443 Self::NotFound(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
444 Self::Unhandled(_inner) => &_inner.meta,
445 }
446 }
447}
448impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for HeadObjectError {
449 fn create_unhandled_error(
450 source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
451 meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
452 ) -> Self {
453 Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
454 source,
455 meta: meta.unwrap_or_default(),
456 })
457 }
458}
459impl crate::s3_request_id::RequestIdExt for crate::operation::head_object::HeadObjectError {
460 fn extended_request_id(&self) -> Option<&str> {
461 self.meta().extended_request_id()
462 }
463}
464impl ::aws_types::request_id::RequestId for crate::operation::head_object::HeadObjectError {
465 fn request_id(&self) -> Option<&str> {
466 self.meta().request_id()
467 }
468}
469
470pub use crate::operation::head_object::_head_object_output::HeadObjectOutput;
471
472pub use crate::operation::head_object::_head_object_input::HeadObjectInput;
473
474mod _head_object_input;
475
476mod _head_object_output;
477
478pub mod builders;