1 1 | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 - | #[cfg(test)]
|
3 - | #[allow(unreachable_code, unused_variables)]
|
4 - | mod server_case_insensitive_error_operation_test {
|
5 - | /// Upper case error modeled lower case.
|
6 - | /// Test ID: ServiceLevelErrorServer
|
7 - | #[::tokio::test]
|
8 - | async fn service_level_error_server_response() {
|
9 - | let output = crate::error::ExtraError {};
|
10 - | let output = crate::error::CaseInsensitiveErrorOperationError::ExtraError(output);
|
11 - | use ::aws_smithy_http_server::response::IntoResponse;
|
12 - | let http_response = output.into_response();
|
13 - | ::pretty_assertions::assert_eq!(
|
14 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
15 - | http_response.status()
|
16 - | );
|
17 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
18 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
19 - | http_response.headers(),
|
20 - | expected_headers,
|
21 - | ));
|
22 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
23 - | .await
|
24 - | .expect("unable to extract body to bytes");
|
25 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
26 - | &body,
|
27 - | "{}",
|
28 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
29 - | ));
|
2 + | static CONTENT_TYPE_HTTPSTRINGPAYLOAD2: ::once_cell::sync::Lazy<::mime::Mime> =
|
3 + | ::once_cell::sync::Lazy::new(|| {
|
4 + | "text/plain"
|
5 + | .parse::<::mime::Mime>()
|
6 + | .expect("BUG: MIME parsing failed, content_type is not valid")
|
7 + | });
|
8 + | ::pin_project_lite::pin_project! {
|
9 + | /// A [`Future`](std::future::Future) aggregating the body bytes of a [`Request`] and constructing the
|
10 + | /// [`HttpStringPayload2Input`](crate::input::HttpStringPayload2Input) using modelled bindings.
|
11 + | pub struct HttpStringPayload2InputFuture {
|
12 + | inner: std::pin::Pin<Box<dyn std::future::Future<Output = Result<crate::input::HttpStringPayload2Input, ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError>> + Send>>
|
30 13 | }
|
31 14 | }
|
32 - | #[cfg(test)]
|
33 - | #[allow(unreachable_code, unused_variables)]
|
34 - | mod server_empty_struct_with_content_on_wire_op_test {
|
35 - | /// Upper case error modeled lower case.
|
36 - | /// Test ID: ServiceLevelErrorServer
|
37 - | #[::tokio::test]
|
38 - | async fn service_level_error_server_response() {
|
39 - | let output = crate::error::ExtraError {};
|
40 - | let output = crate::error::EmptyStructWithContentOnWireOpError::ExtraError(output);
|
41 - | use ::aws_smithy_http_server::response::IntoResponse;
|
42 - | let http_response = output.into_response();
|
43 - | ::pretty_assertions::assert_eq!(
|
44 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
45 - | http_response.status()
|
46 - | );
|
47 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
48 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
49 - | http_response.headers(),
|
50 - | expected_headers,
|
51 - | ));
|
52 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
53 - | .await
|
54 - | .expect("unable to extract body to bytes");
|
55 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
56 - | &body,
|
57 - | "{}",
|
58 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
59 - | ));
|
15 + |
|
16 + | impl std::future::Future for HttpStringPayload2InputFuture {
|
17 + | type Output = Result<
|
18 + | crate::input::HttpStringPayload2Input,
|
19 + | ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError,
|
20 + | >;
|
21 + |
|
22 + | fn poll(
|
23 + | self: std::pin::Pin<&mut Self>,
|
24 + | cx: &mut std::task::Context<'_>,
|
25 + | ) -> std::task::Poll<Self::Output> {
|
26 + | let this = self.project();
|
27 + | this.inner.as_mut().poll(cx)
|
60 28 | }
|
61 29 | }
|
62 - | #[cfg(test)]
|
63 - | #[allow(unreachable_code, unused_variables)]
|
64 - | mod server_enum_query_test {
|
65 - | /// Test ID: EnumQueryRequest
|
66 - | #[::tokio::test]
|
67 - | async fn enum_query_request_request() {
|
68 - | #[allow(unused_mut)]
|
69 - | let mut http_request = http::Request::builder()
|
70 - | .uri("/foo/enumvalue")
|
71 - | .method("GET")
|
72 - | .body(::aws_smithy_http_server::body::Body::empty())
|
73 - | .unwrap();
|
74 - | #[allow(unused_mut)]
|
75 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
76 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
77 - | let service =
|
78 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
79 - | .enum_query(move |input: crate::input::EnumQueryInput| {
|
80 - | let sender = sender.clone();
|
81 - | async move {
|
82 - | let result = {
|
83 - | let expected = crate::input::EnumQueryInput {
|
84 - | r#enum: "enumvalue"
|
85 - | .parse::<crate::model::StringEnum>()
|
86 - | .expect("static value validated to member"),
|
87 - | };
|
88 - | ::pretty_assertions::assert_eq!(input, expected);
|
89 - | let response = crate::output::EnumQueryOutput {};
|
90 - | Ok(response)
|
91 - | };
|
92 - | sender.send(()).await.expect("receiver dropped early");
|
93 - | result
|
94 - | }
|
95 - | })
|
96 - | .build_unchecked();
|
97 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
30 + |
|
31 + | impl<B>
|
32 + | ::aws_smithy_http_server::request::FromRequest<
|
33 + | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
34 + | B,
|
35 + | > for crate::input::HttpStringPayload2Input
|
36 + | where
|
37 + | B: ::aws_smithy_http_server::body::HttpBody + Send,
|
38 + | B: 'static,
|
39 + |
|
40 + | B::Data: Send,
|
41 + | ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection:
|
42 + | From<<B as ::aws_smithy_http_server::body::HttpBody>::Error>,
|
43 + | {
|
44 + | type Rejection = ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError;
|
45 + | type Future = HttpStringPayload2InputFuture;
|
46 + |
|
47 + | fn from_request(request: ::http::Request<B>) -> Self::Future {
|
48 + | let fut = async move {
|
49 + | if !::aws_smithy_http_server::protocol::accept_header_classifier(
|
50 + | request.headers(),
|
51 + | &CONTENT_TYPE_HTTPSTRINGPAYLOAD2,
|
52 + | ) {
|
53 + | return Err(::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection::NotAcceptable);
|
54 + | }
|
55 + | crate::protocol_serde::shape_http_string_payload2::de_http_string_payload2_http_request(
|
56 + | request,
|
57 + | )
|
98 58 | .await
|
99 - | .expect("unable to make an HTTP request");
|
100 - | assert!(receiver.recv().await.is_some());
|
101 - | }
|
102 - | /// Upper case error modeled lower case.
|
103 - | /// Test ID: ServiceLevelErrorServer
|
104 - | #[::tokio::test]
|
105 - | async fn service_level_error_server_response() {
|
106 - | let output = crate::error::ExtraError {};
|
107 - | let output = crate::error::EnumQueryError::ExtraError(output);
|
108 - | use ::aws_smithy_http_server::response::IntoResponse;
|
109 - | let http_response = output.into_response();
|
110 - | ::pretty_assertions::assert_eq!(
|
111 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
112 - | http_response.status()
|
59 + | .map_err(Into::into)
|
60 + | };
|
61 + | use ::futures_util::future::TryFutureExt;
|
62 + | let fut = fut.map_err(
|
63 + | |e: ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection| {
|
64 + | ::tracing::debug!(error = %e, "failed to deserialize request");
|
65 + | ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(
|
66 + | e,
|
67 + | )
|
68 + | },
|
113 69 | );
|
114 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
115 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
116 - | http_response.headers(),
|
117 - | expected_headers,
|
118 - | ));
|
119 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
120 - | .await
|
121 - | .expect("unable to extract body to bytes");
|
122 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
123 - | &body,
|
124 - | "{}",
|
125 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
126 - | ));
|
70 + | HttpStringPayload2InputFuture {
|
71 + | inner: Box::pin(fut),
|
72 + | }
|
127 73 | }
|
128 74 | }
|
129 - | #[cfg(test)]
|
130 - | #[allow(unreachable_code, unused_variables)]
|
131 - | mod server_escaped_string_values_test {
|
132 - | /// Test ID: EscapedStringValuesRequest
|
133 - | #[::tokio::test]
|
134 - | async fn escaped_string_values_request_request() {
|
135 - | #[allow(unused_mut)]
|
136 - | let mut http_request = http::Request::builder()
|
137 - | .uri("/escaped-string-values")
|
138 - | .method("POST")
|
139 - | .header("Content-Type", "application/json")
|
140 - | .body(::aws_smithy_http_server::body::Body::from(
|
141 - | ::bytes::Bytes::from_static(
|
142 - | "{\"enum\":\"has\\\"quotes\",\"also\\\"has\\\"quotes\":\"test\"}".as_bytes(),
|
143 - | ),
|
144 - | ))
|
145 - | .unwrap();
|
146 - | #[allow(unused_mut)]
|
147 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
148 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
149 - | let service =
|
150 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
151 - | .escaped_string_values(move |input: crate::input::EscapedStringValuesInput| {
|
152 - | let sender = sender.clone();
|
153 - | async move {
|
154 - | let result = {
|
155 - | let expected = crate::input::EscapedStringValuesInput {
|
156 - | r#enum: ::std::option::Option::Some(
|
157 - | "has\"quotes"
|
158 - | .parse::<crate::model::EnumWithEscapedChars>()
|
159 - | .expect("static value validated to member"),
|
160 - | ),
|
161 - | some_string: ::std::option::Option::Some("test".to_owned()),
|
162 - | };
|
163 - | ::pretty_assertions::assert_eq!(input, expected);
|
164 - | let response = crate::output::EscapedStringValuesOutput {
|
165 - | r#enum: ::std::option::Option::None,
|
166 - | some_string: ::std::option::Option::None,
|
167 - | };
|
168 - | Ok(response)
|
169 - | };
|
170 - | sender.send(()).await.expect("receiver dropped early");
|
171 - | result
|
75 + | impl
|
76 + | ::aws_smithy_http_server::response::IntoResponse<
|
77 + | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
78 + | > for crate::output::HttpStringPayload2Output
|
79 + | {
|
80 + | fn into_response(self) -> ::aws_smithy_http_server::response::Response {
|
81 + | match crate::protocol_serde::shape_http_string_payload2::ser_http_string_payload2_http_response(self) {
|
82 + | Ok(response) => response,
|
83 + | Err(e) => {
|
84 + | ::tracing::error!(error = %e, "failed to serialize response");
|
85 + | ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
|
86 + | }
|
172 87 | }
|
173 - | })
|
174 - | .build_unchecked();
|
175 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
176 - | .await
|
177 - | .expect("unable to make an HTTP request");
|
178 - | assert!(receiver.recv().await.is_some());
|
179 - | }
|
180 - | /// Test ID: EscapedStringValuesResponse
|
181 - | #[::tokio::test]
|
182 - | async fn escaped_string_values_response_response() {
|
183 - | let output = crate::output::EscapedStringValuesOutput {
|
184 - | r#enum: ::std::option::Option::Some(
|
185 - | "has\"quotes"
|
186 - | .parse::<crate::model::EnumWithEscapedChars>()
|
187 - | .expect("static value validated to member"),
|
188 - | ),
|
189 - | some_string: ::std::option::Option::Some("test".to_owned()),
|
190 - | };
|
191 - | use ::aws_smithy_http_server::response::IntoResponse;
|
192 - | let http_response = output.into_response();
|
193 - | ::pretty_assertions::assert_eq!(
|
194 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
195 - | http_response.status()
|
196 - | );
|
197 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
198 - | .await
|
199 - | .expect("unable to extract body to bytes");
|
200 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
201 - | &body,
|
202 - | "{\"enum\":\"has\\\"quotes\",\"also\\\"has\\\"quotes\":\"test\"}",
|
203 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
204 - | ));
|
205 - | }
|
206 - | /// Upper case error modeled lower case.
|
207 - | /// Test ID: ServiceLevelErrorServer
|
208 - | #[::tokio::test]
|
209 - | async fn service_level_error_server_response() {
|
210 - | let output = crate::error::ExtraError {};
|
211 - | let output = crate::error::EscapedStringValuesError::ExtraError(output);
|
212 - | use ::aws_smithy_http_server::response::IntoResponse;
|
213 - | let http_response = output.into_response();
|
214 - | ::pretty_assertions::assert_eq!(
|
215 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
216 - | http_response.status()
|
217 - | );
|
218 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
219 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
220 - | http_response.headers(),
|
221 - | expected_headers,
|
222 - | ));
|
223 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
224 - | .await
|
225 - | .expect("unable to extract body to bytes");
|
226 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
227 - | &body,
|
228 - | "{}",
|
229 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
230 - | ));
|
231 - | }
|
232 - | }
|
233 - | #[cfg(test)]
|
234 - | #[allow(unreachable_code, unused_variables)]
|
235 - | mod server_http_enum_payload2_test {
|
236 - | /// Test ID: RestJsonEnumPayloadRequest2
|
237 - | #[::tokio::test]
|
238 - | async fn rest_json_enum_payload_request2_request() {
|
239 - | #[allow(unused_mut)]
|
240 - | let mut http_request = http::Request::builder()
|
241 - | .uri("/EnumPayload2")
|
242 - | .method("POST")
|
243 - | .header("Content-Type", "text/plain")
|
244 - | .body(::aws_smithy_http_server::body::Body::from(
|
245 - | ::bytes::Bytes::from_static("enumvalue".as_bytes()),
|
246 - | ))
|
247 - | .unwrap();
|
248 - | #[allow(unused_mut)]
|
249 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
250 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
251 - | let service =
|
252 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
253 - | .http_enum_payload2(move |input: crate::input::HttpEnumPayload2Input| {
|
254 - | let sender = sender.clone();
|
255 - | async move {
|
256 - | let result = {
|
257 - | let expected = crate::input::HttpEnumPayload2Input {
|
258 - | payload: ::std::option::Option::Some(
|
259 - | "enumvalue"
|
260 - | .parse::<crate::model::StringEnum>()
|
261 - | .expect("static value validated to member"),
|
262 - | ),
|
263 - | };
|
264 - | ::pretty_assertions::assert_eq!(input, expected);
|
265 - | let response = crate::output::HttpEnumPayload2Output {
|
266 - | payload: ::std::option::Option::None,
|
267 - | };
|
268 - | Ok(response)
|
269 - | };
|
270 - | sender.send(()).await.expect("receiver dropped early");
|
271 - | result
|
272 - | }
|
273 - | })
|
274 - | .build_unchecked();
|
275 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
276 - | .await
|
277 - | .expect("unable to make an HTTP request");
|
278 - | assert!(receiver.recv().await.is_some());
|
279 - | }
|
280 - | /// Test ID: RestJsonEnumPayloadResponse2
|
281 - | #[::tokio::test]
|
282 - | async fn rest_json_enum_payload_response2_response() {
|
283 - | let output = crate::output::HttpEnumPayload2Output {
|
284 - | payload: ::std::option::Option::Some(
|
285 - | "enumvalue"
|
286 - | .parse::<crate::model::StringEnum>()
|
287 - | .expect("static value validated to member"),
|
288 - | ),
|
289 - | };
|
290 - | use ::aws_smithy_http_server::response::IntoResponse;
|
291 - | let http_response = output.into_response();
|
292 - | ::pretty_assertions::assert_eq!(
|
293 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
294 - | http_response.status()
|
295 - | );
|
296 - | let expected_headers = [("Content-Type", "text/plain")];
|
297 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
298 - | http_response.headers(),
|
299 - | expected_headers,
|
300 - | ));
|
301 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
302 - | .await
|
303 - | .expect("unable to extract body to bytes");
|
304 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
305 - | &body,
|
306 - | "enumvalue",
|
307 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
308 - | ));
|
309 - | }
|
310 - | /// Upper case error modeled lower case.
|
311 - | /// Test ID: ServiceLevelErrorServer
|
312 - | #[::tokio::test]
|
313 - | async fn service_level_error_server_response() {
|
314 - | let output = crate::error::ExtraError {};
|
315 - | let output = crate::error::HttpEnumPayload2Error::ExtraError(output);
|
316 - | use ::aws_smithy_http_server::response::IntoResponse;
|
317 - | let http_response = output.into_response();
|
318 - | ::pretty_assertions::assert_eq!(
|
319 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
320 - | http_response.status()
|
321 - | );
|
322 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
323 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
324 - | http_response.headers(),
|
325 - | expected_headers,
|
326 - | ));
|
327 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
328 - | .await
|
329 - | .expect("unable to extract body to bytes");
|
330 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
331 - | &body,
|
332 - | "{}",
|
333 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
334 - | ));
|
335 - | }
|
336 - | }
|
337 - | #[cfg(test)]
|
338 - | #[allow(unreachable_code, unused_variables)]
|
339 - | mod server_http_payload_traits2_test {
|
340 - | /// Servers must accept no content type for blob inputs
|
341 - | /// without the media type trait.
|
342 - | /// Test ID: RestJsonHttpPayloadTraitsWithBlobAcceptsNoContentType
|
343 - | #[::tokio::test]
|
344 - | async fn rest_json_http_payload_traits_with_blob_accepts_no_content_type_request() {
|
345 - | #[allow(unused_mut)]
|
346 - | let mut http_request = http::Request::builder()
|
347 - | .uri("/HttpPayloadTraits")
|
348 - | .method("POST")
|
349 - | .header("X-Foo", "Foo")
|
350 - | .body(::aws_smithy_http_server::body::Body::from(
|
351 - | ::bytes::Bytes::from_static("This is definitely a jpeg".as_bytes()),
|
352 - | ))
|
353 - | .unwrap();
|
354 - | #[allow(unused_mut)]
|
355 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
356 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
357 - | let service =
|
358 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
359 - | .http_payload_traits2(move |input: crate::input::HttpPayloadTraits2Input| {
|
360 - | let sender = sender.clone();
|
361 - | async move {
|
362 - | let result = {
|
363 - | let expected = crate::input::HttpPayloadTraits2Input {
|
364 - | foo: ::std::option::Option::Some("Foo".to_owned()),
|
365 - | blob: ::std::option::Option::Some(::aws_smithy_types::Blob::new(
|
366 - | "This is definitely a jpeg",
|
367 - | )),
|
368 - | };
|
369 - | ::pretty_assertions::assert_eq!(input, expected);
|
370 - | let response = crate::output::HttpPayloadTraits2Output {
|
371 - | foo: ::std::option::Option::None,
|
372 - | blob: ::std::option::Option::None,
|
373 - | };
|
374 - | Ok(response)
|
375 - | };
|
376 - | sender.send(()).await.expect("receiver dropped early");
|
377 - | result
|
378 - | }
|
379 - | })
|
380 - | .build_unchecked();
|
381 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
382 - | .await
|
383 - | .expect("unable to make an HTTP request");
|
384 - | assert!(receiver.recv().await.is_some());
|
385 - | }
|
386 - | /// Upper case error modeled lower case.
|
387 - | /// Test ID: ServiceLevelErrorServer
|
388 - | #[::tokio::test]
|
389 - | async fn service_level_error_server_response() {
|
390 - | let output = crate::error::ExtraError {};
|
391 - | let output = crate::error::HttpPayloadTraits2Error::ExtraError(output);
|
392 - | use ::aws_smithy_http_server::response::IntoResponse;
|
393 - | let http_response = output.into_response();
|
394 - | ::pretty_assertions::assert_eq!(
|
395 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
396 - | http_response.status()
|
397 - | );
|
398 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
399 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
400 - | http_response.headers(),
|
401 - | expected_headers,
|
402 - | ));
|
403 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
404 - | .await
|
405 - | .expect("unable to extract body to bytes");
|
406 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
407 - | &body,
|
408 - | "{}",
|
409 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
410 - | ));
|
411 - | }
|
412 - | }
|
413 - | #[cfg(test)]
|
414 - | #[allow(unreachable_code, unused_variables)]
|
415 - | mod server_http_string_payload2_test {
|
416 - | /// Test ID: RestJsonStringPayloadRequest2
|
417 - | #[::tokio::test]
|
418 - | async fn rest_json_string_payload_request2_request() {
|
419 - | #[allow(unused_mut)]
|
420 - | let mut http_request = http::Request::builder()
|
421 - | .uri("/StringPayload2")
|
422 - | .method("POST")
|
423 - | .header("Content-Type", "text/plain")
|
424 - | .body(::aws_smithy_http_server::body::Body::from(
|
425 - | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
426 - | ))
|
427 - | .unwrap();
|
428 - | #[allow(unused_mut)]
|
429 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
430 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
431 - | let service =
|
432 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
433 - | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
434 - | let sender = sender.clone();
|
435 - | async move {
|
436 - | let result = {
|
437 - | let expected = crate::input::HttpStringPayload2Input {
|
438 - | payload: ::std::option::Option::Some("rawstring".to_owned()),
|
439 - | };
|
440 - | ::pretty_assertions::assert_eq!(input, expected);
|
441 - | let response = crate::output::HttpStringPayload2Output {
|
442 - | payload: ::std::option::Option::None,
|
443 - | };
|
444 - | Ok(response)
|
445 - | };
|
446 - | sender.send(()).await.expect("receiver dropped early");
|
447 - | result
|
448 - | }
|
449 - | })
|
450 - | .build_unchecked();
|
451 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
452 - | .await
|
453 - | .expect("unable to make an HTTP request");
|
454 - | assert!(receiver.recv().await.is_some());
|
455 - | }
|
456 - | /// Test ID: RestJsonStringPayloadResponse2
|
457 - | #[::tokio::test]
|
458 - | async fn rest_json_string_payload_response2_response() {
|
459 - | let output = crate::output::HttpStringPayload2Output {
|
460 - | payload: ::std::option::Option::Some("rawstring".to_owned()),
|
461 - | };
|
462 - | use ::aws_smithy_http_server::response::IntoResponse;
|
463 - | let http_response = output.into_response();
|
464 - | ::pretty_assertions::assert_eq!(
|
465 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
466 - | http_response.status()
|
467 - | );
|
468 - | let expected_headers = [("Content-Type", "text/plain")];
|
469 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
470 - | http_response.headers(),
|
471 - | expected_headers,
|
472 - | ));
|
473 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
474 - | .await
|
475 - | .expect("unable to extract body to bytes");
|
476 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
477 - | &body,
|
478 - | "rawstring",
|
479 - | ::aws_smithy_protocol_test::MediaType::from("text/plain"),
|
480 - | ));
|
481 - | }
|
482 - | /// Upper case error modeled lower case.
|
483 - | /// Test ID: ServiceLevelErrorServer
|
484 - | #[::tokio::test]
|
485 - | async fn service_level_error_server_response() {
|
486 - | let output = crate::error::ExtraError {};
|
487 - | let output = crate::error::HttpStringPayload2Error::ExtraError(output);
|
488 - | use ::aws_smithy_http_server::response::IntoResponse;
|
489 - | let http_response = output.into_response();
|
490 - | ::pretty_assertions::assert_eq!(
|
491 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
492 - | http_response.status()
|
493 - | );
|
494 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
495 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
496 - | http_response.headers(),
|
497 - | expected_headers,
|
498 - | ));
|
499 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
500 - | .await
|
501 - | .expect("unable to extract body to bytes");
|
502 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
503 - | &body,
|
504 - | "{}",
|
505 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
506 - | ));
|
507 - | }
|
508 - | /// Serializes a string in the HTTP payload without a content-type header
|
509 - | /// Test ID: RestJsonStringPayloadNoContentType2
|
510 - | #[::tokio::test]
|
511 - | async fn rest_json_string_payload_no_content_type2_malformed_request() {
|
512 - | {
|
513 - | #[allow(unused_mut)]
|
514 - | let mut http_request = http::Request::builder()
|
515 - | .uri("/StringPayload2")
|
516 - | .method("POST")
|
517 - | .body(::aws_smithy_http_server::body::Body::from(
|
518 - | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
519 - | ))
|
520 - | .unwrap();
|
521 - | #[allow(unused_mut)]
|
522 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
523 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
524 - | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
525 - | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
526 - | let sender = sender.clone();
|
527 - | async move {
|
528 - | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
529 - | sender.send(()).await.expect("receiver dropped early");
|
530 - | result
|
531 - | }
|
532 - | })
|
533 - | .build_unchecked();
|
534 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
535 - | .await
|
536 - | .expect("unable to make an HTTP request");
|
537 - | ::pretty_assertions::assert_eq!(
|
538 - | http::StatusCode::from_u16(415).expect("invalid expected HTTP status code"),
|
539 - | http_response.status()
|
540 - | );
|
541 - | let expected_headers = [("x-amzn-errortype", "UnsupportedMediaTypeException")];
|
542 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
543 - | http_response.headers(),
|
544 - | expected_headers,
|
545 - | ));
|
546 - | }
|
547 - | }
|
548 - | /// Serializes a string in the HTTP payload without the expected content-type header
|
549 - | /// Test ID: RestJsonStringPayloadWrongContentType2
|
550 - | #[::tokio::test]
|
551 - | async fn rest_json_string_payload_wrong_content_type2_malformed_request() {
|
552 - | {
|
553 - | #[allow(unused_mut)]
|
554 - | let mut http_request = http::Request::builder()
|
555 - | .uri("/StringPayload2")
|
556 - | .method("POST")
|
557 - | .header("Content-Type", "application/json")
|
558 - | .body(::aws_smithy_http_server::body::Body::from(
|
559 - | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
560 - | ))
|
561 - | .unwrap();
|
562 - | #[allow(unused_mut)]
|
563 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
564 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
565 - | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
566 - | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
567 - | let sender = sender.clone();
|
568 - | async move {
|
569 - | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
570 - | sender.send(()).await.expect("receiver dropped early");
|
571 - | result
|
572 - | }
|
573 - | })
|
574 - | .build_unchecked();
|
575 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
576 - | .await
|
577 - | .expect("unable to make an HTTP request");
|
578 - | ::pretty_assertions::assert_eq!(
|
579 - | http::StatusCode::from_u16(415).expect("invalid expected HTTP status code"),
|
580 - | http_response.status()
|
581 - | );
|
582 - | let expected_headers = [("x-amzn-errortype", "UnsupportedMediaTypeException")];
|
583 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
584 - | http_response.headers(),
|
585 - | expected_headers,
|
586 - | ));
|
587 - | }
|
588 - | }
|
589 - | /// Serializes a string in the HTTP payload with an unstatisfiable accept header
|
590 - | /// Test ID: RestJsonStringPayloadUnsatisfiableAccept2
|
591 - | #[::tokio::test]
|
592 - | async fn rest_json_string_payload_unsatisfiable_accept2_malformed_request() {
|
593 - | {
|
594 - | #[allow(unused_mut)]
|
595 - | let mut http_request = http::Request::builder()
|
596 - | .uri("/StringPayload2")
|
597 - | .method("POST")
|
598 - | .header("Accept", "application/json")
|
599 - | .header("Content-Type", "text/plain")
|
600 - | .body(::aws_smithy_http_server::body::Body::from(
|
601 - | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
602 - | ))
|
603 - | .unwrap();
|
604 - | #[allow(unused_mut)]
|
605 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
606 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
607 - | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
608 - | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
609 - | let sender = sender.clone();
|
610 - | async move {
|
611 - | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
612 - | sender.send(()).await.expect("receiver dropped early");
|
613 - | result
|
614 - | }
|
615 - | })
|
616 - | .build_unchecked();
|
617 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
618 - | .await
|
619 - | .expect("unable to make an HTTP request");
|
620 - | ::pretty_assertions::assert_eq!(
|
621 - | http::StatusCode::from_u16(406).expect("invalid expected HTTP status code"),
|
622 - | http_response.status()
|
623 - | );
|
624 - | let expected_headers = [("x-amzn-errortype", "NotAcceptableException")];
|
625 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
626 - | http_response.headers(),
|
627 - | expected_headers,
|
628 - | ));
|
629 - | }
|
630 - | }
|
631 - | }
|
632 - | #[cfg(test)]
|
633 - | #[allow(unreachable_code, unused_variables)]
|
634 - | mod server_malformed_content_type_with_body2_test {
|
635 - | /// Upper case error modeled lower case.
|
636 - | /// Test ID: ServiceLevelErrorServer
|
637 - | #[::tokio::test]
|
638 - | async fn service_level_error_server_response() {
|
639 - | let output = crate::error::ExtraError {};
|
640 - | let output = crate::error::MalformedContentTypeWithBody2Error::ExtraError(output);
|
641 - | use ::aws_smithy_http_server::response::IntoResponse;
|
642 - | let http_response = output.into_response();
|
643 - | ::pretty_assertions::assert_eq!(
|
644 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
645 - | http_response.status()
|
646 - | );
|
647 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
648 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
649 - | http_response.headers(),
|
650 - | expected_headers,
|
651 - | ));
|
652 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
653 - | .await
|
654 - | .expect("unable to extract body to bytes");
|
655 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
656 - | &body,
|
657 - | "{}",
|
658 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
659 - | ));
|
660 - | }
|
661 - | /// When there is modeled input, the content type must be application/json
|
662 - | /// Test ID: RestJsonWithBodyExpectsApplicationJsonContentTypeNoHeaders
|
663 - | #[::tokio::test]
|
664 - | async fn rest_json_with_body_expects_application_json_content_type_no_headers_malformed_request(
|
665 - | ) {
|
666 - | {
|
667 - | #[allow(unused_mut)]
|
668 - | let mut http_request = http::Request::builder()
|
669 - | .uri("/MalformedContentTypeWithBody")
|
670 - | .method("POST")
|
671 - | .body(::aws_smithy_http_server::body::Body::from(
|
672 - | ::bytes::Bytes::from_static("{}".as_bytes()),
|
673 - | ))
|
674 - | .unwrap();
|
675 - | #[allow(unused_mut)]
|
676 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
677 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
678 - | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
679 - | .malformed_content_type_with_body2(move |input: crate::input::MalformedContentTypeWithBody2Input| {
|
680 - | let sender = sender.clone();
|
681 - | async move {
|
682 - | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::MalformedContentTypeWithBody2Output, crate::error::MalformedContentTypeWithBody2Error> };
|
683 - | sender.send(()).await.expect("receiver dropped early");
|
684 - | result
|
685 - | }
|
686 - | })
|
687 - | .build_unchecked();
|
688 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
689 - | .await
|
690 - | .expect("unable to make an HTTP request");
|
691 - | ::pretty_assertions::assert_eq!(
|
692 - | http::StatusCode::from_u16(415).expect("invalid expected HTTP status code"),
|
693 - | http_response.status()
|
694 - | );
|
695 - | let expected_headers = [("x-amzn-errortype", "UnsupportedMediaTypeException")];
|
696 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
697 - | http_response.headers(),
|
698 - | expected_headers,
|
699 - | ));
|
700 - | }
|
701 - | }
|
702 - | }
|
703 - | #[cfg(test)]
|
704 - | #[allow(unreachable_code, unused_variables)]
|
705 - | mod server_map_with_enum_key_op_test {
|
706 - | /// Test ID: MapWithEnumKeyRequest
|
707 - | #[::tokio::test]
|
708 - | async fn map_with_enum_key_request_request() {
|
709 - | #[allow(unused_mut)]
|
710 - | let mut http_request = http::Request::builder()
|
711 - | .uri("/map-with-enum-key")
|
712 - | .method("POST")
|
713 - | .header("Content-Type", "application/json")
|
714 - | .body(::aws_smithy_http_server::body::Body::from(
|
715 - | ::bytes::Bytes::from_static("{\"map\":{\"enumvalue\":\"something\"}}".as_bytes()),
|
716 - | ))
|
717 - | .unwrap();
|
718 - | #[allow(unused_mut)]
|
719 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
720 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
721 - | let service =
|
722 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
723 - | .map_with_enum_key_op(move |input: crate::input::MapWithEnumKeyOpInput| {
|
724 - | let sender = sender.clone();
|
725 - | async move {
|
726 - | let result = {
|
727 - | let expected = crate::input::MapWithEnumKeyOpInput {
|
728 - | map: ::std::option::Option::Some({
|
729 - | let mut ret = ::std::collections::HashMap::new();
|
730 - | ret.insert(
|
731 - | "enumvalue"
|
732 - | .parse::<crate::model::StringEnum>()
|
733 - | .expect("static value validated to member"),
|
734 - | "something".to_owned(),
|
735 - | );
|
736 - | ret
|
737 - | }),
|
738 - | };
|
739 - | ::pretty_assertions::assert_eq!(input, expected);
|
740 - | let response = crate::output::MapWithEnumKeyOpOutput {
|
741 - | map: ::std::option::Option::None,
|
742 - | };
|
743 - | Ok(response)
|
744 - | };
|
745 - | sender.send(()).await.expect("receiver dropped early");
|
746 - | result
|
747 - | }
|
748 - | })
|
749 - | .build_unchecked();
|
750 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
751 - | .await
|
752 - | .expect("unable to make an HTTP request");
|
753 - | assert!(receiver.recv().await.is_some());
|
754 - | }
|
755 - | /// Test ID: MapWithEnumKeyResponse
|
756 - | #[::tokio::test]
|
757 - | async fn map_with_enum_key_response_response() {
|
758 - | let output = crate::output::MapWithEnumKeyOpOutput {
|
759 - | map: ::std::option::Option::Some({
|
760 - | let mut ret = ::std::collections::HashMap::new();
|
761 - | ret.insert(
|
762 - | "enumvalue"
|
763 - | .parse::<crate::model::StringEnum>()
|
764 - | .expect("static value validated to member"),
|
765 - | "something".to_owned(),
|
766 - | );
|
767 - | ret
|
768 - | }),
|
769 - | };
|
770 - | use ::aws_smithy_http_server::response::IntoResponse;
|
771 - | let http_response = output.into_response();
|
772 - | ::pretty_assertions::assert_eq!(
|
773 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
774 - | http_response.status()
|
775 - | );
|
776 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
777 - | .await
|
778 - | .expect("unable to extract body to bytes");
|
779 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
780 - | &body,
|
781 - | "{\"map\":{\"enumvalue\":\"something\"}}",
|
782 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
783 - | ));
|
784 - | }
|
785 - | /// Upper case error modeled lower case.
|
786 - | /// Test ID: ServiceLevelErrorServer
|
787 - | #[::tokio::test]
|
788 - | async fn service_level_error_server_response() {
|
789 - | let output = crate::error::ExtraError {};
|
790 - | let output = crate::error::MapWithEnumKeyOpError::ExtraError(output);
|
791 - | use ::aws_smithy_http_server::response::IntoResponse;
|
792 - | let http_response = output.into_response();
|
793 - | ::pretty_assertions::assert_eq!(
|
794 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
795 - | http_response.status()
|
796 - | );
|
797 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
798 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
799 - | http_response.headers(),
|
800 - | expected_headers,
|
801 - | ));
|
802 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
803 - | .await
|
804 - | .expect("unable to extract body to bytes");
|
805 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
806 - | &body,
|
807 - | "{}",
|
808 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
809 - | ));
|
810 - | }
|
811 - | }
|
812 - | #[cfg(test)]
|
813 - | #[allow(unreachable_code, unused_variables)]
|
814 - | mod server_null_in_non_sparse_test {
|
815 - | /// Upper case error modeled lower case.
|
816 - | /// Test ID: ServiceLevelErrorServer
|
817 - | #[::tokio::test]
|
818 - | async fn service_level_error_server_response() {
|
819 - | let output = crate::error::ExtraError {};
|
820 - | let output = crate::error::NullInNonSparseError::ExtraError(output);
|
821 - | use ::aws_smithy_http_server::response::IntoResponse;
|
822 - | let http_response = output.into_response();
|
823 - | ::pretty_assertions::assert_eq!(
|
824 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
825 - | http_response.status()
|
826 - | );
|
827 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
828 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
829 - | http_response.headers(),
|
830 - | expected_headers,
|
831 - | ));
|
832 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
833 - | .await
|
834 - | .expect("unable to extract body to bytes");
|
835 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
836 - | &body,
|
837 - | "{}",
|
838 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
839 - | ));
|
840 88 | }
|
841 89 | }
|
842 - | #[cfg(test)]
|
843 - | #[allow(unreachable_code, unused_variables)]
|
844 - | mod server_primitive_int_header_test {
|
845 - | /// Test ID: DeserPrimitiveHeader
|
846 - | #[::tokio::test]
|
847 - | async fn deser_primitive_header_response() {
|
848 - | let output = crate::output::PrimitiveIntHeaderOutput { field: 123 };
|
849 - | use ::aws_smithy_http_server::response::IntoResponse;
|
850 - | let http_response = output.into_response();
|
851 - | ::pretty_assertions::assert_eq!(
|
852 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
853 - | http_response.status()
|
854 - | );
|
855 - | let expected_headers = [("x-field", "123")];
|
856 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
857 - | http_response.headers(),
|
858 - | expected_headers,
|
859 - | ));
|
860 - | }
|
861 - | /// Test ID: DeserPrimitiveHeaderMissing
|
862 - | #[::tokio::test]
|
863 - | async fn deser_primitive_header_missing_response() {
|
864 - | let output = crate::output::PrimitiveIntHeaderOutput { field: 0 };
|
865 - | use ::aws_smithy_http_server::response::IntoResponse;
|
866 - | let http_response = output.into_response();
|
867 - | ::pretty_assertions::assert_eq!(
|
868 - | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
869 - | http_response.status()
|
870 - | );
|
871 - | }
|
872 - | /// Upper case error modeled lower case.
|
873 - | /// Test ID: ServiceLevelErrorServer
|
874 - | #[::tokio::test]
|
875 - | async fn service_level_error_server_response() {
|
876 - | let output = crate::error::ExtraError {};
|
877 - | let output = crate::error::PrimitiveIntHeaderError::ExtraError(output);
|
878 - | use ::aws_smithy_http_server::response::IntoResponse;
|
879 - | let http_response = output.into_response();
|
880 - | ::pretty_assertions::assert_eq!(
|
881 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
882 - | http_response.status()
|
883 - | );
|
884 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
885 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
886 - | http_response.headers(),
|
887 - | expected_headers,
|
888 - | ));
|
889 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
890 - | .await
|
891 - | .expect("unable to extract body to bytes");
|
892 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
893 - | &body,
|
894 - | "{}",
|
895 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
896 - | ));
|
90 + | impl
|
91 + | ::aws_smithy_http_server::response::IntoResponse<
|
92 + | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
93 + | > for crate::error::HttpStringPayload2Error
|
94 + | {
|
95 + | fn into_response(self) -> ::aws_smithy_http_server::response::Response {
|
96 + | match crate::protocol_serde::shape_http_string_payload2::ser_http_string_payload2_http_error(
|
97 + | &self,
|
98 + | ) {
|
99 + | Ok(mut response) => {
|
100 + | response.extensions_mut().insert(
|
101 + | ::aws_smithy_http_server::extension::ModeledErrorExtension::new(self.name()),
|
102 + | );
|
103 + | response
|
104 + | }
|
105 + | Err(e) => {
|
106 + | ::tracing::error!(error = %e, "failed to serialize response");
|
107 + | ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
|
108 + | }
|
109 + | }
|
897 110 | }
|
898 111 | }
|
899 - | #[cfg(test)]
|
112 + |
|
900 113 | #[allow(unreachable_code, unused_variables)]
|
901 - | mod server_primitive_int_op_test {
|
902 - | /// Upper case error modeled lower case.
|
903 - | /// Test ID: ServiceLevelErrorServer
|
904 - | #[::tokio::test]
|
905 - | async fn service_level_error_server_response() {
|
906 - | let output = crate::error::ExtraError {};
|
907 - | let output = crate::error::PrimitiveIntOpError::ExtraError(output);
|
908 - | use ::aws_smithy_http_server::response::IntoResponse;
|
909 - | let http_response = output.into_response();
|
910 - | ::pretty_assertions::assert_eq!(
|
911 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
912 - | http_response.status()
|
913 - | );
|
914 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
915 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
916 - | http_response.headers(),
|
917 - | expected_headers,
|
918 - | ));
|
919 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
920 - | .await
|
921 - | .expect("unable to extract body to bytes");
|
922 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
923 - | &body,
|
924 - | "{}",
|
925 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
926 - | ));
|
927 - | }
|
928 - | }
|
929 114 | #[cfg(test)]
|
930 - | #[allow(unreachable_code, unused_variables)]
|
931 - | mod server_query_precedence_test {
|
932 - | /// Servers put all query params in map
|
933 - | /// Test ID: RestJsonServersPutAllQueryParamsInMap
|
115 + | mod http_string_payload2_test {
|
116 + |
|
117 + | /// Test ID: RestJsonStringPayloadRequest2
|
934 118 | #[::tokio::test]
|
935 - | async fn rest_json_servers_put_all_query_params_in_map_request() {
|
119 + | #[::tracing_test::traced_test]
|
120 + | async fn rest_json_string_payload_request2_request() {
|
936 121 | #[allow(unused_mut)]
|
937 122 | let mut http_request = http::Request::builder()
|
938 - | .uri("/Precedence")
|
123 + | .uri("/StringPayload2")
|
939 124 | .method("POST")
|
125 + | .header("Content-Type", "text/plain")
|
940 126 | .body(::aws_smithy_http_server::body::Body::from(
|
941 - | ::bytes::Bytes::from_static("".as_bytes()),
|
127 + | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
942 128 | ))
|
943 129 | .unwrap();
|
944 - | *http_request.uri_mut() = "/Precedence?bar=named&qux=fromMap".parse().unwrap();
|
945 130 | #[allow(unused_mut)]
|
946 131 | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
947 132 | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
948 133 | let service =
|
949 134 | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
950 - | .query_precedence(move |input: crate::input::QueryPrecedenceInput| {
|
135 + | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
951 136 | let sender = sender.clone();
|
952 137 | async move {
|
953 138 | let result = {
|
954 - | let expected = crate::input::QueryPrecedenceInput {
|
955 - | foo: ::std::option::Option::Some("named".to_owned()),
|
956 - | baz: ::std::option::Option::Some({
|
957 - | let mut ret = ::std::collections::HashMap::new();
|
958 - | ret.insert("bar".to_owned(), "named".to_owned());
|
959 - | ret.insert("qux".to_owned(), "fromMap".to_owned());
|
960 - | ret
|
961 - | }),
|
139 + | let expected = crate::input::HttpStringPayload2Input {
|
140 + | payload: ::std::option::Option::Some("rawstring".to_owned()),
|
962 141 | };
|
963 142 | ::pretty_assertions::assert_eq!(input, expected);
|
964 - | let response = crate::output::QueryPrecedenceOutput {};
|
143 + | let response = crate::output::HttpStringPayload2Output {
|
144 + | payload: ::std::option::Option::None,
|
145 + | };
|
965 146 | Ok(response)
|
966 147 | };
|
967 148 | sender.send(()).await.expect("receiver dropped early");
|
968 149 | result
|
969 150 | }
|
970 151 | })
|
971 152 | .build_unchecked();
|
972 153 | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
973 154 | .await
|
974 155 | .expect("unable to make an HTTP request");
|
975 - | assert!(receiver.recv().await.is_some());
|
976 - | }
|
977 - | /// Upper case error modeled lower case.
|
978 - | /// Test ID: ServiceLevelErrorServer
|
979 - | #[::tokio::test]
|
980 - | async fn service_level_error_server_response() {
|
981 - | let output = crate::error::ExtraError {};
|
982 - | let output = crate::error::QueryPrecedenceError::ExtraError(output);
|
983 - | use ::aws_smithy_http_server::response::IntoResponse;
|
984 - | let http_response = output.into_response();
|
985 - | ::pretty_assertions::assert_eq!(
|
986 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
987 - | http_response.status()
|
156 + | assert!(
|
157 + | receiver.recv().await.is_some(),
|
158 + | "we expected operation handler to be invoked but it was not entered"
|
988 159 | );
|
989 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
990 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
991 - | http_response.headers(),
|
992 - | expected_headers,
|
993 - | ));
|
994 - | let body = ::hyper::body::to_bytes(http_response.into_body())
|
995 - | .await
|
996 - | .expect("unable to extract body to bytes");
|
997 - | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
998 - | &body,
|
999 - | "{}",
|
1000 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
1001 - | ));
|
1002 160 | }
|
1003 - | }
|
1004 - | #[cfg(test)]
|
1005 - | #[allow(unreachable_code, unused_variables)]
|
1006 - | mod server_status_response_test {
|
1007 - | /// Upper case error modeled lower case.
|
1008 - | /// Test ID: ServiceLevelErrorServer
|
161 + | /// Test ID: RestJsonStringPayloadResponse2
|
1009 162 | #[::tokio::test]
|
1010 - | async fn service_level_error_server_response() {
|
1011 - | let output = crate::error::ExtraError {};
|
1012 - | let output = crate::error::StatusResponseError::ExtraError(output);
|
163 + | #[::tracing_test::traced_test]
|
164 + | async fn rest_json_string_payload_response2_response() {
|
165 + | let output = crate::output::HttpStringPayload2Output {
|
166 + | payload: ::std::option::Option::Some("rawstring".to_owned()),
|
167 + | };
|
1013 168 | use ::aws_smithy_http_server::response::IntoResponse;
|
1014 169 | let http_response = output.into_response();
|
1015 170 | ::pretty_assertions::assert_eq!(
|
1016 - | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
171 + | http::StatusCode::from_u16(200).expect("invalid expected HTTP status code"),
|
1017 172 | http_response.status()
|
1018 173 | );
|
1019 - | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
174 + | let expected_headers = [("Content-Type", "text/plain")];
|
1020 175 | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
1021 176 | http_response.headers(),
|
1022 177 | expected_headers,
|
1023 178 | ));
|
1024 179 | let body = ::hyper::body::to_bytes(http_response.into_body())
|
1025 180 | .await
|
1026 181 | .expect("unable to extract body to bytes");
|
1027 182 | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
1028 183 | &body,
|
1029 - | "{}",
|
1030 - | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
184 + | "rawstring",
|
185 + | ::aws_smithy_protocol_test::MediaType::from("text/plain"),
|
1031 186 | ));
|
1032 187 | }
|
1033 - | }
|
1034 - | #[cfg(test)]
|
1035 - | #[allow(unreachable_code, unused_variables)]
|
1036 - | mod server_string_payload_test {
|
1037 - | /// Test ID: StringPayload
|
1038 - | #[::tokio::test]
|
1039 - | async fn string_payload_request() {
|
1040 - | #[allow(unused_mut)]
|
1041 - | let mut http_request = http::Request::builder()
|
1042 - | .uri("/StringPayload")
|
1043 - | .method("POST")
|
1044 - | .header("Content-Type", "text/plain")
|
1045 - | .body(::aws_smithy_http_server::body::Body::from(
|
1046 - | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
1047 - | ))
|
1048 - | .unwrap();
|
1049 - | #[allow(unused_mut)]
|
1050 - | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
1051 - | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
1052 - | let service =
|
1053 - | crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
1054 - | .string_payload(move |input: crate::input::StringPayloadInput| {
|
1055 - | let sender = sender.clone();
|
1056 - | async move {
|
1057 - | let result = {
|
1058 - | let expected = crate::input::StringPayloadInput {
|
1059 - | payload: ::std::option::Option::Some("rawstring".to_owned()),
|
1060 - | };
|
1061 - | ::pretty_assertions::assert_eq!(input, expected);
|
1062 - | let response = crate::output::StringPayloadOutput {
|
1063 - | payload: ::std::option::Option::None,
|
1064 - | };
|
1065 - | Ok(response)
|
1066 - | };
|
1067 - | sender.send(()).await.expect("receiver dropped early");
|
1068 - | result
|
1069 - | }
|
1070 - | })
|
1071 - | .build_unchecked();
|
1072 - | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
1073 - | .await
|
1074 - | .expect("unable to make an HTTP request");
|
1075 - | assert!(receiver.recv().await.is_some());
|
1076 - | }
|
1077 188 | /// Upper case error modeled lower case.
|
1078 189 | /// Test ID: ServiceLevelErrorServer
|
1079 190 | #[::tokio::test]
|
191 + | #[::tracing_test::traced_test]
|
1080 192 | async fn service_level_error_server_response() {
|
1081 193 | let output = crate::error::ExtraError {};
|
1082 - | let output = crate::error::StringPayloadError::ExtraError(output);
|
194 + | let output = crate::error::HttpStringPayload2Error::ExtraError(output);
|
1083 195 | use ::aws_smithy_http_server::response::IntoResponse;
|
1084 196 | let http_response = output.into_response();
|
1085 197 | ::pretty_assertions::assert_eq!(
|
1086 198 | http::StatusCode::from_u16(500).expect("invalid expected HTTP status code"),
|
1087 199 | http_response.status()
|
1088 200 | );
|
1089 201 | let expected_headers = [("X-Amzn-Errortype", "ExtraError")];
|
1090 202 | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
1091 203 | http_response.headers(),
|
1092 204 | expected_headers,
|
1093 205 | ));
|
1094 206 | let body = ::hyper::body::to_bytes(http_response.into_body())
|
1095 207 | .await
|
1096 208 | .expect("unable to extract body to bytes");
|
1097 209 | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_body(
|
1098 210 | &body,
|
1099 211 | "{}",
|
1100 212 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
1101 213 | ));
|
1102 214 | }
|
1103 - | }
|
1104 - |
|
1105 - | static CONTENT_TYPE_HTTPSTRINGPAYLOAD2: ::once_cell::sync::Lazy<::mime::Mime> =
|
1106 - | ::once_cell::sync::Lazy::new(|| {
|
1107 - | "text/plain"
|
1108 - | .parse::<::mime::Mime>()
|
1109 - | .expect("BUG: MIME parsing failed, content_type is not valid")
|
1110 - | });
|
1111 - | ::pin_project_lite::pin_project! {
|
1112 - | /// A [`Future`](std::future::Future) aggregating the body bytes of a [`Request`] and constructing the
|
1113 - | /// [`HttpStringPayload2Input`](crate::input::HttpStringPayload2Input) using modelled bindings.
|
1114 - | pub struct HttpStringPayload2InputFuture {
|
1115 - | inner: std::pin::Pin<Box<dyn std::future::Future<Output = Result<crate::input::HttpStringPayload2Input, ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError>> + Send>>
|
1116 - | }
|
1117 - | }
|
1118 - |
|
1119 - | impl std::future::Future for HttpStringPayload2InputFuture {
|
1120 - | type Output = Result<
|
1121 - | crate::input::HttpStringPayload2Input,
|
1122 - | ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError,
|
1123 - | >;
|
1124 - |
|
1125 - | fn poll(
|
1126 - | self: std::pin::Pin<&mut Self>,
|
1127 - | cx: &mut std::task::Context<'_>,
|
1128 - | ) -> std::task::Poll<Self::Output> {
|
1129 - | let this = self.project();
|
1130 - | this.inner.as_mut().poll(cx)
|
1131 - | }
|
1132 - | }
|
1133 - |
|
1134 - | impl<B>
|
1135 - | ::aws_smithy_http_server::request::FromRequest<
|
1136 - | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
1137 - | B,
|
1138 - | > for crate::input::HttpStringPayload2Input
|
1139 - | where
|
1140 - | B: ::aws_smithy_http_server::body::HttpBody + Send,
|
1141 - | B: 'static,
|
1142 - |
|
1143 - | B::Data: Send,
|
1144 - | ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection:
|
1145 - | From<<B as ::aws_smithy_http_server::body::HttpBody>::Error>,
|
1146 - | {
|
1147 - | type Rejection = ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError;
|
1148 - | type Future = HttpStringPayload2InputFuture;
|
1149 - |
|
1150 - | fn from_request(request: ::http::Request<B>) -> Self::Future {
|
1151 - | let fut = async move {
|
1152 - | if !::aws_smithy_http_server::protocol::accept_header_classifier(
|
1153 - | request.headers(),
|
1154 - | &CONTENT_TYPE_HTTPSTRINGPAYLOAD2,
|
1155 - | ) {
|
1156 - | return Err(::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection::NotAcceptable);
|
1157 - | }
|
1158 - | crate::protocol_serde::shape_http_string_payload2::de_http_string_payload2_http_request(
|
1159 - | request,
|
1160 - | )
|
1161 - | .await
|
1162 - | .map_err(Into::into)
|
1163 - | };
|
1164 - | use ::futures_util::future::TryFutureExt;
|
1165 - | let fut = fut.map_err(
|
1166 - | |e: ::aws_smithy_http_server::protocol::rest_json_1::rejection::RequestRejection| {
|
1167 - | ::tracing::debug!(error = %e, "failed to deserialize request");
|
1168 - | ::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(
|
1169 - | e,
|
1170 - | )
|
1171 - | },
|
1172 - | );
|
1173 - | HttpStringPayload2InputFuture {
|
1174 - | inner: Box::pin(fut),
|
215 + | /// Serializes a string in the HTTP payload without a content-type header
|
216 + | /// Test ID: RestJsonStringPayloadNoContentType2
|
217 + | #[::tokio::test]
|
218 + | #[::tracing_test::traced_test]
|
219 + | async fn rest_json_string_payload_no_content_type2_malformed_request() {
|
220 + | {
|
221 + | #[allow(unused_mut)]
|
222 + | let mut http_request = http::Request::builder()
|
223 + | .uri("/StringPayload2")
|
224 + | .method("POST")
|
225 + | .body(::aws_smithy_http_server::body::Body::from(
|
226 + | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
227 + | ))
|
228 + | .unwrap();
|
229 + | #[allow(unused_mut)]
|
230 + | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
231 + | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
232 + | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
233 + | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
234 + | let sender = sender.clone();
|
235 + | async move {
|
236 + | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
237 + | sender.send(()).await.expect("receiver dropped early");
|
238 + | result
|
239 + | }
|
240 + | })
|
241 + | .build_unchecked();
|
242 + | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
243 + | .await
|
244 + | .expect("unable to make an HTTP request");
|
245 + | ::pretty_assertions::assert_eq!(
|
246 + | http::StatusCode::from_u16(415).expect("invalid expected HTTP status code"),
|
247 + | http_response.status()
|
248 + | );
|
249 + | let expected_headers = [("x-amzn-errortype", "UnsupportedMediaTypeException")];
|
250 + | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
251 + | http_response.headers(),
|
252 + | expected_headers,
|
253 + | ));
|
1175 254 | }
|
1176 255 | }
|
1177 - | }
|
1178 - | impl
|
1179 - | ::aws_smithy_http_server::response::IntoResponse<
|
1180 - | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
1181 - | > for crate::output::HttpStringPayload2Output
|
1182 - | {
|
1183 - | fn into_response(self) -> ::aws_smithy_http_server::response::Response {
|
1184 - | match crate::protocol_serde::shape_http_string_payload2::ser_http_string_payload2_http_response(self) {
|
1185 - | Ok(response) => response,
|
1186 - | Err(e) => {
|
1187 - | ::tracing::error!(error = %e, "failed to serialize response");
|
1188 - | ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
|
1189 - | }
|
1190 - | }
|
256 + | /// Serializes a string in the HTTP payload without the expected content-type header
|
257 + | /// Test ID: RestJsonStringPayloadWrongContentType2
|
258 + | #[::tokio::test]
|
259 + | #[::tracing_test::traced_test]
|
260 + | async fn rest_json_string_payload_wrong_content_type2_malformed_request() {
|
261 + | {
|
262 + | #[allow(unused_mut)]
|
263 + | let mut http_request = http::Request::builder()
|
264 + | .uri("/StringPayload2")
|
265 + | .method("POST")
|
266 + | .header("Content-Type", "application/json")
|
267 + | .body(::aws_smithy_http_server::body::Body::from(
|
268 + | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
269 + | ))
|
270 + | .unwrap();
|
271 + | #[allow(unused_mut)]
|
272 + | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
273 + | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
274 + | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
275 + | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
276 + | let sender = sender.clone();
|
277 + | async move {
|
278 + | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
279 + | sender.send(()).await.expect("receiver dropped early");
|
280 + | result
|
281 + | }
|
282 + | })
|
283 + | .build_unchecked();
|
284 + | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
285 + | .await
|
286 + | .expect("unable to make an HTTP request");
|
287 + | ::pretty_assertions::assert_eq!(
|
288 + | http::StatusCode::from_u16(415).expect("invalid expected HTTP status code"),
|
289 + | http_response.status()
|
290 + | );
|
291 + | let expected_headers = [("x-amzn-errortype", "UnsupportedMediaTypeException")];
|
292 + | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
293 + | http_response.headers(),
|
294 + | expected_headers,
|
295 + | ));
|
296 + | }
|
1191 297 | }
|
1192 - | }
|
1193 - | impl
|
1194 - | ::aws_smithy_http_server::response::IntoResponse<
|
1195 - | ::aws_smithy_http_server::protocol::rest_json_1::RestJson1,
|
1196 - | > for crate::error::HttpStringPayload2Error
|
1197 - | {
|
1198 - | fn into_response(self) -> ::aws_smithy_http_server::response::Response {
|
1199 - | match crate::protocol_serde::shape_http_string_payload2::ser_http_string_payload2_http_error(
|
1200 - | &self,
|
1201 - | ) {
|
1202 - | Ok(mut response) => {
|
1203 - | response.extensions_mut().insert(
|
1204 - | ::aws_smithy_http_server::extension::ModeledErrorExtension::new(self.name()),
|
1205 - | );
|
1206 - | response
|
1207 - | }
|
1208 - | Err(e) => {
|
1209 - | ::tracing::error!(error = %e, "failed to serialize response");
|
1210 - | ::aws_smithy_http_server::response::IntoResponse::<::aws_smithy_http_server::protocol::rest_json_1::RestJson1>::into_response(::aws_smithy_http_server::protocol::rest_json_1::runtime_error::RuntimeError::from(e))
|
1211 - | }
|
298 + | /// Serializes a string in the HTTP payload with an unstatisfiable accept header
|
299 + | /// Test ID: RestJsonStringPayloadUnsatisfiableAccept2
|
300 + | #[::tokio::test]
|
301 + | #[::tracing_test::traced_test]
|
302 + | async fn rest_json_string_payload_unsatisfiable_accept2_malformed_request() {
|
303 + | {
|
304 + | #[allow(unused_mut)]
|
305 + | let mut http_request = http::Request::builder()
|
306 + | .uri("/StringPayload2")
|
307 + | .method("POST")
|
308 + | .header("Accept", "application/json")
|
309 + | .header("Content-Type", "text/plain")
|
310 + | .body(::aws_smithy_http_server::body::Body::from(
|
311 + | ::bytes::Bytes::from_static("rawstring".as_bytes()),
|
312 + | ))
|
313 + | .unwrap();
|
314 + | #[allow(unused_mut)]
|
315 + | let (sender, mut receiver) = ::tokio::sync::mpsc::channel(1);
|
316 + | let config = crate::service::RestJsonExtrasConfig::builder().build();
|
317 + | let service = crate::service::RestJsonExtras::builder::<::hyper::body::Body, _, _, _>(config)
|
318 + | .http_string_payload2(move |input: crate::input::HttpStringPayload2Input| {
|
319 + | let sender = sender.clone();
|
320 + | async move {
|
321 + | let result = { panic!("request should have been rejected, but we accepted it; we parsed operation input `{:?}`", &input) as Result<crate::output::HttpStringPayload2Output, crate::error::HttpStringPayload2Error> };
|
322 + | sender.send(()).await.expect("receiver dropped early");
|
323 + | result
|
324 + | }
|
325 + | })
|
326 + | .build_unchecked();
|
327 + | let http_response = ::tower::ServiceExt::oneshot(service, http_request)
|
328 + | .await
|
329 + | .expect("unable to make an HTTP request");
|
330 + | ::pretty_assertions::assert_eq!(
|
331 + | http::StatusCode::from_u16(406).expect("invalid expected HTTP status code"),
|
332 + | http_response.status()
|
333 + | );
|
334 + | let expected_headers = [("x-amzn-errortype", "NotAcceptableException")];
|
335 + | ::aws_smithy_protocol_test::assert_ok(::aws_smithy_protocol_test::validate_headers(
|
336 + | http_response.headers(),
|
337 + | expected_headers,
|
338 + | ));
|
1212 339 | }
|
1213 340 | }
|
1214 341 | }
|
1215 342 |
|
1216 343 | static CONTENT_TYPE_HTTPENUMPAYLOAD2: ::once_cell::sync::Lazy<::mime::Mime> =
|
1217 344 | ::once_cell::sync::Lazy::new(|| {
|
1218 345 | "text/plain"
|
1219 346 | .parse::<::mime::Mime>()
|
1220 347 | .expect("BUG: MIME parsing failed, content_type is not valid")
|
1221 348 | });
|