AWS SDK

AWS SDK

rev. 163d4d6410694aaf071424777ecbecd050925f36

Files changed:

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-runtime/src/client/orchestrator/operation.rs

@@ -67,67 +126,127 @@
   87     87   
}
   88     88   
impl<F, O, E> DeserializeResponse for FnDeserializer<F, O, E>
   89     89   
where
   90     90   
    F: Fn(&HttpResponse) -> Result<O, OrchestratorError<E>> + Send + Sync,
   91     91   
    O: fmt::Debug + Send + Sync + 'static,
   92     92   
    E: std::error::Error + fmt::Debug + Send + Sync + 'static,
   93     93   
{
   94     94   
    fn deserialize_nonstreaming(
   95     95   
        &self,
   96     96   
        response: &HttpResponse,
          97  +
        _cfg: &ConfigBag,
   97     98   
    ) -> Result<Output, OrchestratorError<Error>> {
   98     99   
        (self.f)(response)
   99    100   
            .map(|output| Output::erase(output))
  100    101   
            .map_err(|err| err.map_operation_error(Error::erase))
  101    102   
    }
  102    103   
}
  103    104   
impl<F, O, E> fmt::Debug for FnDeserializer<F, O, E> {
  104    105   
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  105    106   
        write!(f, "FnDeserializer")
  106    107   
    }

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-runtime/src/client/test_util/deserializer.rs

@@ -1,1 +54,55 @@
    1      1   
/*
    2      2   
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
    3      3   
 * SPDX-License-Identifier: Apache-2.0
    4      4   
 */
    5      5   
    6      6   
use aws_smithy_runtime_api::client::interceptors::context::{Error, Output};
    7      7   
use aws_smithy_runtime_api::client::orchestrator::{HttpResponse, OrchestratorError};
    8      8   
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
    9      9   
use aws_smithy_runtime_api::client::ser_de::{DeserializeResponse, SharedResponseDeserializer};
   10         -
use aws_smithy_types::config_bag::{FrozenLayer, Layer};
          10  +
use aws_smithy_types::config_bag::{ConfigBag, FrozenLayer, Layer};
   11     11   
use std::sync::Mutex;
   12     12   
   13     13   
/// Test response deserializer that always returns the same canned response.
   14     14   
#[derive(Default, Debug)]
   15     15   
pub struct CannedResponseDeserializer {
   16     16   
    inner: Mutex<Option<Result<Output, OrchestratorError<Error>>>>,
   17     17   
}
   18     18   
   19     19   
impl CannedResponseDeserializer {
   20     20   
    /// Creates a new `CannedResponseDeserializer` with the given canned response.
   21     21   
    pub fn new(output: Result<Output, OrchestratorError<Error>>) -> Self {
   22     22   
        Self {
   23     23   
            inner: Mutex::new(Some(output)),
   24     24   
        }
   25     25   
    }
   26     26   
   27     27   
    fn take(&self) -> Option<Result<Output, OrchestratorError<Error>>> {
   28     28   
        match self.inner.lock() {
   29     29   
            Ok(mut guard) => guard.take(),
   30     30   
            Err(_) => None,
   31     31   
        }
   32     32   
    }
   33     33   
}
   34     34   
   35     35   
impl DeserializeResponse for CannedResponseDeserializer {
   36     36   
    fn deserialize_nonstreaming(
   37     37   
        &self,
   38     38   
        _response: &HttpResponse,
          39  +
        _cfg: &ConfigBag,
   39     40   
    ) -> Result<Output, OrchestratorError<Error>> {
   40     41   
        self.take()
   41     42   
            .ok_or("CannedResponseDeserializer's inner value has already been taken.")
   42     43   
            .unwrap()
   43     44   
    }
   44     45   
}
   45     46   
   46     47   
impl RuntimePlugin for CannedResponseDeserializer {
   47     48   
    fn config(&self) -> Option<FrozenLayer> {
   48     49   
        let mut cfg = Layer::new("CannedResponse");

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-runtime/tests/retries.rs

@@ -73,73 +132,133 @@
   93     93   
    service: impl Into<String>,
   94     94   
    max_attempts: usize,
   95     95   
    http_client: impl Into<SharedHttpClient>,
   96     96   
) -> (Operation<(), String, Infallible>, OperationState) {
   97     97   
    #[derive(Debug)]
   98     98   
    struct Deserializer;
   99     99   
    impl DeserializeResponse for Deserializer {
  100    100   
        fn deserialize_nonstreaming(
  101    101   
            &self,
  102    102   
            resp: &HttpResponse,
         103  +
            _cfg: &ConfigBag,
  103    104   
        ) -> Result<Output, OrchestratorError<Error>> {
  104    105   
            if resp.status().is_success() {
  105    106   
                Ok(Output::erase("output".to_owned()))
  106    107   
            } else {
  107    108   
                Err(OrchestratorError::connector(ConnectorError::io(
  108    109   
                    "mock connector error".into(),
  109    110   
                )))
  110    111   
            }
  111    112   
        }
  112    113   
    }

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-runtime/tests/stalled_stream_common.rs

@@ -15,15 +75,76 @@
   35     35   
        orchestrator::{HttpRequest, HttpResponse, OrchestratorError},
   36     36   
        result::SdkError,
   37     37   
        runtime_components::RuntimeComponents,
   38     38   
        ser_de::DeserializeResponse,
   39     39   
        stalled_stream_protection::StalledStreamProtectionConfig,
   40     40   
    },
   41     41   
    http::{Response, StatusCode},
   42     42   
    shared::IntoShared,
   43     43   
};
   44     44   
pub use aws_smithy_types::{
   45         -
    body::SdkBody, error::display::DisplayErrorContext, timeout::TimeoutConfig,
          45  +
    body::SdkBody, config_bag::ConfigBag, error::display::DisplayErrorContext,
          46  +
    timeout::TimeoutConfig,
   46     47   
};
   47     48   
pub use bytes::Bytes;
   48     49   
pub use pin_utils::pin_mut;
   49     50   
pub use std::{
   50     51   
    collections::VecDeque,
   51     52   
    convert::Infallible,
   52     53   
    future::poll_fn,
   53     54   
    mem,
   54     55   
    pin::Pin,
   55     56   
    sync::{Arc, Mutex},

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-runtime/tests/stalled_stream_download.rs

@@ -264,264 +323,324 @@
  284    284   
                response: &mut HttpResponse,
  285    285   
            ) -> Option<Result<Output, OrchestratorError<Error>>> {
  286    286   
                let mut body = SdkBody::taken();
  287    287   
                mem::swap(response.body_mut(), &mut body);
  288    288   
                Some(Ok(Output::erase(body)))
  289    289   
            }
  290    290   
  291    291   
            fn deserialize_nonstreaming(
  292    292   
                &self,
  293    293   
                _: &HttpResponse,
         294  +
                _cfg: &ConfigBag,
  294    295   
            ) -> Result<Output, OrchestratorError<Error>> {
  295    296   
                unreachable!()
  296    297   
            }
  297    298   
        }
  298    299   
  299    300   
        Operation::builder()
  300    301   
            .service_name("test")
  301    302   
            .operation_name("test")
  302    303   
            .http_client(FakeServer(http_connector.into_shared()))
  303    304   
            .endpoint_url("http://localhost:1234/doesntmatter")

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/Cargo.toml

@@ -1,1 +24,33 @@
    9      9   
repository = "https://github.com/smithy-lang/smithy-rs"
   10     10   
rust-version = "1.91"
   11     11   
[package.metadata.docs.rs]
   12     12   
all-features = true
   13     13   
targets = ["x86_64-unknown-linux-gnu"]
   14     14   
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
   15     15   
rustdoc-args = ["--cfg", "docsrs"]
   16     16   
   17     17   
[package.metadata.smithy-rs-release-tooling]
   18     18   
stable = true
          19  +
          20  +
[dependencies]
          21  +
http = "1.3.1"
          22  +
          23  +
[dependencies.aws-smithy-runtime-api]
          24  +
path = "../aws-smithy-runtime-api"
          25  +
features = ["client", "http-02x"]
          26  +
version = "1.11.7"
          27  +
   19     28   
[dependencies.aws-smithy-types]
   20     29   
path = "../aws-smithy-types"
   21     30   
default-features = false
   22     31   
version = "1.4.7"
   23     32   
   24     33   
[dev-dependencies]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/external-types.toml

@@ -1,1 +3,5 @@
    1      1   
allowed_external_types = [
           2  +
    "aws_smithy_runtime_api::http::request::Request",
           3  +
    "aws_smithy_runtime_api::http::response::Response",
    2      4   
    "aws_smithy_types::*",
    3      5   
]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/lib.rs

@@ -1,1 +165,179 @@
   13     13   
//! enabling protocol-agnostic serialization and deserialization.
   14     14   
   15     15   
mod schema {
   16     16   
    pub mod shape_id;
   17     17   
    pub mod shape_type;
   18     18   
    pub mod trait_map;
   19     19   
    pub mod trait_type;
   20     20   
    pub mod traits;
   21     21   
   22     22   
    pub mod codec;
          23  +
    pub mod http_protocol;
   23     24   
    pub mod prelude;
          25  +
    pub mod protocol;
   24     26   
    pub mod serde;
   25     27   
}
   26     28   
   27     29   
pub use schema::shape_id::ShapeId;
   28     30   
pub use schema::shape_type::ShapeType;
   29     31   
pub use schema::trait_map::TraitMap;
   30     32   
pub use schema::trait_type::Trait;
   31     33   
pub use schema::trait_type::{AnnotationTrait, DocumentTrait, StringTrait};
   32     34   
   33     35   
pub mod prelude {
   34     36   
    pub use crate::schema::prelude::*;
   35     37   
}
   36     38   
   37     39   
pub mod serde {
   38     40   
    pub use crate::schema::serde::*;
   39     41   
}
   40     42   
   41     43   
pub mod traits {
   42     44   
    pub use crate::schema::traits::*;
   43     45   
}
   44     46   
   45     47   
pub mod codec {
   46     48   
    pub use crate::schema::codec::*;
   47     49   
}
   48     50   
          51  +
pub mod protocol {
          52  +
    pub use crate::schema::protocol::*;
          53  +
}
          54  +
          55  +
pub mod http_protocol {
          56  +
    pub use crate::schema::http_protocol::*;
          57  +
}
          58  +
   49     59   
/// A Smithy schema — a lightweight runtime representation of a Smithy shape.
   50     60   
///
   51     61   
/// Contains the shape's ID, type, traits relevant to serialization, and
   52     62   
/// references to member schemas (for aggregate types).
   53     63   
///
   54     64   
/// Schemas are constructed at compile time (via `const`) for generated code
   55     65   
/// and prelude types. The Smithy type system is closed, so no extensibility
   56     66   
/// via trait objects is needed.
   57     67   
use schema::traits as trait_types;
   58     68   
   59     69   
#[derive(Debug)]
   60     70   
pub struct Schema {
   61     71   
    id: ShapeId,
   62     72   
    shape_type: ShapeType,
   63     73   
    /// Member name if this is a member schema.
   64     74   
    member_name: Option<&'static str>,
   65     75   
    /// Member index for position-based lookup in generated code.
   66     76   
    member_index: Option<usize>,
   67     77   
    /// Shape-type-specific member data.
   68     78   
    members: SchemaMembers,
   69     79   
   70     80   
    // -- Known serde trait fields (const-constructable) --
   71     81   
    // IMPORTANT: These fields and their `with_*` setters must stay in sync with
   72     82   
    // `knownTraitSetter` in `SchemaGenerator.kt`. If a new known trait is added
   73     83   
    // here, a corresponding entry must be added in the codegen.
   74     84   
    sensitive: Option<trait_types::SensitiveTrait>,
   75     85   
    json_name: Option<trait_types::JsonNameTrait>,
   76     86   
    timestamp_format: Option<trait_types::TimestampFormatTrait>,
   77     87   
    xml_name: Option<trait_types::XmlNameTrait>,
   78     88   
    xml_attribute: Option<trait_types::XmlAttributeTrait>,
   79     89   
    xml_flattened: Option<trait_types::XmlFlattenedTrait>,
   80     90   
    xml_namespace: Option<trait_types::XmlNamespaceTrait>,
   81     91   
    http_header: Option<trait_types::HttpHeaderTrait>,
   82     92   
    http_label: Option<trait_types::HttpLabelTrait>,
   83     93   
    http_payload: Option<trait_types::HttpPayloadTrait>,
   84     94   
    http_prefix_headers: Option<trait_types::HttpPrefixHeadersTrait>,
   85     95   
    http_query: Option<trait_types::HttpQueryTrait>,
   86     96   
    http_query_params: Option<trait_types::HttpQueryParamsTrait>,
   87     97   
    http_response_code: Option<trait_types::HttpResponseCodeTrait>,
          98  +
    /// The `@http` trait — an operation-level trait included on the input schema
          99  +
    /// for convenience so the protocol serializer can construct the request URI.
         100  +
    http: Option<trait_types::HttpTrait>,
   88    101   
    streaming: Option<trait_types::StreamingTrait>,
   89    102   
    event_header: Option<trait_types::EventHeaderTrait>,
   90    103   
    event_payload: Option<trait_types::EventPayloadTrait>,
   91    104   
    host_label: Option<trait_types::HostLabelTrait>,
   92    105   
    media_type: Option<trait_types::MediaTypeTrait>,
   93    106   
   94    107   
    /// Fallback for unknown/custom traits. `None` in const contexts (no allocation).
   95    108   
    traits: Option<&'static std::sync::LazyLock<TraitMap>>,
   96    109   
}
   97    110   
   98    111   
/// Shape-type-specific member references.
   99    112   
#[derive(Debug)]
  100    113   
enum SchemaMembers {
  101    114   
    /// No members (simple types).
  102    115   
    None,
  103    116   
    /// Structure or union members.
  104    117   
    Struct { members: &'static [&'static Schema] },
  105    118   
    /// List member schema.
  106    119   
    List { member: &'static Schema },
  107    120   
    /// Map key and value schemas.
  108    121   
    Map {
  109    122   
        key: &'static Schema,
  110    123   
        value: &'static Schema,
  111    124   
    },
  112    125   
}
  113    126   
  114    127   
impl Schema {
  115    128   
    /// Default values for all trait fields (should only be used by constructors as a spread source).
  116    129   
    const EMPTY_TRAITS: Self = Self {
  117    130   
        id: ShapeId::from_static("", "", ""),
  118    131   
        shape_type: ShapeType::Boolean,
  119    132   
        member_name: None,
  120    133   
        member_index: None,
  121    134   
        members: SchemaMembers::None,
  122    135   
        sensitive: None,
  123    136   
        json_name: None,
  124    137   
        timestamp_format: None,
  125    138   
        xml_name: None,
  126    139   
        xml_attribute: None,
  127    140   
        xml_flattened: None,
  128    141   
        xml_namespace: None,
  129    142   
        http_header: None,
  130    143   
        http_label: None,
  131    144   
        http_payload: None,
  132    145   
        http_prefix_headers: None,
  133    146   
        http_query: None,
  134    147   
        http_query_params: None,
  135    148   
        http_response_code: None,
         149  +
        http: None,
  136    150   
        streaming: None,
  137    151   
        event_header: None,
  138    152   
        event_payload: None,
  139    153   
        host_label: None,
  140    154   
        media_type: None,
  141    155   
        traits: None,
  142    156   
    };
  143    157   
  144    158   
    /// Creates a schema for a simple type (no members).
  145    159   
    pub const fn new(id: ShapeId, shape_type: ShapeType) -> Self {
@@ -211,225 +279,335 @@
  231    245   
    pub fn timestamp_format(&self) -> Option<&trait_types::TimestampFormatTrait> {
  232    246   
        self.timestamp_format.as_ref()
  233    247   
    }
  234    248   
  235    249   
    /// Returns the `@xmlName` value if present.
  236    250   
    pub fn xml_name(&self) -> Option<&trait_types::XmlNameTrait> {
  237    251   
        self.xml_name.as_ref()
  238    252   
    }
  239    253   
  240    254   
    /// Returns the `@httpHeader` value if present.
         255  +
    /// Returns `true` if this member schema has any HTTP response binding trait
         256  +
    /// (`@httpHeader`, `@httpResponseCode`, `@httpPrefixHeaders`, or `@httpPayload`).
         257  +
    pub fn has_http_response_binding(&self) -> bool {
         258  +
        self.http_header.is_some()
         259  +
            || self.http_response_code.is_some()
         260  +
            || self.http_prefix_headers.is_some()
         261  +
            || self.http_payload.is_some()
         262  +
    }
         263  +
  241    264   
    pub fn http_header(&self) -> Option<&trait_types::HttpHeaderTrait> {
  242    265   
        self.http_header.as_ref()
  243    266   
    }
  244    267   
  245    268   
    /// Returns the `@httpQuery` value if present.
  246    269   
    pub fn http_query(&self) -> Option<&trait_types::HttpQueryTrait> {
  247    270   
        self.http_query.as_ref()
  248    271   
    }
  249    272   
         273  +
    /// Returns the `@httpLabel` trait if present.
         274  +
    pub fn http_label(&self) -> Option<&trait_types::HttpLabelTrait> {
         275  +
        self.http_label.as_ref()
         276  +
    }
         277  +
         278  +
    /// Returns the `@httpPayload` trait if present.
         279  +
    pub fn http_payload(&self) -> Option<&trait_types::HttpPayloadTrait> {
         280  +
        self.http_payload.as_ref()
         281  +
    }
         282  +
         283  +
    /// Returns the `@httpPrefixHeaders` value if present.
         284  +
    pub fn http_prefix_headers(&self) -> Option<&trait_types::HttpPrefixHeadersTrait> {
         285  +
        self.http_prefix_headers.as_ref()
         286  +
    }
         287  +
         288  +
    /// Returns the `@httpQueryParams` trait if present.
         289  +
    pub fn http_query_params(&self) -> Option<&trait_types::HttpQueryParamsTrait> {
         290  +
        self.http_query_params.as_ref()
         291  +
    }
         292  +
         293  +
    /// Returns the `@httpResponseCode` trait if present.
         294  +
    pub fn http_response_code(&self) -> Option<&trait_types::HttpResponseCodeTrait> {
         295  +
        self.http_response_code.as_ref()
         296  +
    }
         297  +
         298  +
    /// Returns the `@http` trait if present.
         299  +
    ///
         300  +
    /// This is an operation-level trait included on the input schema for
         301  +
    /// convenience so the protocol serializer can construct the request URI.
         302  +
    pub fn http(&self) -> Option<&trait_types::HttpTrait> {
         303  +
        self.http.as_ref()
         304  +
    }
         305  +
  250    306   
    // -- Const setters for builder-style construction in generated code --
  251    307   
  252    308   
    /// Sets the `@sensitive` trait.
  253    309   
    pub const fn with_sensitive(mut self) -> Self {
  254    310   
        self.sensitive = Some(trait_types::SensitiveTrait);
  255    311   
        self
  256    312   
    }
  257    313   
  258    314   
    /// Sets the `@jsonName` trait.
  259    315   
    pub const fn with_json_name(mut self, value: &'static str) -> Self {
@@ -300,356 +359,421 @@
  320    376   
        self.http_query_params = Some(trait_types::HttpQueryParamsTrait);
  321    377   
        self
  322    378   
    }
  323    379   
  324    380   
    /// Sets the `@httpResponseCode` trait.
  325    381   
    pub const fn with_http_response_code(mut self) -> Self {
  326    382   
        self.http_response_code = Some(trait_types::HttpResponseCodeTrait);
  327    383   
        self
  328    384   
    }
  329    385   
         386  +
    /// Sets the `@http` trait (operation-level, included on input schema for convenience).
         387  +
    pub const fn with_http(mut self, http: trait_types::HttpTrait) -> Self {
         388  +
        self.http = Some(http);
         389  +
        self
         390  +
    }
         391  +
  330    392   
    /// Sets the `@streaming` trait.
  331    393   
    pub const fn with_streaming(mut self) -> Self {
  332    394   
        self.streaming = Some(trait_types::StreamingTrait);
  333    395   
        self
  334    396   
    }
  335    397   
  336    398   
    /// Sets the `@eventHeader` trait.
  337    399   
    pub const fn with_event_header(mut self) -> Self {
  338    400   
        self.event_header = Some(trait_types::EventHeaderTrait);
  339    401   
        self

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/codec.rs

@@ -1,1 +105,120 @@
    5      5   
    6      6   
//! Codec trait for creating shape serializers and deserializers.
    7      7   
//!
    8      8   
//! A codec represents a specific serialization format (e.g., JSON, XML, CBOR)
    9      9   
//! and provides methods to create serializers and deserializers for that format.
   10     10   
   11     11   
pub mod http_string;
   12     12   
   13     13   
use crate::serde::{ShapeDeserializer, ShapeSerializer};
   14     14   
          15  +
/// Trait for serializers that can produce a final byte output.
          16  +
///
          17  +
/// This is separate from [`ShapeSerializer`] to preserve object safety on
          18  +
/// `ShapeSerializer` (which is used as `&mut dyn ShapeSerializer` in generated code).
          19  +
pub trait FinishSerializer {
          20  +
    /// Consumes the serializer and returns the serialized bytes.
          21  +
    fn finish(self) -> Vec<u8>;
          22  +
}
          23  +
   15     24   
/// A codec for a specific serialization format.
   16     25   
///
   17     26   
/// Codecs are responsible for creating [`ShapeSerializer`] and [`ShapeDeserializer`]
   18     27   
/// instances that can serialize and deserialize shapes to and from a specific format.
   19     28   
///
   20     29   
/// # Examples
   21     30   
///
   22     31   
/// Implementing a custom codec:
   23     32   
///
   24     33   
/// ```ignore
   25     34   
/// use aws_smithy_schema::codec::Codec;
   26     35   
/// use aws_smithy_schema::serde::{ShapeSerializer, ShapeDeserializer};
   27     36   
///
   28     37   
/// struct MyCodec {
   29     38   
///     // codec configuration
   30     39   
/// }
   31     40   
///
   32     41   
/// impl Codec for MyCodec {
   33     42   
///     type Serializer = MySerializer;
   34     43   
///     type Deserializer = MyDeserializer;
   35     44   
///
   36     45   
///     fn create_serializer(&self) -> Self::Serializer {
   37     46   
///         MySerializer::new()
   38     47   
///     }
   39     48   
///
   40     49   
///     fn create_deserializer(&self, input: &[u8]) -> Self::Deserializer {
   41     50   
///         MyDeserializer::new(input)
   42     51   
///     }
   43     52   
/// }
   44     53   
/// ```
   45     54   
pub trait Codec {
   46     55   
    /// The serializer type for this codec.
   47         -
    type Serializer: ShapeSerializer;
          56  +
    type Serializer: ShapeSerializer + FinishSerializer;
   48     57   
   49     58   
    /// The deserializer type for this codec.
   50     59   
    type Deserializer<'a>: ShapeDeserializer;
   51     60   
   52     61   
    /// Creates a new serializer for this codec.
   53     62   
    fn create_serializer(&self) -> Self::Serializer;
   54     63   
   55     64   
    /// Creates a new deserializer for this codec from the given input bytes.
   56     65   
    fn create_deserializer<'a>(&self, input: &'a [u8]) -> Self::Deserializer<'a>;
   57     66   
}
   58     67   
   59     68   
#[cfg(test)]
   60     69   
mod test {
   61     70   
    use super::*;
   62     71   
    use crate::serde::{SerdeError, SerializableStruct, ShapeDeserializer, ShapeSerializer};
   63     72   
    use crate::{prelude::*, Schema};
   64     73   
   65     74   
    // Mock serializer
   66     75   
    struct MockSerializer {
   67     76   
        output: Vec<u8>,
   68     77   
    }
   69     78   
   70     79   
    impl MockSerializer {
   71     80   
        fn finish(self) -> Vec<u8> {
   72     81   
            self.output
   73     82   
        }
   74     83   
    }
   75     84   
          85  +
    impl FinishSerializer for MockSerializer {
          86  +
        fn finish(self) -> Vec<u8> {
          87  +
            self.output
          88  +
        }
          89  +
    }
          90  +
   76     91   
    impl ShapeSerializer for MockSerializer {
   77     92   
        fn write_struct(
   78     93   
            &mut self,
   79     94   
            _schema: &Schema,
   80     95   
            _value: &dyn SerializableStruct,
   81     96   
        ) -> Result<(), SerdeError> {
   82     97   
            Ok(())
   83     98   
        }
   84     99   
   85    100   
        fn write_list(
@@ -155,170 +248,254 @@
  175    190   
        }
  176    191   
    }
  177    192   
  178    193   
    // Mock deserializer
  179    194   
    struct MockDeserializer<'a> {
  180    195   
        #[allow(dead_code)]
  181    196   
        input: &'a [u8],
  182    197   
    }
  183    198   
  184    199   
    impl<'a> ShapeDeserializer for MockDeserializer<'a> {
  185         -
        fn read_struct<T, F>(
         200  +
        fn read_struct(
  186    201   
            &mut self,
  187    202   
            _schema: &Schema,
  188         -
            state: T,
  189         -
            _consumer: F,
  190         -
        ) -> Result<T, SerdeError>
  191         -
        where
  192         -
            F: FnMut(T, &Schema, &mut Self) -> Result<T, SerdeError>,
  193         -
        {
  194         -
            Ok(state)
         203  +
            _consumer: &mut dyn FnMut(
         204  +
                &Schema,
         205  +
                &mut dyn ShapeDeserializer,
         206  +
            ) -> Result<(), SerdeError>,
         207  +
        ) -> Result<(), SerdeError> {
         208  +
            Ok(())
  195    209   
        }
  196    210   
  197         -
        fn read_list<T, F>(
         211  +
        fn read_list(
  198    212   
            &mut self,
  199    213   
            _schema: &Schema,
  200         -
            state: T,
  201         -
            _consumer: F,
  202         -
        ) -> Result<T, SerdeError>
  203         -
        where
  204         -
            F: FnMut(T, &mut Self) -> Result<T, SerdeError>,
  205         -
        {
  206         -
            Ok(state)
         214  +
            _consumer: &mut dyn FnMut(&mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         215  +
        ) -> Result<(), SerdeError> {
         216  +
            Ok(())
  207    217   
        }
  208    218   
  209         -
        fn read_map<T, F>(
         219  +
        fn read_map(
  210    220   
            &mut self,
  211    221   
            _schema: &Schema,
  212         -
            state: T,
  213         -
            _consumer: F,
  214         -
        ) -> Result<T, SerdeError>
  215         -
        where
  216         -
            F: FnMut(T, String, &mut Self) -> Result<T, SerdeError>,
  217         -
        {
  218         -
            Ok(state)
         222  +
            _consumer: &mut dyn FnMut(String, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         223  +
        ) -> Result<(), SerdeError> {
         224  +
            Ok(())
  219    225   
        }
  220    226   
  221    227   
        fn read_boolean(&mut self, _schema: &Schema) -> Result<bool, SerdeError> {
  222    228   
            Ok(false)
  223    229   
        }
  224    230   
  225    231   
        fn read_byte(&mut self, _schema: &Schema) -> Result<i8, SerdeError> {
  226    232   
            Ok(0)
  227    233   
        }
  228    234   

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/codec/http_string.rs

@@ -1,1 +60,66 @@
   21     21   
            output: String::new(),
   22     22   
        }
   23     23   
    }
   24     24   
   25     25   
    /// Finalizes the serialization and returns the output string.
   26     26   
    pub fn finish(self) -> String {
   27     27   
        self.output
   28     28   
    }
   29     29   
}
   30     30   
          31  +
impl super::FinishSerializer for HttpStringSerializer {
          32  +
    fn finish(self) -> Vec<u8> {
          33  +
        self.output.into_bytes()
          34  +
    }
          35  +
}
          36  +
   31     37   
impl Default for HttpStringSerializer {
   32     38   
    fn default() -> Self {
   33     39   
        Self::new()
   34     40   
    }
   35     41   
}
   36     42   
   37     43   
impl ShapeSerializer for HttpStringSerializer {
   38     44   
    fn write_struct(
   39     45   
        &mut self,
   40     46   
        _schema: &Schema,
@@ -220,226 +306,310 @@
  240    246   
            Some(&self.input[start..])
  241    247   
        }
  242    248   
    }
  243    249   
  244    250   
    fn current_value(&self) -> &str {
  245    251   
        &self.input[self.position..]
  246    252   
    }
  247    253   
}
  248    254   
  249    255   
impl<'a> ShapeDeserializer for HttpStringDeserializer<'a> {
  250         -
    fn read_struct<T, F>(
         256  +
    fn read_struct(
  251    257   
        &mut self,
  252    258   
        _schema: &Schema,
  253         -
        _state: T,
  254         -
        _consumer: F,
  255         -
    ) -> Result<T, SerdeError>
  256         -
    where
  257         -
        F: FnMut(T, &Schema, &mut Self) -> Result<T, SerdeError>,
  258         -
    {
         259  +
        _consumer: &mut dyn FnMut(&Schema, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         260  +
    ) -> Result<(), SerdeError> {
  259    261   
        Err(SerdeError::UnsupportedOperation {
  260    262   
            message: "structures cannot be deserialized from strings".into(),
  261    263   
        })
  262    264   
    }
  263    265   
  264         -
    fn read_list<T, F>(&mut self, _schema: &Schema, state: T, _consumer: F) -> Result<T, SerdeError>
  265         -
    where
  266         -
        F: FnMut(T, &mut Self) -> Result<T, SerdeError>,
  267         -
    {
         266  +
    fn read_list(
         267  +
        &mut self,
         268  +
        _schema: &Schema,
         269  +
        _consumer: &mut dyn FnMut(&mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         270  +
    ) -> Result<(), SerdeError> {
  268    271   
        // Lists are comma-separated values
  269    272   
        // The consumer will call read methods for each element
  270         -
        Ok(state)
         273  +
        Ok(())
  271    274   
    }
  272    275   
  273         -
    fn read_map<T, F>(&mut self, _schema: &Schema, _state: T, _consumer: F) -> Result<T, SerdeError>
  274         -
    where
  275         -
        F: FnMut(T, String, &mut Self) -> Result<T, SerdeError>,
  276         -
    {
         276  +
    fn read_map(
         277  +
        &mut self,
         278  +
        _schema: &Schema,
         279  +
        _consumer: &mut dyn FnMut(String, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         280  +
    ) -> Result<(), SerdeError> {
  277    281   
        Err(SerdeError::UnsupportedOperation {
  278    282   
            message: "maps cannot be deserialized from strings".into(),
  279    283   
        })
  280    284   
    }
  281    285   
  282    286   
    fn read_boolean(&mut self, _schema: &Schema) -> Result<bool, SerdeError> {
  283    287   
        let value = self.next_value().ok_or_else(|| SerdeError::InvalidInput {
  284    288   
            message: "expected boolean value".into(),
  285    289   
        })?;
  286    290   
        value.parse().map_err(|_| SerdeError::InvalidInput {

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/http_protocol.rs

@@ -0,1 +0,31 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! HTTP-based client protocol implementations.
           7  +
//!
           8  +
//! This module provides two concrete protocol types that implement [`crate::schema::protocol::ClientProtocol`]
           9  +
//! for HTTP transports:
          10  +
//!
          11  +
//! - [`HttpBindingProtocol`] — for REST-style protocols (e.g., `restJson1`, `restXml`)
          12  +
//!   that split members across HTTP headers, query strings, URI labels, and the payload.
          13  +
//! - [`HttpRpcProtocol`] — for RPC-style protocols (e.g., `awsJson1_0`, `rpcv2Cbor`)
          14  +
//!   that put everything in the body and ignore HTTP bindings.
          15  +
//!
          16  +
//! # Protocol hierarchy
          17  +
//!
          18  +
//! ```text
          19  +
//! ClientProtocol
          20  +
//!   ├─ HttpBindingProtocol<C>   (REST: restJson, restXml)
          21  +
//!   └─ HttpRpcProtocol<C>       (RPC: awsJson, rpcv2Cbor)
          22  +
//! ```
          23  +
//!
          24  +
//! Concrete protocol types like `AwsRestJsonProtocol` are thin wrappers that
          25  +
//! construct one of these with the appropriate codec and settings.
          26  +
          27  +
mod binding;
          28  +
mod rpc;
          29  +
          30  +
pub use binding::{percent_encode, HttpBindingProtocol};
          31  +
pub use rpc::HttpRpcProtocol;

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-schema/src/schema/http_protocol/binding.rs

@@ -0,1 +0,1717 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! HTTP binding protocol for REST-style APIs.
           7  +
           8  +
use crate::codec::{Codec, FinishSerializer};
           9  +
use crate::protocol::ClientProtocol;
          10  +
use crate::serde::{SerdeError, SerializableStruct, ShapeDeserializer, ShapeSerializer};
          11  +
use crate::{Schema, ShapeId};
          12  +
use aws_smithy_runtime_api::http::{Request, Response};
          13  +
use aws_smithy_types::body::SdkBody;
          14  +
use aws_smithy_types::config_bag::ConfigBag;
          15  +
          16  +
/// An HTTP protocol for REST-style APIs that use HTTP bindings.
          17  +
///
          18  +
/// This protocol splits input members between HTTP locations (headers, query
          19  +
/// strings, URI labels) and the payload based on HTTP binding traits
          20  +
/// (`@httpHeader`, `@httpQuery`, `@httpLabel`, `@httpPayload`, etc.).
          21  +
/// Non-bound members are serialized into the body using the provided codec.
          22  +
///
          23  +
/// # Type parameters
          24  +
///
          25  +
/// * `C` — the payload codec (e.g., `JsonCodec`, `XmlCodec`)
          26  +
#[derive(Debug)]
          27  +
pub struct HttpBindingProtocol<C> {
          28  +
    protocol_id: ShapeId,
          29  +
    codec: C,
          30  +
    content_type: &'static str,
          31  +
}
          32  +
          33  +
impl<C: Codec> HttpBindingProtocol<C> {
          34  +
    /// Creates a new HTTP binding protocol.
          35  +
    pub fn new(protocol_id: ShapeId, codec: C, content_type: &'static str) -> Self {
          36  +
        Self {
          37  +
            protocol_id,
          38  +
            codec,
          39  +
            content_type,
          40  +
        }
          41  +
    }
          42  +
}
          43  +
          44  +
// Note: there is a percent_encoding crate we use some other places for this, but I'm trying to keep
          45  +
// the dependencies to a minimum.
          46  +
/// Percent-encode a string per RFC 3986 section 2.3 (unreserved characters only).
          47  +
pub fn percent_encode(input: &str) -> String {
          48  +
    let mut out = String::with_capacity(input.len());
          49  +
    for byte in input.bytes() {
          50  +
        match byte {
          51  +
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
          52  +
                out.push(byte as char);
          53  +
            }
          54  +
            _ => {
          55  +
                out.push('%');
          56  +
                out.push(char::from(HEX[(byte >> 4) as usize]));
          57  +
                out.push(char::from(HEX[(byte & 0x0f) as usize]));
          58  +
            }
          59  +
        }
          60  +
    }
          61  +
    out
          62  +
}
          63  +
          64  +
pub(crate) const HEX: &[u8; 16] = b"0123456789ABCDEF";
          65  +
          66  +
/// A ShapeSerializer that intercepts member writes and routes HTTP-bound
          67  +
/// members to headers, query params, or URI labels instead of the body.
          68  +
///
          69  +
/// Members without HTTP binding traits are forwarded to the inner body
          70  +
/// serializer unchanged.
          71  +
struct HttpBindingSerializer<'a, S> {
          72  +
    body: S,
          73  +
    headers: Vec<(String, String)>,
          74  +
    query_params: Vec<(String, String)>,
          75  +
    labels: Vec<(String, String)>,
          76  +
    /// When set, member schemas are resolved from this schema by name to find
          77  +
    /// HTTP binding traits. This allows the protocol to override bindings
          78  +
    /// (e.g., for presigning where body members become query params).
          79  +
    input_schema: Option<&'a Schema>,
          80  +
    /// True for the top-level input struct in serialize_request.
          81  +
    /// Cleared after the first write_struct so nested structs delegate directly.
          82  +
    is_top_level: bool,
          83  +
    /// Tracks whether any member was written to the body serializer (i.e., a member
          84  +
    /// without an HTTP binding trait). Used by `HttpBindingProtocol` to determine
          85  +
    /// whether to wrap the body in `{}` and set `Content-Type: application/json`.
          86  +
    /// Per the REST-JSON spec, operations with no body members must send an empty
          87  +
    /// body with no Content-Type header.
          88  +
    has_body_content: bool,
          89  +
    /// Raw payload bytes for `@httpPayload` blob/string members. When a member
          90  +
    /// has `@httpPayload` and targets a blob or string, the raw bytes bypass
          91  +
    /// the codec serializer entirely and are used as the HTTP body directly.
          92  +
    /// Safety: the referenced bytes are borrowed from the input struct passed to
          93  +
    /// `serialize_request`, which outlives this serializer.
          94  +
    raw_payload: Option<&'a [u8]>,
          95  +
}
          96  +
          97  +
impl<'a, S> HttpBindingSerializer<'a, S> {
          98  +
    fn new(body: S, input_schema: Option<&'a Schema>) -> Self {
          99  +
        Self {
         100  +
            body,
         101  +
            headers: Vec::new(),
         102  +
            query_params: Vec::new(),
         103  +
            labels: Vec::new(),
         104  +
            input_schema,
         105  +
            is_top_level: true,
         106  +
            has_body_content: false,
         107  +
            raw_payload: None,
         108  +
        }
         109  +
    }
         110  +
         111  +
    /// Finish serialization and return only the body bytes, discarding
         112  +
    /// any collected headers/query/labels.
         113  +
    fn finish_body(self) -> Vec<u8>
         114  +
    where
         115  +
        S: FinishSerializer,
         116  +
    {
         117  +
        if let Some(payload) = self.raw_payload {
         118  +
            payload.to_vec()
         119  +
        } else {
         120  +
            self.body.finish()
         121  +
        }
         122  +
    }
         123  +
         124  +
    /// Resolve the effective member schema: if an input_schema override is set,
         125  +
    /// look up the member by name there (to get the correct HTTP bindings).
         126  +
    /// Otherwise use the schema as-is.
         127  +
    fn resolve_member<'s>(&self, schema: &'s Schema) -> &'s Schema
         128  +
    where
         129  +
        'a: 's,
         130  +
    {
         131  +
        if let (Some(input_schema), Some(name)) = (self.input_schema, schema.member_name()) {
         132  +
            input_schema.member_schema(name).unwrap_or(schema)
         133  +
        } else {
         134  +
            schema
         135  +
        }
         136  +
    }
         137  +
}
         138  +
         139  +
/// Helper: format a value as a string for HTTP binding serialization.
         140  +
fn value_to_string<T: std::fmt::Display>(value: T) -> String {
         141  +
    value.to_string()
         142  +
}
         143  +
         144  +
impl<'a, S: ShapeSerializer> ShapeSerializer for HttpBindingSerializer<'a, S> {
         145  +
    fn write_struct(
         146  +
        &mut self,
         147  +
        schema: &Schema,
         148  +
        value: &dyn SerializableStruct,
         149  +
    ) -> Result<(), SerdeError> {
         150  +
        if self.is_top_level {
         151  +
            // Top-level input struct: route serialize_members through the binder
         152  +
            // so HTTP-bound members are intercepted. The body serializer's
         153  +
            // write_struct is used for framing (e.g., { } for JSON), with a
         154  +
            // proxy whose serialize_members delegates back to the binder.
         155  +
            struct Proxy<'a, 'b, S> {
         156  +
                binder: &'a mut HttpBindingSerializer<'b, S>,
         157  +
                value: &'a dyn SerializableStruct,
         158  +
            }
         159  +
            impl<S: ShapeSerializer> SerializableStruct for Proxy<'_, '_, S> {
         160  +
                fn serialize_members(
         161  +
                    &self,
         162  +
                    _serializer: &mut dyn ShapeSerializer,
         163  +
                ) -> Result<(), SerdeError> {
         164  +
                    let binder = self.binder as *const HttpBindingSerializer<'_, S>
         165  +
                        as *mut HttpBindingSerializer<'_, S>;
         166  +
                    // SAFETY: The body serializer called serialize_members on
         167  +
                    // this proxy, passing &mut self (body). The binder wraps
         168  +
                    // that same body serializer. We need mutable access to the
         169  +
                    // binder to route writes. This is safe because:
         170  +
                    // 1. The body serializer's write_struct only calls
         171  +
                    //    serialize_members once, synchronously.
         172  +
                    // 2. Body member writes from the binder go back to the
         173  +
                    //    body serializer, which is in a valid state (between
         174  +
                    //    the { and } it emitted).
         175  +
                    self.value.serialize_members(unsafe { &mut *binder })
         176  +
                }
         177  +
            }
         178  +
            // Clear is_top_level so nested write_struct calls (from body members)
         179  +
            // take the else branch and delegate directly to the body serializer.
         180  +
            // input_schema is preserved so resolve_member continues to work.
         181  +
            self.is_top_level = false;
         182  +
            let proxy = Proxy {
         183  +
                binder: self,
         184  +
                value,
         185  +
            };
         186  +
            let binder_ptr = &mut *proxy.binder as *mut HttpBindingSerializer<'_, S>;
         187  +
            // SAFETY: `proxy` holds a shared reference to `binder` (via &mut that
         188  +
            // we reborrow). We need to call `binder.body.write_struct(schema, &proxy)`
         189  +
            // but can't do so through normal references because `proxy` borrows `binder`.
         190  +
            // The raw pointer dereference is safe because:
         191  +
            // 1. `binder_ptr` points to a valid, live `HttpBindingSerializer` (it was
         192  +
            //    just derived from `proxy.binder`).
         193  +
            // 2. `body.write_struct` is called synchronously and returns before `proxy`
         194  +
            //    is dropped, so the binder is not moved or deallocated.
         195  +
            // 3. The only re-entrant access is through `proxy.serialize_members`, which
         196  +
            //    uses the same raw-pointer pattern with its own safety justification above.
         197  +
            unsafe { (*binder_ptr).body.write_struct(schema, &proxy) }
         198  +
        } else {
         199  +
            // Nested struct (a body member targeting a structure): delegate
         200  +
            // entirely to the body serializer.
         201  +
            let schema = self.resolve_member(schema);
         202  +
            if schema.http_payload().is_some() {
         203  +
                // @httpPayload struct/union: write as the body's top-level object
         204  +
                // without a member name prefix. Use a non-member schema for the
         205  +
                // write_struct call so prefix() doesn't emit a field name.
         206  +
                self.has_body_content = true;
         207  +
                self.body.write_struct(&crate::prelude::DOCUMENT, value)?;
         208  +
                return Ok(());
         209  +
            }
         210  +
            self.has_body_content = true;
         211  +
            self.body.write_struct(schema, value)
         212  +
        }
         213  +
    }
         214  +
         215  +
    fn write_list(
         216  +
        &mut self,
         217  +
        schema: &Schema,
         218  +
        write_elements: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         219  +
    ) -> Result<(), SerdeError> {
         220  +
        self.has_body_content = true;
         221  +
        self.body.write_list(schema, write_elements)
         222  +
    }
         223  +
         224  +
    fn write_map(
         225  +
        &mut self,
         226  +
        schema: &Schema,
         227  +
        write_entries: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         228  +
    ) -> Result<(), SerdeError> {
         229  +
        let schema = self.resolve_member(schema);
         230  +
        // @httpPrefixHeaders: serialize map entries as prefixed headers
         231  +
        if let Some(prefix) = schema.http_prefix_headers() {
         232  +
            // Collect entries via a temporary serializer
         233  +
            let mut collector = MapEntryCollector::new(prefix.value().to_string());
         234  +
            write_entries(&mut collector)?;
         235  +
            self.headers.extend(collector.entries);
         236  +
            return Ok(());
         237  +
        }
         238  +
        // @httpQueryParams: serialize map entries as query params
         239  +
        if schema.http_query_params().is_some() {
         240  +
            let mut collector = MapEntryCollector::new(String::new());
         241  +
            write_entries(&mut collector)?;
         242  +
            for (k, v) in collector.entries {
         243  +
                self.query_params.push((k, v));
         244  +
            }
         245  +
            return Ok(());
         246  +
        }
         247  +
        self.has_body_content = true;
         248  +
        self.body.write_map(schema, write_entries)
         249  +
    }
         250  +
         251  +
    fn write_boolean(&mut self, schema: &Schema, value: bool) -> Result<(), SerdeError> {
         252  +
        let schema = self.resolve_member(schema);
         253  +
        if let Some(binding) = http_string_binding(schema) {
         254  +
            return self.add_binding(binding, schema, &value_to_string(value));
         255  +
        }
         256  +
        self.has_body_content = true;
         257  +
        self.body.write_boolean(schema, value)
         258  +
    }
         259  +
         260  +
    fn write_byte(&mut self, schema: &Schema, value: i8) -> Result<(), SerdeError> {
         261  +
        let schema = self.resolve_member(schema);
         262  +
        if let Some(binding) = http_string_binding(schema) {
         263  +
            return self.add_binding(binding, schema, &value_to_string(value));
         264  +
        }
         265  +
        self.has_body_content = true;
         266  +
        self.body.write_byte(schema, value)
         267  +
    }
         268  +
         269  +
    fn write_short(&mut self, schema: &Schema, value: i16) -> Result<(), SerdeError> {
         270  +
        let schema = self.resolve_member(schema);
         271  +
        if let Some(binding) = http_string_binding(schema) {
         272  +
            return self.add_binding(binding, schema, &value_to_string(value));
         273  +
        }
         274  +
        self.has_body_content = true;
         275  +
        self.body.write_short(schema, value)
         276  +
    }
         277  +
         278  +
    fn write_integer(&mut self, schema: &Schema, value: i32) -> Result<(), SerdeError> {
         279  +
        let schema = self.resolve_member(schema);
         280  +
        if let Some(binding) = http_string_binding(schema) {
         281  +
            return self.add_binding(binding, schema, &value_to_string(value));
         282  +
        }
         283  +
        self.has_body_content = true;
         284  +
        self.body.write_integer(schema, value)
         285  +
    }
         286  +
         287  +
    fn write_long(&mut self, schema: &Schema, value: i64) -> Result<(), SerdeError> {
         288  +
        let schema = self.resolve_member(schema);
         289  +
        if let Some(binding) = http_string_binding(schema) {
         290  +
            return self.add_binding(binding, schema, &value_to_string(value));
         291  +
        }
         292  +
        self.has_body_content = true;
         293  +
        self.body.write_long(schema, value)
         294  +
    }
         295  +
         296  +
    fn write_float(&mut self, schema: &Schema, value: f32) -> Result<(), SerdeError> {
         297  +
        let schema = self.resolve_member(schema);
         298  +
        if let Some(binding) = http_string_binding(schema) {
         299  +
            return self.add_binding(binding, schema, &value_to_string(value));
         300  +
        }
         301  +
        self.has_body_content = true;
         302  +
        self.body.write_float(schema, value)
         303  +
    }
         304  +
         305  +
    fn write_double(&mut self, schema: &Schema, value: f64) -> Result<(), SerdeError> {
         306  +
        let schema = self.resolve_member(schema);
         307  +
        if let Some(binding) = http_string_binding(schema) {
         308  +
            return self.add_binding(binding, schema, &value_to_string(value));
         309  +
        }
         310  +
        self.has_body_content = true;
         311  +
        self.body.write_double(schema, value)
         312  +
    }
         313  +
         314  +
    fn write_big_integer(
         315  +
        &mut self,
         316  +
        schema: &Schema,
         317  +
        value: &aws_smithy_types::BigInteger,
         318  +
    ) -> Result<(), SerdeError> {
         319  +
        let schema = self.resolve_member(schema);
         320  +
        if let Some(binding) = http_string_binding(schema) {
         321  +
            return self.add_binding(binding, schema, value.as_ref());
         322  +
        }
         323  +
        self.has_body_content = true;
         324  +
        self.body.write_big_integer(schema, value)
         325  +
    }
         326  +
         327  +
    fn write_big_decimal(
         328  +
        &mut self,
         329  +
        schema: &Schema,
         330  +
        value: &aws_smithy_types::BigDecimal,
         331  +
    ) -> Result<(), SerdeError> {
         332  +
        let schema = self.resolve_member(schema);
         333  +
        if let Some(binding) = http_string_binding(schema) {
         334  +
            return self.add_binding(binding, schema, value.as_ref());
         335  +
        }
         336  +
        self.has_body_content = true;
         337  +
        self.body.write_big_decimal(schema, value)
         338  +
    }
         339  +
         340  +
    fn write_string(&mut self, schema: &Schema, value: &str) -> Result<(), SerdeError> {
         341  +
        let schema = self.resolve_member(schema);
         342  +
        if let Some(binding) = http_string_binding(schema) {
         343  +
            return self.add_binding(binding, schema, value);
         344  +
        }
         345  +
        if schema.http_payload().is_some() {
         346  +
            // SAFETY: We extend the lifetime of `value.as_bytes()` from its anonymous
         347  +
            // lifetime to `'a`. This is sound because:
         348  +
            // 1. `value` is borrowed from the input struct passed to `serialize_request`.
         349  +
            // 2. `HttpBindingSerializer` is a local variable within `serialize_request`
         350  +
            //    and is dropped before `serialize_request` returns.
         351  +
            // 3. The input struct (and thus `value`) outlives the serializer.
         352  +
            // 4. `raw_payload` is read in `serialize_request` immediately after
         353  +
            //    `serialize_members` returns, before the input is dropped.
         354  +
            // We use transmute rather than copying to avoid allocating for potentially
         355  +
            // multi-GB string payloads.
         356  +
            self.raw_payload =
         357  +
                Some(unsafe { std::mem::transmute::<&[u8], &'a [u8]>(value.as_bytes()) });
         358  +
            return Ok(());
         359  +
        }
         360  +
        self.has_body_content = true;
         361  +
        self.body.write_string(schema, value)
         362  +
    }
         363  +
         364  +
    fn write_blob(
         365  +
        &mut self,
         366  +
        schema: &Schema,
         367  +
        value: &aws_smithy_types::Blob,
         368  +
    ) -> Result<(), SerdeError> {
         369  +
        let schema = self.resolve_member(schema);
         370  +
        if schema.http_header().is_some() {
         371  +
            let encoded = aws_smithy_types::base64::encode(value.as_ref());
         372  +
            self.headers
         373  +
                .push((schema.http_header().unwrap().value().to_string(), encoded));
         374  +
            return Ok(());
         375  +
        }
         376  +
        if schema.http_payload().is_some() {
         377  +
            // SAFETY: We extend the lifetime of `value.as_ref()` (a `&[u8]`) from its
         378  +
            // anonymous lifetime to `'a`. This is sound because:
         379  +
            // 1. `value` is borrowed from the input struct passed to `serialize_request`.
         380  +
            // 2. `HttpBindingSerializer` is a local variable within `serialize_request`
         381  +
            //    and is dropped before `serialize_request` returns.
         382  +
            // 3. The input struct (and thus `value`) outlives the serializer.
         383  +
            // 4. `raw_payload` is read in `serialize_request` immediately after
         384  +
            //    `serialize_members` returns, before the input is dropped.
         385  +
            // We use transmute rather than copying to avoid allocating for potentially
         386  +
            // multi-GB blob payloads.
         387  +
            self.raw_payload =
         388  +
                Some(unsafe { std::mem::transmute::<&[u8], &'a [u8]>(value.as_ref()) });
         389  +
            return Ok(());
         390  +
        }
         391  +
        self.has_body_content = true;
         392  +
        self.body.write_blob(schema, value)
         393  +
    }
         394  +
         395  +
    fn write_timestamp(
         396  +
        &mut self,
         397  +
        schema: &Schema,
         398  +
        value: &aws_smithy_types::DateTime,
         399  +
    ) -> Result<(), SerdeError> {
         400  +
        let schema = self.resolve_member(schema);
         401  +
        if let Some(binding) = http_string_binding(schema) {
         402  +
            // Headers default to http-date, query/label default to date-time
         403  +
            let format = if schema.timestamp_format().is_some() {
         404  +
                match schema.timestamp_format().unwrap().format() {
         405  +
                    crate::traits::TimestampFormat::EpochSeconds => {
         406  +
                        aws_smithy_types::date_time::Format::EpochSeconds
         407  +
                    }
         408  +
                    crate::traits::TimestampFormat::HttpDate => {
         409  +
                        aws_smithy_types::date_time::Format::HttpDate
         410  +
                    }
         411  +
                    crate::traits::TimestampFormat::DateTime => {
         412  +
                        aws_smithy_types::date_time::Format::DateTime
         413  +
                    }
         414  +
                }
         415  +
            } else {
         416  +
                match binding {
         417  +
                    HttpBinding::Header(_) => aws_smithy_types::date_time::Format::HttpDate,
         418  +
                    _ => aws_smithy_types::date_time::Format::DateTime,
         419  +
                }
         420  +
            };
         421  +
            let formatted = value
         422  +
                .fmt(format)
         423  +
                .map_err(|e| SerdeError::custom(format!("failed to format timestamp: {e}")))?;
         424  +
            return self.add_binding(binding, schema, &formatted);
         425  +
        }
         426  +
        self.has_body_content = true;
         427  +
        self.body.write_timestamp(schema, value)
         428  +
    }
         429  +
         430  +
    fn write_document(
         431  +
        &mut self,
         432  +
        schema: &Schema,
         433  +
        value: &aws_smithy_types::Document,
         434  +
    ) -> Result<(), SerdeError> {
         435  +
        self.has_body_content = true;
         436  +
        self.body.write_document(schema, value)
         437  +
    }
         438  +
         439  +
    fn write_null(&mut self, schema: &Schema) -> Result<(), SerdeError> {
         440  +
        self.has_body_content = true;
         441  +
        self.body.write_null(schema)
         442  +
    }
         443  +
}
         444  +
         445  +
/// Which HTTP location a member is bound to.
         446  +
enum HttpBinding<'a> {
         447  +
    Header(&'a str),
         448  +
    Query(&'a str),
         449  +
    Label,
         450  +
}
         451  +
         452  +
/// Determine the HTTP binding for a member schema, if any.
         453  +
fn http_string_binding(schema: &Schema) -> Option<HttpBinding<'_>> {
         454  +
    if let Some(h) = schema.http_header() {
         455  +
        return Some(HttpBinding::Header(h.value()));
         456  +
    }
         457  +
    if let Some(q) = schema.http_query() {
         458  +
        return Some(HttpBinding::Query(q.value()));
         459  +
    }
         460  +
    if schema.http_label().is_some() {
         461  +
        return Some(HttpBinding::Label);
         462  +
    }
         463  +
    None
         464  +
}
         465  +
         466  +
impl<'a, S> HttpBindingSerializer<'a, S> {
         467  +
    fn add_binding(
         468  +
        &mut self,
         469  +
        binding: HttpBinding<'_>,
         470  +
        schema: &Schema,
         471  +
        value: &str,
         472  +
    ) -> Result<(), SerdeError> {
         473  +
        match binding {
         474  +
            HttpBinding::Header(name) => {
         475  +
                self.headers.push((name.to_string(), value.to_string()));
         476  +
            }
         477  +
            HttpBinding::Query(name) => {
         478  +
                self.query_params
         479  +
                    .push((name.to_string(), value.to_string()));
         480  +
            }
         481  +
            HttpBinding::Label => {
         482  +
                let name = schema
         483  +
                    .member_name()
         484  +
                    .ok_or_else(|| SerdeError::custom("httpLabel on non-member schema"))?;
         485  +
                self.labels.push((name.to_string(), value.to_string()));
         486  +
            }
         487  +
        }
         488  +
        Ok(())
         489  +
    }
         490  +
}
         491  +
         492  +
/// Collects map key-value pairs written via ShapeSerializer for
         493  +
/// @httpPrefixHeaders and @httpQueryParams.
         494  +
struct MapEntryCollector {
         495  +
    prefix: String,
         496  +
    entries: Vec<(String, String)>,
         497  +
    pending_key: Option<String>,
         498  +
}
         499  +
         500  +
impl MapEntryCollector {
         501  +
    fn new(prefix: String) -> Self {
         502  +
        Self {
         503  +
            prefix,
         504  +
            entries: Vec::new(),
         505  +
            pending_key: None,
         506  +
        }
         507  +
    }
         508  +
}
         509  +
         510  +
impl ShapeSerializer for MapEntryCollector {
         511  +
    fn write_string(&mut self, _schema: &Schema, value: &str) -> Result<(), SerdeError> {
         512  +
        if let Some(key) = self.pending_key.take() {
         513  +
            self.entries
         514  +
                .push((format!("{}{}", self.prefix, key), value.to_string()));
         515  +
        } else {
         516  +
            self.pending_key = Some(value.to_string());
         517  +
        }
         518  +
        Ok(())
         519  +
    }
         520  +
         521  +
    // All other methods are no-ops — maps in HTTP bindings only have string keys/values.
         522  +
    fn write_struct(&mut self, _: &Schema, _: &dyn SerializableStruct) -> Result<(), SerdeError> {
         523  +
        Ok(())
         524  +
    }
         525  +
    fn write_list(
         526  +
        &mut self,
         527  +
        _: &Schema,
         528  +
        _: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         529  +
    ) -> Result<(), SerdeError> {
         530  +
        Ok(())
         531  +
    }
         532  +
    fn write_map(
         533  +
        &mut self,
         534  +
        _: &Schema,
         535  +
        _: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         536  +
    ) -> Result<(), SerdeError> {
         537  +
        Ok(())
         538  +
    }
         539  +
    fn write_boolean(&mut self, _: &Schema, _: bool) -> Result<(), SerdeError> {
         540  +
        Ok(())
         541  +
    }
         542  +
    fn write_byte(&mut self, _: &Schema, _: i8) -> Result<(), SerdeError> {
         543  +
        Ok(())
         544  +
    }
         545  +
    fn write_short(&mut self, _: &Schema, _: i16) -> Result<(), SerdeError> {
         546  +
        Ok(())
         547  +
    }
         548  +
    fn write_integer(&mut self, _: &Schema, _: i32) -> Result<(), SerdeError> {
         549  +
        Ok(())
         550  +
    }
         551  +
    fn write_long(&mut self, _: &Schema, _: i64) -> Result<(), SerdeError> {
         552  +
        Ok(())
         553  +
    }
         554  +
    fn write_float(&mut self, _: &Schema, _: f32) -> Result<(), SerdeError> {
         555  +
        Ok(())
         556  +
    }
         557  +
    fn write_double(&mut self, _: &Schema, _: f64) -> Result<(), SerdeError> {
         558  +
        Ok(())
         559  +
    }
         560  +
    fn write_big_integer(
         561  +
        &mut self,
         562  +
        _: &Schema,
         563  +
        _: &aws_smithy_types::BigInteger,
         564  +
    ) -> Result<(), SerdeError> {
         565  +
        Ok(())
         566  +
    }
         567  +
    fn write_big_decimal(
         568  +
        &mut self,
         569  +
        _: &Schema,
         570  +
        _: &aws_smithy_types::BigDecimal,
         571  +
    ) -> Result<(), SerdeError> {
         572  +
        Ok(())
         573  +
    }
         574  +
    fn write_blob(&mut self, _: &Schema, _: &aws_smithy_types::Blob) -> Result<(), SerdeError> {
         575  +
        Ok(())
         576  +
    }
         577  +
    fn write_timestamp(
         578  +
        &mut self,
         579  +
        _: &Schema,
         580  +
        _: &aws_smithy_types::DateTime,
         581  +
    ) -> Result<(), SerdeError> {
         582  +
        Ok(())
         583  +
    }
         584  +
    fn write_document(
         585  +
        &mut self,
         586  +
        _: &Schema,
         587  +
        _: &aws_smithy_types::Document,
         588  +
    ) -> Result<(), SerdeError> {
         589  +
        Ok(())
         590  +
    }
         591  +
    fn write_null(&mut self, _: &Schema) -> Result<(), SerdeError> {
         592  +
        Ok(())
         593  +
    }
         594  +
}
         595  +
         596  +
impl<C> ClientProtocol for HttpBindingProtocol<C>
         597  +
where
         598  +
    C: Codec + Send + Sync + std::fmt::Debug + 'static,
         599  +
    for<'a> C::Deserializer<'a>: ShapeDeserializer,
         600  +
{
         601  +
    fn protocol_id(&self) -> &ShapeId {
         602  +
        &self.protocol_id
         603  +
    }
         604  +
         605  +
    fn supports_http_bindings(&self) -> bool {
         606  +
        true
         607  +
    }
         608  +
         609  +
    fn serialize_request(
         610  +
        &self,
         611  +
        input: &dyn SerializableStruct,
         612  +
        input_schema: &Schema,
         613  +
        endpoint: &str,
         614  +
        _cfg: &ConfigBag,
         615  +
    ) -> Result<Request, SerdeError> {
         616  +
        let mut binder =
         617  +
            HttpBindingSerializer::new(self.codec.create_serializer(), Some(input_schema));
         618  +
         619  +
        // Check if there's an @httpPayload member targeting a structure/union.
         620  +
        // In that case, the payload member's own write_struct provides the body
         621  +
        // framing, so we must not add top-level struct framing.
         622  +
        let has_struct_payload = input_schema.members().iter().any(|m| {
         623  +
            m.http_payload().is_some()
         624  +
                && matches!(
         625  +
                    m.shape_type(),
         626  +
                    crate::ShapeType::Structure | crate::ShapeType::Union
         627  +
                )
         628  +
        });
         629  +
        if has_struct_payload {
         630  +
            binder.is_top_level = false;
         631  +
            input.serialize_members(&mut binder)?;
         632  +
        } else {
         633  +
            binder.write_struct(input_schema, input)?;
         634  +
        }
         635  +
        let raw_payload = binder.raw_payload;
         636  +
        let mut body = if raw_payload.is_some() {
         637  +
            // @httpPayload blob/string — don't use the codec output
         638  +
            Vec::new()
         639  +
        } else {
         640  +
            binder.body.finish()
         641  +
        };
         642  +
         643  +
        // Per the REST-JSON content-type handling spec:
         644  +
        // - If @httpPayload targets a blob/string: send raw bytes, no Content-Type when empty
         645  +
        // - If body members exist (even if all optional and unset): send `{}` with Content-Type
         646  +
        // - If no body members at all (everything is in headers/query/labels): empty body, no Content-Type
         647  +
        let has_blob_or_string_payload = raw_payload.is_some();
         648  +
        let has_body_members = input_schema.members().iter().any(|m| {
         649  +
            m.http_header().is_none()
         650  +
                && m.http_query().is_none()
         651  +
                && m.http_label().is_none()
         652  +
                && m.http_prefix_headers().is_none()
         653  +
                && m.http_query_params().is_none()
         654  +
        });
         655  +
         656  +
        let set_content_type = if has_blob_or_string_payload {
         657  +
            // Blob/string payload: only set Content-Type if there's actual content
         658  +
            raw_payload.is_some_and(|p| !p.is_empty())
         659  +
        } else if has_body_members {
         660  +
            // Operation has body members — body includes framing (e.g., `{}`).
         661  +
            // Per the REST-JSON spec, even if all members are optional and unset, send `{}`.
         662  +
            true
         663  +
        } else {
         664  +
            // No body members at all — empty body, no Content-Type.
         665  +
            body = Vec::new();
         666  +
            false
         667  +
        };
         668  +
         669  +
        // Build URI: use @http trait if available (with label substitution from binder),
         670  +
        // otherwise fall back to endpoint with manual label substitution.
         671  +
        let mut uri = match input_schema.http() {
         672  +
            Some(h) => {
         673  +
                let mut path = h.uri().to_string();
         674  +
                for (name, value) in &binder.labels {
         675  +
                    let placeholder = format!("{{{name}}}");
         676  +
                    path = path.replace(&placeholder, &percent_encode(value));
         677  +
                }
         678  +
                if endpoint.is_empty() {
         679  +
                    path
         680  +
                } else {
         681  +
                    format!("{}{}", endpoint, path)
         682  +
                }
         683  +
            }
         684  +
            None => {
         685  +
                let mut u = if endpoint.is_empty() {
         686  +
                    "/".to_string()
         687  +
                } else {
         688  +
                    endpoint.to_string()
         689  +
                };
         690  +
                for (name, value) in &binder.labels {
         691  +
                    let placeholder = format!("{{{name}}}");
         692  +
                    u = u.replace(&placeholder, &percent_encode(value));
         693  +
                }
         694  +
                u
         695  +
            }
         696  +
        };
         697  +
        if !binder.query_params.is_empty() {
         698  +
            uri.push(if uri.contains('?') { '&' } else { '?' });
         699  +
            let pairs: Vec<String> = binder
         700  +
                .query_params
         701  +
                .iter()
         702  +
                .map(|(k, v)| format!("{}={}", percent_encode(k), percent_encode(v)))
         703  +
                .collect();
         704  +
            uri.push_str(&pairs.join("&"));
         705  +
        }
         706  +
         707  +
        let mut request = if let Some(payload) = raw_payload {
         708  +
            Request::new(SdkBody::from(payload))
         709  +
        } else {
         710  +
            Request::new(SdkBody::from(body))
         711  +
        };
         712  +
        // Set HTTP method from @http trait
         713  +
        if let Some(http) = input_schema.http() {
         714  +
            request
         715  +
                .set_method(http.method())
         716  +
                .map_err(|e| SerdeError::custom(format!("invalid HTTP method: {e}")))?;
         717  +
        }
         718  +
        request
         719  +
            .set_uri(uri.as_str())
         720  +
            .map_err(|e| SerdeError::custom(format!("invalid endpoint URI: {e}")))?;
         721  +
        if set_content_type {
         722  +
            request
         723  +
                .headers_mut()
         724  +
                .insert("Content-Type", self.content_type);
         725  +
        }
         726  +
        if let Some(len) = request.body().content_length() {
         727  +
            if len > 0 || set_content_type {
         728  +
                request
         729  +
                    .headers_mut()
         730  +
                    .insert("Content-Length", len.to_string());
         731  +
            }
         732  +
        }
         733  +
        for (name, value) in &binder.headers {
         734  +
            request.headers_mut().insert(name.clone(), value.clone());
         735  +
        }
         736  +
        Ok(request)
         737  +
    }
         738  +
         739  +
    fn deserialize_response<'a>(
         740  +
        &self,
         741  +
        response: &'a Response,
         742  +
        _output_schema: &Schema,
         743  +
        _cfg: &ConfigBag,
         744  +
    ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError> {
         745  +
        let body = response
         746  +
            .body()
         747  +
            .bytes()
         748  +
            .ok_or_else(|| SerdeError::custom("response body is not available as bytes"))?;
         749  +
        Ok(Box::new(self.codec.create_deserializer(body)))
         750  +
    }
         751  +
         752  +
    fn serialize_body(
         753  +
        &self,
         754  +
        input: &dyn SerializableStruct,
         755  +
        input_schema: &Schema,
         756  +
        _endpoint: &str,
         757  +
        _cfg: &ConfigBag,
         758  +
    ) -> Result<Request, SerdeError> {
         759  +
        // Check if there are body members (non-HTTP-bound) to determine Content-Type and body behavior.
         760  +
        let has_body_members = input_schema.members().iter().any(|m| {
         761  +
            m.http_header().is_none()
         762  +
                && m.http_query().is_none()
         763  +
                && m.http_label().is_none()
         764  +
                && m.http_prefix_headers().is_none()
         765  +
                && m.http_query_params().is_none()
         766  +
                && m.http_payload().is_none()
         767  +
        });
         768  +
         769  +
        // Use HttpBindingSerializer to filter out HTTP-bound members, keeping only body members.
         770  +
        // The collected headers/query/labels are discarded — the caller writes those directly.
         771  +
        let mut request = if has_body_members {
         772  +
            let serializer = self.codec.create_serializer();
         773  +
            let mut binding_ser = HttpBindingSerializer::new(serializer, None);
         774  +
            binding_ser.write_struct(input_schema, input)?;
         775  +
            let body = binding_ser.finish_body();
         776  +
            let mut r = Request::new(SdkBody::from(body));
         777  +
            r.headers_mut().insert("Content-Type", self.content_type);
         778  +
            if let Some(len) = r.body().content_length() {
         779  +
                r.headers_mut().insert("Content-Length", len.to_string());
         780  +
            }
         781  +
            r
         782  +
        } else {
         783  +
            Request::new(SdkBody::empty())
         784  +
        };
         785  +
         786  +
        // Set HTTP method from @http trait.
         787  +
        if let Some(http) = input_schema.http() {
         788  +
            request
         789  +
                .set_method(http.method())
         790  +
                .map_err(|e| SerdeError::custom(format!("invalid HTTP method: {e}")))?;
         791  +
        }
         792  +
        Ok(request)
         793  +
    }
         794  +
}
         795  +
         796  +
#[cfg(test)]
         797  +
mod tests {
         798  +
    use super::*;
         799  +
    use crate::serde::SerializableStruct;
         800  +
    use crate::{prelude::*, ShapeType};
         801  +
         802  +
    struct TestSerializer {
         803  +
        output: Vec<u8>,
         804  +
    }
         805  +
         806  +
    impl FinishSerializer for TestSerializer {
         807  +
        fn finish(self) -> Vec<u8> {
         808  +
            self.output
         809  +
        }
         810  +
    }
         811  +
         812  +
    impl ShapeSerializer for TestSerializer {
         813  +
        fn write_struct(
         814  +
            &mut self,
         815  +
            _: &Schema,
         816  +
            value: &dyn SerializableStruct,
         817  +
        ) -> Result<(), SerdeError> {
         818  +
            self.output.push(b'{');
         819  +
            value.serialize_members(self)?;
         820  +
            self.output.push(b'}');
         821  +
            Ok(())
         822  +
        }
         823  +
        fn write_list(
         824  +
            &mut self,
         825  +
            _: &Schema,
         826  +
            _: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         827  +
        ) -> Result<(), SerdeError> {
         828  +
            Ok(())
         829  +
        }
         830  +
        fn write_map(
         831  +
            &mut self,
         832  +
            _: &Schema,
         833  +
            _: &dyn Fn(&mut dyn ShapeSerializer) -> Result<(), SerdeError>,
         834  +
        ) -> Result<(), SerdeError> {
         835  +
            Ok(())
         836  +
        }
         837  +
        fn write_boolean(&mut self, _: &Schema, _: bool) -> Result<(), SerdeError> {
         838  +
            Ok(())
         839  +
        }
         840  +
        fn write_byte(&mut self, _: &Schema, _: i8) -> Result<(), SerdeError> {
         841  +
            Ok(())
         842  +
        }
         843  +
        fn write_short(&mut self, _: &Schema, _: i16) -> Result<(), SerdeError> {
         844  +
            Ok(())
         845  +
        }
         846  +
        fn write_integer(&mut self, _: &Schema, _: i32) -> Result<(), SerdeError> {
         847  +
            Ok(())
         848  +
        }
         849  +
        fn write_long(&mut self, _: &Schema, _: i64) -> Result<(), SerdeError> {
         850  +
            Ok(())
         851  +
        }
         852  +
        fn write_float(&mut self, _: &Schema, _: f32) -> Result<(), SerdeError> {
         853  +
            Ok(())
         854  +
        }
         855  +
        fn write_double(&mut self, _: &Schema, _: f64) -> Result<(), SerdeError> {
         856  +
            Ok(())
         857  +
        }
         858  +
        fn write_big_integer(
         859  +
            &mut self,
         860  +
            _: &Schema,
         861  +
            _: &aws_smithy_types::BigInteger,
         862  +
        ) -> Result<(), SerdeError> {
         863  +
            Ok(())
         864  +
        }
         865  +
        fn write_big_decimal(
         866  +
            &mut self,
         867  +
            _: &Schema,
         868  +
            _: &aws_smithy_types::BigDecimal,
         869  +
        ) -> Result<(), SerdeError> {
         870  +
            Ok(())
         871  +
        }
         872  +
        fn write_string(&mut self, _: &Schema, v: &str) -> Result<(), SerdeError> {
         873  +
            self.output.extend_from_slice(v.as_bytes());
         874  +
            Ok(())
         875  +
        }
         876  +
        fn write_blob(&mut self, _: &Schema, _: &aws_smithy_types::Blob) -> Result<(), SerdeError> {
         877  +
            Ok(())
         878  +
        }
         879  +
        fn write_timestamp(
         880  +
            &mut self,
         881  +
            _: &Schema,
         882  +
            _: &aws_smithy_types::DateTime,
         883  +
        ) -> Result<(), SerdeError> {
         884  +
            Ok(())
         885  +
        }
         886  +
        fn write_document(
         887  +
            &mut self,
         888  +
            _: &Schema,
         889  +
            _: &aws_smithy_types::Document,
         890  +
        ) -> Result<(), SerdeError> {
         891  +
            Ok(())
         892  +
        }
         893  +
        fn write_null(&mut self, _: &Schema) -> Result<(), SerdeError> {
         894  +
            Ok(())
         895  +
        }
         896  +
    }
         897  +
         898  +
    struct TestDeserializer<'a> {
         899  +
        input: &'a [u8],
         900  +
    }
         901  +
         902  +
    impl ShapeDeserializer for TestDeserializer<'_> {
         903  +
        fn read_struct(
         904  +
            &mut self,
         905  +
            _: &Schema,
         906  +
            _: &mut dyn FnMut(&Schema, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         907  +
        ) -> Result<(), SerdeError> {
         908  +
            Ok(())
         909  +
        }
         910  +
        fn read_list(
         911  +
            &mut self,
         912  +
            _: &Schema,
         913  +
            _: &mut dyn FnMut(&mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         914  +
        ) -> Result<(), SerdeError> {
         915  +
            Ok(())
         916  +
        }
         917  +
        fn read_map(
         918  +
            &mut self,
         919  +
            _: &Schema,
         920  +
            _: &mut dyn FnMut(String, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
         921  +
        ) -> Result<(), SerdeError> {
         922  +
            Ok(())
         923  +
        }
         924  +
        fn read_boolean(&mut self, _: &Schema) -> Result<bool, SerdeError> {
         925  +
            Ok(false)
         926  +
        }
         927  +
        fn read_byte(&mut self, _: &Schema) -> Result<i8, SerdeError> {
         928  +
            Ok(0)
         929  +
        }
         930  +
        fn read_short(&mut self, _: &Schema) -> Result<i16, SerdeError> {
         931  +
            Ok(0)
         932  +
        }
         933  +
        fn read_integer(&mut self, _: &Schema) -> Result<i32, SerdeError> {
         934  +
            Ok(0)
         935  +
        }
         936  +
        fn read_long(&mut self, _: &Schema) -> Result<i64, SerdeError> {
         937  +
            Ok(0)
         938  +
        }
         939  +
        fn read_float(&mut self, _: &Schema) -> Result<f32, SerdeError> {
         940  +
            Ok(0.0)
         941  +
        }
         942  +
        fn read_double(&mut self, _: &Schema) -> Result<f64, SerdeError> {
         943  +
            Ok(0.0)
         944  +
        }
         945  +
        fn read_big_integer(
         946  +
            &mut self,
         947  +
            _: &Schema,
         948  +
        ) -> Result<aws_smithy_types::BigInteger, SerdeError> {
         949  +
            use std::str::FromStr;
         950  +
            Ok(aws_smithy_types::BigInteger::from_str("0").unwrap())
         951  +
        }
         952  +
        fn read_big_decimal(
         953  +
            &mut self,
         954  +
            _: &Schema,
         955  +
        ) -> Result<aws_smithy_types::BigDecimal, SerdeError> {
         956  +
            use std::str::FromStr;
         957  +
            Ok(aws_smithy_types::BigDecimal::from_str("0").unwrap())
         958  +
        }
         959  +
        fn read_string(&mut self, _: &Schema) -> Result<String, SerdeError> {
         960  +
            Ok(String::from_utf8_lossy(self.input).into_owned())
         961  +
        }
         962  +
        fn read_blob(&mut self, _: &Schema) -> Result<aws_smithy_types::Blob, SerdeError> {
         963  +
            Ok(aws_smithy_types::Blob::new(vec![]))
         964  +
        }
         965  +
        fn read_timestamp(&mut self, _: &Schema) -> Result<aws_smithy_types::DateTime, SerdeError> {
         966  +
            Ok(aws_smithy_types::DateTime::from_secs(0))
         967  +
        }
         968  +
        fn read_document(&mut self, _: &Schema) -> Result<aws_smithy_types::Document, SerdeError> {
         969  +
            Ok(aws_smithy_types::Document::Null)
         970  +
        }
         971  +
        fn is_null(&self) -> bool {
         972  +
            false
         973  +
        }
         974  +
        fn container_size(&self) -> Option<usize> {
         975  +
            None
         976  +
        }
         977  +
    }
         978  +
         979  +
    #[derive(Debug)]
         980  +
    struct TestCodec;
         981  +
         982  +
    impl Codec for TestCodec {
         983  +
        type Serializer = TestSerializer;
         984  +
        type Deserializer<'a> = TestDeserializer<'a>;
         985  +
        fn create_serializer(&self) -> Self::Serializer {
         986  +
            TestSerializer { output: Vec::new() }
         987  +
        }
         988  +
        fn create_deserializer<'a>(&self, input: &'a [u8]) -> Self::Deserializer<'a> {
         989  +
            TestDeserializer { input }
         990  +
        }
         991  +
    }
         992  +
         993  +
    static TEST_SCHEMA: Schema =
         994  +
        Schema::new(crate::shape_id!("test", "TestStruct"), ShapeType::Structure);
         995  +
         996  +
    struct EmptyStruct;
         997  +
    impl SerializableStruct for EmptyStruct {
         998  +
        fn serialize_members(&self, _: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
         999  +
            Ok(())
        1000  +
        }
        1001  +
    }
        1002  +
        1003  +
    static NAME_MEMBER: Schema = Schema::new_member(
        1004  +
        crate::shape_id!("test", "TestStruct"),
        1005  +
        ShapeType::String,
        1006  +
        "name",
        1007  +
        0,
        1008  +
    );
        1009  +
    static MEMBERS: &[&Schema] = &[&NAME_MEMBER];
        1010  +
    static STRUCT_WITH_MEMBER: Schema = Schema::new_struct(
        1011  +
        crate::shape_id!("test", "TestStruct"),
        1012  +
        ShapeType::Structure,
        1013  +
        MEMBERS,
        1014  +
    );
        1015  +
        1016  +
    struct NameStruct;
        1017  +
    impl SerializableStruct for NameStruct {
        1018  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1019  +
            s.write_string(&NAME_MEMBER, "Alice")
        1020  +
        }
        1021  +
    }
        1022  +
        1023  +
    fn make_protocol() -> HttpBindingProtocol<TestCodec> {
        1024  +
        HttpBindingProtocol::new(
        1025  +
            crate::shape_id!("test", "proto"),
        1026  +
            TestCodec,
        1027  +
            "application/test",
        1028  +
        )
        1029  +
    }
        1030  +
        1031  +
    #[test]
        1032  +
    fn serialize_sets_content_type() {
        1033  +
        // A struct with body members gets Content-Type
        1034  +
        let request = make_protocol()
        1035  +
            .serialize_request(
        1036  +
                &EmptyStruct,
        1037  +
                &STRUCT_WITH_MEMBER,
        1038  +
                "https://example.com",
        1039  +
                &ConfigBag::base(),
        1040  +
            )
        1041  +
            .unwrap();
        1042  +
        assert_eq!(
        1043  +
            request.headers().get("Content-Type").unwrap(),
        1044  +
            "application/test"
        1045  +
        );
        1046  +
    }
        1047  +
        1048  +
    #[test]
        1049  +
    fn serialize_no_body_members_omits_content_type() {
        1050  +
        // A struct with no members gets no Content-Type per REST-JSON spec
        1051  +
        let request = make_protocol()
        1052  +
            .serialize_request(
        1053  +
                &EmptyStruct,
        1054  +
                &TEST_SCHEMA,
        1055  +
                "https://example.com",
        1056  +
                &ConfigBag::base(),
        1057  +
            )
        1058  +
            .unwrap();
        1059  +
        assert!(request.headers().get("Content-Type").is_none());
        1060  +
    }
        1061  +
        1062  +
    #[test]
        1063  +
    fn serialize_sets_uri() {
        1064  +
        let request = make_protocol()
        1065  +
            .serialize_request(
        1066  +
                &EmptyStruct,
        1067  +
                &TEST_SCHEMA,
        1068  +
                "https://example.com/path",
        1069  +
                &ConfigBag::base(),
        1070  +
            )
        1071  +
            .unwrap();
        1072  +
        assert_eq!(request.uri(), "https://example.com/path");
        1073  +
    }
        1074  +
        1075  +
    #[test]
        1076  +
    fn serialize_body() {
        1077  +
        let request = make_protocol()
        1078  +
            .serialize_request(
        1079  +
                &NameStruct,
        1080  +
                &STRUCT_WITH_MEMBER,
        1081  +
                "https://example.com",
        1082  +
                &ConfigBag::base(),
        1083  +
            )
        1084  +
            .unwrap();
        1085  +
        assert_eq!(request.body().bytes().unwrap(), b"{Alice}");
        1086  +
    }
        1087  +
        1088  +
    #[test]
        1089  +
    fn deserialize_response() {
        1090  +
        let response = Response::new(
        1091  +
            200u16.try_into().unwrap(),
        1092  +
            SdkBody::from(r#"{"name":"Bob"}"#),
        1093  +
        );
        1094  +
        let mut deser = make_protocol()
        1095  +
            .deserialize_response(&response, &TEST_SCHEMA, &ConfigBag::base())
        1096  +
            .unwrap();
        1097  +
        assert_eq!(deser.read_string(&STRING).unwrap(), r#"{"name":"Bob"}"#);
        1098  +
    }
        1099  +
        1100  +
    #[test]
        1101  +
    fn update_endpoint() {
        1102  +
        let mut request = make_protocol()
        1103  +
            .serialize_request(
        1104  +
                &EmptyStruct,
        1105  +
                &TEST_SCHEMA,
        1106  +
                "https://old.example.com",
        1107  +
                &ConfigBag::base(),
        1108  +
            )
        1109  +
            .unwrap();
        1110  +
        let endpoint = aws_smithy_types::endpoint::Endpoint::builder()
        1111  +
            .url("https://new.example.com")
        1112  +
            .build();
        1113  +
        make_protocol()
        1114  +
            .update_endpoint(&mut request, &endpoint, &ConfigBag::base())
        1115  +
            .unwrap();
        1116  +
        assert_eq!(request.uri(), "https://new.example.com/");
        1117  +
    }
        1118  +
        1119  +
    #[test]
        1120  +
    fn protocol_id() {
        1121  +
        let protocol = HttpBindingProtocol::new(
        1122  +
            crate::shape_id!("aws.protocols", "restJson1"),
        1123  +
            TestCodec,
        1124  +
            "application/json",
        1125  +
        );
        1126  +
        assert_eq!(protocol.protocol_id().as_str(), "aws.protocols#restJson1");
        1127  +
    }
        1128  +
        1129  +
    #[test]
        1130  +
    fn invalid_uri_returns_error() {
        1131  +
        assert!(make_protocol()
        1132  +
            .serialize_request(
        1133  +
                &EmptyStruct,
        1134  +
                &TEST_SCHEMA,
        1135  +
                "not a valid uri\n\n",
        1136  +
                &ConfigBag::base()
        1137  +
            )
        1138  +
            .is_err());
        1139  +
    }
        1140  +
        1141  +
    // -- @httpHeader tests --
        1142  +
        1143  +
    static HEADER_MEMBER: Schema = Schema::new_member(
        1144  +
        crate::shape_id!("test", "S"),
        1145  +
        ShapeType::String,
        1146  +
        "xToken",
        1147  +
        0,
        1148  +
    )
        1149  +
    .with_http_header("X-Token");
        1150  +
        1151  +
    static HEADER_SCHEMA: Schema = Schema::new_struct(
        1152  +
        crate::shape_id!("test", "S"),
        1153  +
        ShapeType::Structure,
        1154  +
        &[&HEADER_MEMBER],
        1155  +
    );
        1156  +
        1157  +
    struct HeaderStruct;
        1158  +
    impl SerializableStruct for HeaderStruct {
        1159  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1160  +
            s.write_string(&HEADER_MEMBER, "my-token-value")
        1161  +
        }
        1162  +
    }
        1163  +
        1164  +
    #[test]
        1165  +
    fn http_header_string() {
        1166  +
        let request = make_protocol()
        1167  +
            .serialize_request(
        1168  +
                &HeaderStruct,
        1169  +
                &HEADER_SCHEMA,
        1170  +
                "https://example.com",
        1171  +
                &ConfigBag::base(),
        1172  +
            )
        1173  +
            .unwrap();
        1174  +
        assert_eq!(request.headers().get("X-Token").unwrap(), "my-token-value");
        1175  +
    }
        1176  +
        1177  +
    static INT_HEADER_MEMBER: Schema = Schema::new_member(
        1178  +
        crate::shape_id!("test", "S"),
        1179  +
        ShapeType::Integer,
        1180  +
        "retryCount",
        1181  +
        0,
        1182  +
    )
        1183  +
    .with_http_header("X-Retry-Count");
        1184  +
        1185  +
    static INT_HEADER_SCHEMA: Schema = Schema::new_struct(
        1186  +
        crate::shape_id!("test", "S"),
        1187  +
        ShapeType::Structure,
        1188  +
        &[&INT_HEADER_MEMBER],
        1189  +
    );
        1190  +
        1191  +
    struct IntHeaderStruct;
        1192  +
    impl SerializableStruct for IntHeaderStruct {
        1193  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1194  +
            s.write_integer(&INT_HEADER_MEMBER, 3)
        1195  +
        }
        1196  +
    }
        1197  +
        1198  +
    #[test]
        1199  +
    fn http_header_integer() {
        1200  +
        let request = make_protocol()
        1201  +
            .serialize_request(
        1202  +
                &IntHeaderStruct,
        1203  +
                &INT_HEADER_SCHEMA,
        1204  +
                "https://example.com",
        1205  +
                &ConfigBag::base(),
        1206  +
            )
        1207  +
            .unwrap();
        1208  +
        assert_eq!(request.headers().get("X-Retry-Count").unwrap(), "3");
        1209  +
    }
        1210  +
        1211  +
    static BOOL_HEADER_MEMBER: Schema = Schema::new_member(
        1212  +
        crate::shape_id!("test", "S"),
        1213  +
        ShapeType::Boolean,
        1214  +
        "verbose",
        1215  +
        0,
        1216  +
    )
        1217  +
    .with_http_header("X-Verbose");
        1218  +
        1219  +
    static BOOL_HEADER_SCHEMA: Schema = Schema::new_struct(
        1220  +
        crate::shape_id!("test", "S"),
        1221  +
        ShapeType::Structure,
        1222  +
        &[&BOOL_HEADER_MEMBER],
        1223  +
    );
        1224  +
        1225  +
    struct BoolHeaderStruct;
        1226  +
    impl SerializableStruct for BoolHeaderStruct {
        1227  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1228  +
            s.write_boolean(&BOOL_HEADER_MEMBER, true)
        1229  +
        }
        1230  +
    }
        1231  +
        1232  +
    #[test]
        1233  +
    fn http_header_boolean() {
        1234  +
        let request = make_protocol()
        1235  +
            .serialize_request(
        1236  +
                &BoolHeaderStruct,
        1237  +
                &BOOL_HEADER_SCHEMA,
        1238  +
                "https://example.com",
        1239  +
                &ConfigBag::base(),
        1240  +
            )
        1241  +
            .unwrap();
        1242  +
        assert_eq!(request.headers().get("X-Verbose").unwrap(), "true");
        1243  +
    }
        1244  +
        1245  +
    // -- @httpQuery tests --
        1246  +
        1247  +
    static QUERY_MEMBER: Schema =
        1248  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "color", 0)
        1249  +
            .with_http_query("color");
        1250  +
        1251  +
    static QUERY_SCHEMA: Schema = Schema::new_struct(
        1252  +
        crate::shape_id!("test", "S"),
        1253  +
        ShapeType::Structure,
        1254  +
        &[&QUERY_MEMBER],
        1255  +
    );
        1256  +
        1257  +
    struct QueryStruct;
        1258  +
    impl SerializableStruct for QueryStruct {
        1259  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1260  +
            s.write_string(&QUERY_MEMBER, "blue")
        1261  +
        }
        1262  +
    }
        1263  +
        1264  +
    #[test]
        1265  +
    fn http_query_string() {
        1266  +
        let request = make_protocol()
        1267  +
            .serialize_request(
        1268  +
                &QueryStruct,
        1269  +
                &QUERY_SCHEMA,
        1270  +
                "https://example.com/things",
        1271  +
                &ConfigBag::base(),
        1272  +
            )
        1273  +
            .unwrap();
        1274  +
        assert_eq!(request.uri(), "https://example.com/things?color=blue");
        1275  +
    }
        1276  +
        1277  +
    static INT_QUERY_MEMBER: Schema =
        1278  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::Integer, "size", 0)
        1279  +
            .with_http_query("size");
        1280  +
        1281  +
    static INT_QUERY_SCHEMA: Schema = Schema::new_struct(
        1282  +
        crate::shape_id!("test", "S"),
        1283  +
        ShapeType::Structure,
        1284  +
        &[&INT_QUERY_MEMBER],
        1285  +
    );
        1286  +
        1287  +
    struct IntQueryStruct;
        1288  +
    impl SerializableStruct for IntQueryStruct {
        1289  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1290  +
            s.write_integer(&INT_QUERY_MEMBER, 42)
        1291  +
        }
        1292  +
    }
        1293  +
        1294  +
    #[test]
        1295  +
    fn http_query_integer() {
        1296  +
        let request = make_protocol()
        1297  +
            .serialize_request(
        1298  +
                &IntQueryStruct,
        1299  +
                &INT_QUERY_SCHEMA,
        1300  +
                "https://example.com/things",
        1301  +
                &ConfigBag::base(),
        1302  +
            )
        1303  +
            .unwrap();
        1304  +
        assert_eq!(request.uri(), "https://example.com/things?size=42");
        1305  +
    }
        1306  +
        1307  +
    // -- Multiple @httpQuery params --
        1308  +
        1309  +
    static Q1: Schema =
        1310  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "a", 0)
        1311  +
            .with_http_query("a");
        1312  +
    static Q2: Schema =
        1313  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "b", 1)
        1314  +
            .with_http_query("b");
        1315  +
    static MULTI_QUERY_SCHEMA: Schema = Schema::new_struct(
        1316  +
        crate::shape_id!("test", "S"),
        1317  +
        ShapeType::Structure,
        1318  +
        &[&Q1, &Q2],
        1319  +
    );
        1320  +
        1321  +
    struct MultiQueryStruct;
        1322  +
    impl SerializableStruct for MultiQueryStruct {
        1323  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1324  +
            s.write_string(&Q1, "x")?;
        1325  +
            s.write_string(&Q2, "y")
        1326  +
        }
        1327  +
    }
        1328  +
        1329  +
    #[test]
        1330  +
    fn http_query_multiple_params() {
        1331  +
        let request = make_protocol()
        1332  +
            .serialize_request(
        1333  +
                &MultiQueryStruct,
        1334  +
                &MULTI_QUERY_SCHEMA,
        1335  +
                "https://example.com",
        1336  +
                &ConfigBag::base(),
        1337  +
            )
        1338  +
            .unwrap();
        1339  +
        assert_eq!(request.uri(), "https://example.com?a=x&b=y");
        1340  +
    }
        1341  +
        1342  +
    // -- @httpQuery with percent-encoding --
        1343  +
        1344  +
    #[test]
        1345  +
    fn http_query_percent_encodes_values() {
        1346  +
        struct SpaceQueryStruct;
        1347  +
        impl SerializableStruct for SpaceQueryStruct {
        1348  +
            fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1349  +
                s.write_string(&QUERY_MEMBER, "hello world")
        1350  +
            }
        1351  +
        }
        1352  +
        let request = make_protocol()
        1353  +
            .serialize_request(
        1354  +
                &SpaceQueryStruct,
        1355  +
                &QUERY_SCHEMA,
        1356  +
                "https://example.com",
        1357  +
                &ConfigBag::base(),
        1358  +
            )
        1359  +
            .unwrap();
        1360  +
        assert_eq!(request.uri(), "https://example.com?color=hello%20world");
        1361  +
    }
        1362  +
        1363  +
    // -- @httpLabel tests --
        1364  +
        1365  +
    static LABEL_MEMBER: Schema = Schema::new_member(
        1366  +
        crate::shape_id!("test", "S"),
        1367  +
        ShapeType::String,
        1368  +
        "bucketName",
        1369  +
        0,
        1370  +
    )
        1371  +
    .with_http_label();
        1372  +
        1373  +
    static LABEL_SCHEMA: Schema = Schema::new_struct(
        1374  +
        crate::shape_id!("test", "S"),
        1375  +
        ShapeType::Structure,
        1376  +
        &[&LABEL_MEMBER],
        1377  +
    );
        1378  +
        1379  +
    struct LabelStruct;
        1380  +
    impl SerializableStruct for LabelStruct {
        1381  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1382  +
            s.write_string(&LABEL_MEMBER, "my-bucket")
        1383  +
        }
        1384  +
    }
        1385  +
        1386  +
    #[test]
        1387  +
    fn http_label_substitution() {
        1388  +
        let request = make_protocol()
        1389  +
            .serialize_request(
        1390  +
                &LabelStruct,
        1391  +
                &LABEL_SCHEMA,
        1392  +
                "https://example.com/{bucketName}/objects",
        1393  +
                &ConfigBag::base(),
        1394  +
            )
        1395  +
            .unwrap();
        1396  +
        assert_eq!(request.uri(), "https://example.com/my-bucket/objects");
        1397  +
    }
        1398  +
        1399  +
    #[test]
        1400  +
    fn http_label_percent_encodes() {
        1401  +
        struct SpecialLabelStruct;
        1402  +
        impl SerializableStruct for SpecialLabelStruct {
        1403  +
            fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1404  +
                s.write_string(&LABEL_MEMBER, "my bucket/name")
        1405  +
            }
        1406  +
        }
        1407  +
        let request = make_protocol()
        1408  +
            .serialize_request(
        1409  +
                &SpecialLabelStruct,
        1410  +
                &LABEL_SCHEMA,
        1411  +
                "https://example.com/{bucketName}",
        1412  +
                &ConfigBag::base(),
        1413  +
            )
        1414  +
            .unwrap();
        1415  +
        assert!(request.uri().contains("my%20bucket%2Fname"));
        1416  +
    }
        1417  +
        1418  +
    static INT_LABEL_MEMBER: Schema = Schema::new_member(
        1419  +
        crate::shape_id!("test", "S"),
        1420  +
        ShapeType::Integer,
        1421  +
        "itemId",
        1422  +
        0,
        1423  +
    )
        1424  +
    .with_http_label();
        1425  +
        1426  +
    static INT_LABEL_SCHEMA: Schema = Schema::new_struct(
        1427  +
        crate::shape_id!("test", "S"),
        1428  +
        ShapeType::Structure,
        1429  +
        &[&INT_LABEL_MEMBER],
        1430  +
    );
        1431  +
        1432  +
    struct IntLabelStruct;
        1433  +
    impl SerializableStruct for IntLabelStruct {
        1434  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1435  +
            s.write_integer(&INT_LABEL_MEMBER, 123)
        1436  +
        }
        1437  +
    }
        1438  +
        1439  +
    #[test]
        1440  +
    fn http_label_integer() {
        1441  +
        let request = make_protocol()
        1442  +
            .serialize_request(
        1443  +
                &IntLabelStruct,
        1444  +
                &INT_LABEL_SCHEMA,
        1445  +
                "https://example.com/items/{itemId}",
        1446  +
                &ConfigBag::base(),
        1447  +
            )
        1448  +
            .unwrap();
        1449  +
        assert_eq!(request.uri(), "https://example.com/items/123");
        1450  +
    }
        1451  +
        1452  +
    // -- Combined: @httpHeader + @httpQuery + @httpLabel + body --
        1453  +
        1454  +
    static COMBINED_LABEL: Schema =
        1455  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "id", 0)
        1456  +
            .with_http_label();
        1457  +
    static COMBINED_HEADER: Schema =
        1458  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "token", 1)
        1459  +
            .with_http_header("X-Token");
        1460  +
    static COMBINED_QUERY: Schema = Schema::new_member(
        1461  +
        crate::shape_id!("test", "S"),
        1462  +
        ShapeType::String,
        1463  +
        "filter",
        1464  +
        2,
        1465  +
    )
        1466  +
    .with_http_query("filter");
        1467  +
    static COMBINED_BODY: Schema =
        1468  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::String, "data", 3);
        1469  +
    static COMBINED_SCHEMA: Schema = Schema::new_struct(
        1470  +
        crate::shape_id!("test", "S"),
        1471  +
        ShapeType::Structure,
        1472  +
        &[
        1473  +
            &COMBINED_LABEL,
        1474  +
            &COMBINED_HEADER,
        1475  +
            &COMBINED_QUERY,
        1476  +
            &COMBINED_BODY,
        1477  +
        ],
        1478  +
    );
        1479  +
        1480  +
    struct CombinedStruct;
        1481  +
    impl SerializableStruct for CombinedStruct {
        1482  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1483  +
            s.write_string(&COMBINED_LABEL, "item-42")?;
        1484  +
            s.write_string(&COMBINED_HEADER, "secret")?;
        1485  +
            s.write_string(&COMBINED_QUERY, "active")?;
        1486  +
            s.write_string(&COMBINED_BODY, "payload-data")
        1487  +
        }
        1488  +
    }
        1489  +
        1490  +
    #[test]
        1491  +
    fn combined_bindings() {
        1492  +
        let request = make_protocol()
        1493  +
            .serialize_request(
        1494  +
                &CombinedStruct,
        1495  +
                &COMBINED_SCHEMA,
        1496  +
                "https://example.com/{id}/details",
        1497  +
                &ConfigBag::base(),
        1498  +
            )
        1499  +
            .unwrap();
        1500  +
        assert_eq!(
        1501  +
            request.uri(),
        1502  +
            "https://example.com/item-42/details?filter=active"
        1503  +
        );
        1504  +
        // Header
        1505  +
        assert_eq!(request.headers().get("X-Token").unwrap(), "secret");
        1506  +
        // Body contains only the unbound member
        1507  +
        let body = request.body().bytes().unwrap();
        1508  +
        assert!(body
        1509  +
            .windows(b"payload-data".len())
        1510  +
            .any(|w| w == b"payload-data"));
        1511  +
    }
        1512  +
        1513  +
    // -- @httpPrefixHeaders tests --
        1514  +
        1515  +
    static PREFIX_MEMBER: Schema =
        1516  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::Map, "metadata", 0)
        1517  +
            .with_http_prefix_headers("X-Meta-");
        1518  +
        1519  +
    static PREFIX_SCHEMA: Schema = Schema::new_struct(
        1520  +
        crate::shape_id!("test", "S"),
        1521  +
        ShapeType::Structure,
        1522  +
        &[&PREFIX_MEMBER],
        1523  +
    );
        1524  +
        1525  +
    struct PrefixHeaderStruct;
        1526  +
    impl SerializableStruct for PrefixHeaderStruct {
        1527  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1528  +
            s.write_map(&PREFIX_MEMBER, &|s| {
        1529  +
                s.write_string(&STRING, "Color")?;
        1530  +
                s.write_string(&STRING, "red")?;
        1531  +
                s.write_string(&STRING, "Size")?;
        1532  +
                s.write_string(&STRING, "large")?;
        1533  +
                Ok(())
        1534  +
            })
        1535  +
        }
        1536  +
    }
        1537  +
        1538  +
    #[test]
        1539  +
    fn http_prefix_headers() {
        1540  +
        let request = make_protocol()
        1541  +
            .serialize_request(
        1542  +
                &PrefixHeaderStruct,
        1543  +
                &PREFIX_SCHEMA,
        1544  +
                "https://example.com",
        1545  +
                &ConfigBag::base(),
        1546  +
            )
        1547  +
            .unwrap();
        1548  +
        assert_eq!(request.headers().get("X-Meta-Color").unwrap(), "red");
        1549  +
        assert_eq!(request.headers().get("X-Meta-Size").unwrap(), "large");
        1550  +
    }
        1551  +
        1552  +
    // -- @httpQueryParams tests --
        1553  +
        1554  +
    static QUERY_PARAMS_MEMBER: Schema =
        1555  +
        Schema::new_member(crate::shape_id!("test", "S"), ShapeType::Map, "params", 0)
        1556  +
            .with_http_query_params();
        1557  +
        1558  +
    static QUERY_PARAMS_SCHEMA: Schema = Schema::new_struct(
        1559  +
        crate::shape_id!("test", "S"),
        1560  +
        ShapeType::Structure,
        1561  +
        &[&QUERY_PARAMS_MEMBER],
        1562  +
    );
        1563  +
        1564  +
    struct QueryParamsStruct;
        1565  +
    impl SerializableStruct for QueryParamsStruct {
        1566  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1567  +
            s.write_map(&QUERY_PARAMS_MEMBER, &|s| {
        1568  +
                s.write_string(&STRING, "page")?;
        1569  +
                s.write_string(&STRING, "2")?;
        1570  +
                s.write_string(&STRING, "limit")?;
        1571  +
                s.write_string(&STRING, "50")?;
        1572  +
                Ok(())
        1573  +
            })
        1574  +
        }
        1575  +
    }
        1576  +
        1577  +
    #[test]
        1578  +
    fn http_query_params() {
        1579  +
        let request = make_protocol()
        1580  +
            .serialize_request(
        1581  +
                &QueryParamsStruct,
        1582  +
                &QUERY_PARAMS_SCHEMA,
        1583  +
                "https://example.com",
        1584  +
                &ConfigBag::base(),
        1585  +
            )
        1586  +
            .unwrap();
        1587  +
        assert_eq!(request.uri(), "https://example.com?page=2&limit=50");
        1588  +
    }
        1589  +
        1590  +
    // -- Timestamp in header defaults to http-date --
        1591  +
        1592  +
    static TS_HEADER_MEMBER: Schema = Schema::new_member(
        1593  +
        crate::shape_id!("test", "S"),
        1594  +
        ShapeType::Timestamp,
        1595  +
        "ifModified",
        1596  +
        0,
        1597  +
    )
        1598  +
    .with_http_header("If-Modified-Since");
        1599  +
        1600  +
    static TS_HEADER_SCHEMA: Schema = Schema::new_struct(
        1601  +
        crate::shape_id!("test", "S"),
        1602  +
        ShapeType::Structure,
        1603  +
        &[&TS_HEADER_MEMBER],
        1604  +
    );
        1605  +
        1606  +
    struct TimestampHeaderStruct;
        1607  +
    impl SerializableStruct for TimestampHeaderStruct {
        1608  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1609  +
            s.write_timestamp(&TS_HEADER_MEMBER, &aws_smithy_types::DateTime::from_secs(0))
        1610  +
        }
        1611  +
    }
        1612  +
        1613  +
    #[test]
        1614  +
    fn timestamp_header_uses_http_date() {
        1615  +
        let request = make_protocol()
        1616  +
            .serialize_request(
        1617  +
                &TimestampHeaderStruct,
        1618  +
                &TS_HEADER_SCHEMA,
        1619  +
                "https://example.com",
        1620  +
                &ConfigBag::base(),
        1621  +
            )
        1622  +
            .unwrap();
        1623  +
        let value = request.headers().get("If-Modified-Since").unwrap();
        1624  +
        // http-date format: "Thu, 01 Jan 1970 00:00:00 GMT"
        1625  +
        assert!(value.contains("1970"), "expected http-date, got: {value}");
        1626  +
    }
        1627  +
        1628  +
    // -- Timestamp in query defaults to date-time --
        1629  +
        1630  +
    static TS_QUERY_MEMBER: Schema = Schema::new_member(
        1631  +
        crate::shape_id!("test", "S"),
        1632  +
        ShapeType::Timestamp,
        1633  +
        "since",
        1634  +
        0,
        1635  +
    )
        1636  +
    .with_http_query("since");
        1637  +
        1638  +
    static TS_QUERY_SCHEMA: Schema = Schema::new_struct(
        1639  +
        crate::shape_id!("test", "S"),
        1640  +
        ShapeType::Structure,
        1641  +
        &[&TS_QUERY_MEMBER],
        1642  +
    );
        1643  +
        1644  +
    struct TimestampQueryStruct;
        1645  +
    impl SerializableStruct for TimestampQueryStruct {
        1646  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1647  +
            s.write_timestamp(&TS_QUERY_MEMBER, &aws_smithy_types::DateTime::from_secs(0))
        1648  +
        }
        1649  +
    }
        1650  +
        1651  +
    #[test]
        1652  +
    fn timestamp_query_uses_date_time() {
        1653  +
        let request = make_protocol()
        1654  +
            .serialize_request(
        1655  +
                &TimestampQueryStruct,
        1656  +
                &TS_QUERY_SCHEMA,
        1657  +
                "https://example.com",
        1658  +
                &ConfigBag::base(),
        1659  +
            )
        1660  +
            .unwrap();
        1661  +
        assert_eq!(
        1662  +
            request.uri(),
        1663  +
            "https://example.com?since=1970-01-01T00%3A00%3A00Z"
        1664  +
        );
        1665  +
    }
        1666  +
        1667  +
    // -- Unbound members go to body, bound members do not --
        1668  +
        1669  +
    static BOUND_MEMBER: Schema = Schema::new_member(
        1670  +
        crate::shape_id!("test", "S"),
        1671  +
        ShapeType::String,
        1672  +
        "headerVal",
        1673  +
        0,
        1674  +
    )
        1675  +
    .with_http_header("X-Val");
        1676  +
    static UNBOUND_MEMBER: Schema = Schema::new_member(
        1677  +
        crate::shape_id!("test", "S"),
        1678  +
        ShapeType::String,
        1679  +
        "bodyVal",
        1680  +
        1,
        1681  +
    );
        1682  +
    static MIXED_SCHEMA: Schema = Schema::new_struct(
        1683  +
        crate::shape_id!("test", "S"),
        1684  +
        ShapeType::Structure,
        1685  +
        &[&BOUND_MEMBER, &UNBOUND_MEMBER],
        1686  +
    );
        1687  +
        1688  +
    struct MixedStruct;
        1689  +
    impl SerializableStruct for MixedStruct {
        1690  +
        fn serialize_members(&self, s: &mut dyn ShapeSerializer) -> Result<(), SerdeError> {
        1691  +
            s.write_string(&BOUND_MEMBER, "in-header")?;
        1692  +
            s.write_string(&UNBOUND_MEMBER, "in-body")
        1693  +
        }
        1694  +
    }
        1695  +
        1696  +
    #[test]
        1697  +
    fn bound_members_not_in_body() {
        1698  +
        let request = make_protocol()
        1699  +
            .serialize_request(
        1700  +
                &MixedStruct,
        1701  +
                &MIXED_SCHEMA,
        1702  +
                "https://example.com",
        1703  +
                &ConfigBag::base(),
        1704  +
            )
        1705  +
            .unwrap();
        1706  +
        let body = std::str::from_utf8(request.body().bytes().unwrap()).unwrap();
        1707  +
        assert!(
        1708  +
            body.contains("in-body"),
        1709  +
            "body should contain unbound member"
        1710  +
        );
        1711  +
        assert!(
        1712  +
            !body.contains("in-header"),
        1713  +
            "body should NOT contain header-bound member"
        1714  +
        );
        1715  +
        assert_eq!(request.headers().get("X-Val").unwrap(), "in-header");
        1716  +
    }
        1717  +
}