Skip to content

fix: [core] Hard code version number in user agent string (#98) #533

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

Merged
merged 5 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/AWSLambdaRuntime/ControlPlaneRequestEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct ControlPlaneRequestEncoder: _EmittingChannelHandler {
extension String {
static let CRLF: String = "\r\n"

static let userAgent = "Swift-Lambda/Unknown"
static let userAgent = "Swift-Lambda/\(Version.current)"
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

String interpolation is performed every time this static property is accessed. Consider using a computed property or pre-computing the string to avoid repeated interpolation overhead.

Suggested change
static let userAgent = "Swift-Lambda/\(Version.current)"
static let userAgent: String = {
return "Swift-Lambda/\(Version.current)"
}()

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Don't think this is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think neither. Typical hallucination :-)

static let userAgentHeader: String = "user-agent: \(userAgent)\r\n"
static let unhandledErrorHeader: String = "lambda-runtime-function-error-type: Unhandled\r\n"

Expand Down
25 changes: 25 additions & 0 deletions Sources/AWSLambdaRuntime/Version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftAWSLambdaRuntime open source project
//
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

/// The version of the AWS Lambda Runtime.
///
/// This is used in the User Agent header when making requests to the AWS Lambda data Plane.
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

"data Plane" should be "Data Plane" - both words should be capitalized when referring to the AWS Lambda Data Plane as a proper noun.

Suggested change
/// This is used in the User Agent header when making requests to the AWS Lambda data Plane.
/// This is used in the User Agent header when making requests to the AWS Lambda Data Plane.

Copilot uses AI. Check for mistakes.

///
/// - Note: This is a static property that returns the current version of the AWS Lambda Runtime.
/// It is used to ensure that the runtime can be identified by the AWS Lambda service.
/// As such, we mainly care about major version and minor version. Patch and pre-release versions are ignored.
package enum Version {
/// The current version of the AWS Lambda Runtime.
package static let current = "2.0"
}