-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't change HTTP request components after they have been signed (…
- Loading branch information
Showing
16 changed files
with
176 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Sources/ClientRuntime/Networking/Http/String+URLPercentEncoding.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import Foundation | ||
|
||
// Creates a `CharacterSet` of the characters that need not be percent encoded in the | ||
// resulting URL. This set consists of alphanumerics plus underscore, dash, tilde, and | ||
// period. Any other character should be percent-encoded when used in a path segment. | ||
// Forward-slash is added as well because the segments have already been joined into a path. | ||
// | ||
// See, for URL-allowed characters: | ||
// https://www.rfc-editor.org/rfc/rfc3986#section-2.3 | ||
private let allowedForPath = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "/_-.~")) | ||
private let allowedForQuery = CharacterSet.alphanumerics.union(CharacterSet(charactersIn: "_-.~")) | ||
|
||
extension String { | ||
|
||
/// Encodes a URL component for inclusion in the path or query items, using percent-escaping. | ||
/// | ||
/// All characters except alphanumerics plus forward slash, underscore, dash, tilde, and period will be escaped. | ||
var urlPercentEncodedForPath: String { | ||
addingPercentEncoding(withAllowedCharacters: allowedForPath) ?? self | ||
} | ||
|
||
/// Encodes a URL component for inclusion in query item name or value, using percent-escaping. | ||
/// | ||
/// All characters except alphanumerics plus forward slash, underscore, dash, tilde, and period will be escaped. | ||
var urlPercentEncodedForQuery: String { | ||
addingPercentEncoding(withAllowedCharacters: allowedForQuery) ?? self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.