Skip to content

Replace host and port parameters with unified endpoint parameter for HTTP and MQTT connections#4706

Draft
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-4705
Draft

Replace host and port parameters with unified endpoint parameter for HTTP and MQTT connections#4706
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-4705

Conversation

Copy link
Copy Markdown

Copilot AI commented Aug 22, 2025

This PR replaces separate host and port parameters with a single endpoint parameter for HTTP and MQTT connections, unifying the configuration approach with the Kafka connection feature introduced in issue #4666.

Changes Made

Core Structure Updates

  • SenderThreadParams: Replaced separate ip and port fields with a unified endpoint field (format: "host:port")
  • MQTT Functions: Updated sendMqttNotification() and getConnection() to accept endpoint parameter instead of separate host/port
  • Notification Pipeline: Modified notification creation and consumption to use endpoint consistently

New Helper Functions

Added utility functions in src/lib/common/string.h:

  • buildEndpoint(host, port) - Constructs endpoint string from host and port
  • parseEndpoint(endpoint, host, port) - Parses endpoint string back to host and port with IPv6 support
  • parseUrl(url, host, port, path, protocol, endpoint) - Overloaded version that extracts endpoint directly

Updated Flow

  1. Creation: Notifier.cpp uses overloaded parseUrl() to extract endpoint directly from URL parsing
  2. Storage: SenderThreadParams stores single endpoint string
  3. Consumption: doNotify.cpp parses endpoint for HTTP calls or passes directly to MQTT

Benefits

  • Unified Configuration: Consistent endpoint parameter across HTTP, MQTT, and Kafka
  • Simplified Parameters: Single endpoint instead of separate host/port reduces complexity
  • Reduced Errors: Less chance for host/port mismatch issues
  • Optimized Flow: Endpoint extracted directly from URL parsing, no roundtrip through host/port
  • Future-ready: Easier extension for additional protocols

Backward Compatibility

  • HTTP httpRequestSend() function signature unchanged to minimize impact
  • Existing URL parsing and notification logic continue to work
  • No changes to external APIs or configuration files

Testing

  • Added comprehensive unit tests for endpoint helper functions
  • Added tests for new parseUrl overload with endpoint parameter
  • Included edge cases, IPv6 support, and roundtrip validation
  • Verified existing notification behavior remains unchanged

Fixes #4705.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Copy Markdown
Author

Copilot AI commented Aug 22, 2025

@fgalan 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] Adopt endpoint as the way to define the connection destination for HTTP and MQTT. Replacing parameters host and port Replace host and port parameters with unified endpoint parameter for HTTP and MQTT connections Aug 22, 2025
Copilot AI requested a review from fgalan August 22, 2025 06:51
@fgalan
Copy link
Copy Markdown
Member

fgalan commented Aug 22, 2025

@copilot I don't like this solution proposal too much...

Instead of

  paramsP->endpoint         = buildEndpoint(host, port);

The endpoint parameters should come set from the very beginning, instead of building if from port and host. In other words, host and port should not be needed at this point.

- Add overloaded parseUrl function that also extracts endpoint directly
- Update Notifier.cpp to use endpoint from parseUrl instead of buildEndpoint
- Add comprehensive unit tests for new parseUrl overload
- Addresses feedback: endpoint comes from the beginning, no host/port roundtrip

Co-authored-by: fgalan <[email protected]>
Copy link
Copy Markdown
Author

Copilot AI commented Aug 22, 2025

@copilot I don't like this solution proposal too much...

Instead of
...

You're absolutely right! I've addressed this by adding an overloaded version of parseUrl() that extracts the endpoint directly during URL parsing, eliminating the need for the buildEndpoint(host, port) roundtrip.

The change ensures the endpoint parameter comes from the very beginning of the URL parsing process, so host and port are no longer needed at the point where we build the SenderThreadParams.

The commit 5111726 implements this optimization.

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.

Adopt endpoint as the way to define the connection destination for HTTP and MQTT. Replacing parameters host and port

2 participants