-
Notifications
You must be signed in to change notification settings - Fork 42
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
JsonHandler not removable as described in documentation #105
Comments
Hi, Your correct it doesn't remove it from the list - I'll get that changed in the docs. But it does skip the functionality protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request)
{
request.SetConfig(_config);
if (_config.UseDefaultHandlers)
{
request.Content = GetContent(request);
if (!request.Headers.Accept.Any())
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Config.JsonMediaType));
request.ExpectJsonResponse(true);
}
return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
} So it won't add the json headers or try to process the response as json. Are you getting a specific issue that I can help with? |
Yes. I tried to read an "octet-stream" and the default Json Handler destroys the streams inside the octet-stream. I built another handler.
And I use it like this: and later:
I found no other way to get a correct octet-stream from the rest client. And I found nothing in the documentation. I first tried to take the hrm.Content and cast that to a byte array, but it was already disposed (from the JsonHandler I think), so I couldn't get the array and casting the result directly wasn't helpful. Maybe you could give an example in the documentation for idiots to come (like me :D). |
Hi, I'll take a further look. Your correct the response stream is disposed of, this is to stop any memory leaks, but I see it's a hindrance in your case. I feel like I need to add a helper to get the response in the handler like I do with the request. Which is exactly the workaround you have had to do. I also feel getting a stream is something I should support so I'll add both features. |
I tried to unset the DefaultJsonHandler like described by this link:
https://restclient.dalsoft.io/docs/default-pipeline/
But this:
Config config = new Config()
{
UseDefaultHandlers = false
}.UseFormUrlEncodedHandler().UseMultipartFormDataHandler();
creates a config with all three handlers:
{DalSoft.RestClient.Handlers.DefaultJsonHandler},
{DalSoft.RestClient.Handlers.FormUrlEncodedHandler} and
{DalSoft.RestClient.Handlers.MultipartFormDataHandler}
But it is written, that UseDefaultHandlers = false would remove the DefaultJsonHandler from the list, so it should be done. Right? ;)
p.s.: I tried also
Config config = new Config().UseFormUrlEncodedHandler().UseMultipartFormDataHandler().UseNoDefaultHandlers();
But to the same result.
The text was updated successfully, but these errors were encountered: