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

Custom Headers on Request #291

Open
DanStockham opened this issue Jul 31, 2021 · 0 comments
Open

Custom Headers on Request #291

DanStockham opened this issue Jul 31, 2021 · 0 comments

Comments

@DanStockham
Copy link

We need a way to set the Accept-Language headers before a request is sent out the Fitbit Web API. In particular, these support forum questions is what I am referring to:

https://community.fitbit.com/t5/Web-API-Development/Does-not-get-the-exact-weight-if-in-lbs/td-p/1605424
https://community.fitbit.com/t5/Web-API-Development/Unit-and-Value-doesnt-match-in-the-Get-Profile-response/m-p/1385899

Basically, without setting and specifying the Accept-Language header in the request, The web api will always assume metrics. Which is fine if your configure measurements are in the metric system but any other selection in your profile the values get converted and thus truncated in the process.

There needs to be a way set the headers on the request. I thought the interceptors would allow for custom headers but from looking at the source code, it's actually passing back a "fake" response and I think this is used for testing

...
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            Task<HttpResponseMessage> interceptorFakeResponse = null;
            Debug.WriteLine("Entering Http client's request message handler. Request details: {0}", request.ToString());

            if (interceptor != null)
                interceptorFakeResponse = interceptor.InterceptRequest(request, cancellationToken, FitbitClient);

            if (interceptorFakeResponse != null) //then highjack the request pipeline and return the HttpResponse returned by interceptor. Invoke Response handler at return.
            {
                //If we are faking the response, have the courtesy of setting the original HttpRequestMessage
                interceptorFakeResponse.Result.RequestMessage = request;
                return interceptorFakeResponse.ContinueWith(
                        responseTask => ResponseHandler(responseTask, cancellationToken).Result
                    );
            }
            else //Let the base object continue with the request pipeline. Invoke Response handler at return.
            {
                return base.SendAsync(request, cancellationToken).ContinueWith(
                     responseTask => ResponseHandler(responseTask, cancellationToken).Result
                 );
            }
        }
...
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

No branches or pull requests

1 participant