Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

perf(providers): get response as bytes #1536

Merged
merged 1 commit into from
Jul 30, 2022

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Jul 29, 2022

Motivation

uses resp.bytes() instead of resp.text()

text decodes the body and scans the entire body. this is a bit redundant for json since deserialization is expected to fail if anyway

reqwest's json function is also just this:

pub async fn json<T: DeserializeOwned>(self) -> crate::Result<T> {
        let full = self.bytes().await?;

        serde_json::from_slice(&full).map_err(crate::error::decode)
    }

Solution

get bytes and deserialize from_slice, and only convert to String in error case

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

@gakonst gakonst merged commit e855676 into gakonst:master Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants