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

Add common headers for Platform, SDK version, Source app #455

Merged
merged 9 commits into from
Oct 4, 2024

Conversation

pinarol
Copy link
Contributor

@pinarol pinarol commented Oct 3, 2024

Closes #451

Description

Adding headers:

X-Platform: ios
X-SDK-Version: <version>
X-Source: <app bundle name>

I created a follow-up issue to find a better way about injecting the SDK version into the iOS runtime. #456

Testing Steps

SwiftUI demo app > QE
Check with a tool like proxyman and confirm the headers are added.

@pinarol pinarol added the enhance New feature or request label Oct 3, 2024
@pinarol pinarol added this to the Milestone 4 - Quick Editor milestone Oct 3, 2024
@pinarol pinarol self-assigned this Oct 3, 2024
@pinarol pinarol changed the title Add more common headers Add common headers for Platform, SDK version, source app Oct 3, 2024
@pinarol pinarol changed the title Add common headers for Platform, SDK version, source app Add common headers for Platform, SDK version, Source app Oct 3, 2024
@wpmobilebot
Copy link

wpmobilebot commented Oct 3, 2024

Gravatar UIKit Prototype Build📲 You can test the changes from this Pull Request in Gravatar UIKit Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar UIKit Prototype Build Gravatar UIKit Prototype Build
Build Number1376
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commit2e1a915
App Center BuildGravatar SDK Demo - UIKit #203
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link

wpmobilebot commented Oct 3, 2024

Gravatar SwiftUI Prototype Build📲 You can test the changes from this Pull Request in Gravatar SwiftUI Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar SwiftUI Prototype Build Gravatar SwiftUI Prototype Build
Build Number1376
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-swiftui.prototype-build
Commit2e1a915
App Center BuildGravatar SDK Demo - SwiftUI #203
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@pinarol pinarol marked this pull request as ready for review October 3, 2024 16:45
Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

I see the correct parameters on the Headers 🎉
CleanShot 2024-10-03 at 19 17 53@2x

Copy link
Contributor

@andrewdmontgomery andrewdmontgomery left a comment

Choose a reason for hiding this comment

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

Just a small change to a comment. Looks good.

@@ -14,6 +14,9 @@ struct URLSessionHTTPClient: HTTPClient {
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = [
"Accept": "application/json",
"X-Platform": "ios",
Copy link
Contributor

Choose a reason for hiding this comment

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

This reminds me of a separate question: do we want to track iOS/iPadOS? If so, I think we'd still treat them both as X-Platform ios, and add a separate header for device form factor. That way both platforms could record this.

We could add a separate header like "X-Device-Type: tablet".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now we don't want to track iOS/iPadOS and yes i agree that would be a separate header if needed.

let defaultBundle = Bundle(for: BundleFinder.self)
// If installed with CocoaPods, resources will be in GravatarUI.bundle
if let bundleURL = defaultBundle.resourceURL,
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("Gravatar.bundle"))
Copy link
Contributor

@andrewdmontgomery andrewdmontgomery Oct 3, 2024

Choose a reason for hiding this comment

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

Nice.

For those visiting this in the future:

The name of the bundle "Gravatar.bundle" (without the .bundle file extension) needs to match the key in the respective Gravatar.podspec:

 s.resource_bundles = {
    'Gravatar' => ['Sources/Gravatar/Resources/*.plist']
  }

We happen to be using the same name ("Gravatar") for the module and the pod, too. So it's easier to get right. But the actual dependency is on the name of the resource bundle we define in the podspec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for elaborating. This is valuable info so i added it in the code comment.

extension Bundle {
static var module: Bundle {
let defaultBundle = Bundle(for: BundleFinder.self)
// If installed with CocoaPods, resources will be in GravatarUI.bundle
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If installed with CocoaPods, resources will be in GravatarUI.bundle
// If installed with CocoaPods, resources will be in Gravatar.bundle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@pinarol pinarol merged commit 26d64d8 into trunk Oct 4, 2024
9 checks passed
@pinarol pinarol deleted the wppinar/add-common-headers branch October 4, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add some additional headers for all requests
4 participants