Skip to content

Expose the new optional event headers through Plausible. #30

@leogdion

Description

@leogdion

⚠️ Potential issue | 🟠 Major

Expose the new optional event headers through Plausible.

The generated client now supports X-Forwarded-For and X-Debug-Request, but this wrapper still hardcodes only User-Agent. As shipped, callers cannot use two of the new POST /event features from the public API.

Suggested direction
-  public func postEvent(_ event: Event) async throws {
+  public func postEvent(
+    _ event: Event,
+    forwardedFor: String? = nil,
+    debugRequest: Bool? = nil
+  ) async throws {
     _ = try await client.post_sol_event(
-      headers: .init(User_hyphen_Agent: userAgent),
+      headers: .init(
+        User_hyphen_Agent: userAgent,
+        X_hyphen_Forwarded_hyphen_For: forwardedFor,
+        X_hyphen_Debug_hyphen_Request: debugRequest
+      ),
       body: .init(event: event, defaultDomain: defaultDomain)
     ).accepted
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  public func postEvent(
    _ event: Event,
    forwardedFor: String? = nil,
    debugRequest: Bool? = nil
  ) async throws {
    _ = try await client.post_sol_event(
      headers: .init(
        User_hyphen_Agent: userAgent,
        X_hyphen_Forwarded_hyphen_For: forwardedFor,
        X_hyphen_Debug_hyphen_Request: debugRequest
      ),
      body: .init(event: event, defaultDomain: defaultDomain)
    ).accepted
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/AviaryInsights/Plausible.swift` around lines 186 - 189, The
Plausible.postEvent wrapper currently hardcodes only the User-Agent header when
calling client.post_sol_event, so add optional parameters to Plausible.postEvent
(e.g., xForwardedFor: String? and xDebugRequest: String?) or a single optional
headers struct, surface them in the public API, and pass them into the generated
client's headers initializer alongside User_hyphen_Agent; update the
Plausible.postEvent signature and call to client.post_sol_event to include
X-Forwarded-For and X-Debug-Request when non-nil so callers can supply those new
optional event headers.

Originally posted by @coderabbitai[bot] in #26 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions