Skip to content

fix: Correct SecureHttpClient request/response handling for Dexcom API#7

Draft
sam0jones0 wants to merge 12 commits into
mainfrom
test-on-device
Draft

fix: Correct SecureHttpClient request/response handling for Dexcom API#7
sam0jones0 wants to merge 12 commits into
mainfrom
test-on-device

Conversation

@sam0jones0
Copy link
Copy Markdown
Owner

Overview

Resolves HTTP 500 errors encountered during Dexcom API authentication (LoginPublisherAccountById) after refactoring DexcomClient to use SecureHttpClient.

Problem

The previous SecureHttpClient implementation formatted POST requests incorrectly and mishandled response parsing, leading to server errors from the Dexcom API.

Solution

  • Refactored SecureHttpClient::send to correctly format HTTP POST requests:
    • Ensured proper Content-Length header calculation.
    • Used client->write() instead of client->println() for sending the request body to avoid extra newlines.
    • Verified correct header/body separation (\r\n).
  • Refactored SecureHttpClient::readResponse and parseResponse to reliably handle HTTP responses:
    • Separated header and body reading logic.
    • Parsed status code and headers first.
    • Read the response body accurately based on the Content-Length header.
  • Added detailed debug logging to SecureHttpClient to aid troubleshooting (can be removed later if desired).
  • Updated unit tests for SecureHttpClient to cover the corrected request formatting and response handling logic.

Result

The DexcomClient now successfully authenticates and communicates with the Dexcom API using the corrected SecureHttpClient, resolving the previous HTTP 500 errors.

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.

1 participant