Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stored property for adding additional headers in SdkHttpRequest #593

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

dayaffe
Copy link
Contributor

@dayaffe dayaffe commented Sep 25, 2023

Provide the ability to add additional headers to an existing request of type SdkHttpRequest.

Issue #

#1130
#583

Description of changes

Cause: headers is already a mutable property but it is computed without any stored values. This means that a customer who attempts to modify headers will either have no effect (because computed properties are read-only) or because it points to an instance of endpoint.headers whose headers are immutable.

Solution: Add additionalHeaders stored property which is mutable and provide add/removal methods.

Risk: Computed properties ensure that the request is never modified in-transit. In order to reduce any risk associated I have chosen to add a new property that is mutable, stores values, and provided my own setters rather than modify the existing property to no longer be computed. Additionally, we should remove this functionality once Swift SDK SRA-compliant with interceptors (#307)

How to use:

class MyHTTPClientEngineProxy: HttpClientEngine {
    let base: HttpClientEngine

    init(base: HttpClientEngine) {
        self.base = base
    }

    func execute(request: SdkHttpRequest) async throws -> HttpResponse {
        request.withHeader(name: "foo", value: "bar")
        return try await base.execute(request: request)
    }
}

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dayaffe dayaffe changed the title feat: add stored property for adding additional headers SDK request feat: add stored property for adding additional headers in SDK request Sep 25, 2023
@dayaffe dayaffe changed the title feat: add stored property for adding additional headers in SDK request feat: add stored property for adding additional headers in SdkHttpRequest Sep 25, 2023
Copy link
Contributor

@sichanyoo sichanyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Copy link
Contributor

@jbelkins jbelkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this, as an interim fix to restore what Amplify needs, but this should be removed once reference architecture features that allow for headers to be set are implemented.

@dayaffe dayaffe merged commit 2e4e744 into main Sep 26, 2023
7 checks passed
@dayaffe dayaffe deleted the day/sdk-http-request-headers branch September 26, 2023 16:15
@dayaffe
Copy link
Contributor Author

dayaffe commented Sep 26, 2023

This PR should be reverted once #307 is implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants