From 63f2e95be3e816fa658fa8f9c248f3fa6a0687f2 Mon Sep 17 00:00:00 2001 From: tottoto Date: Thu, 12 Jan 2023 02:16:59 +0900 Subject: [PATCH] chore(web): Update to base64 0.21 (#1235) --- tonic-web/tests/integration/Cargo.toml | 2 +- tonic-web/tests/integration/src/lib.rs | 19 +++++++++++++++++++ tonic-web/tests/integration/tests/grpc_web.rs | 10 ++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tonic-web/tests/integration/Cargo.toml b/tonic-web/tests/integration/Cargo.toml index 9e7facd..e97f15f 100644 --- a/tonic-web/tests/integration/Cargo.toml +++ b/tonic-web/tests/integration/Cargo.toml @@ -7,7 +7,7 @@ version = "0.1.0" license = "MIT" [dependencies] -base64 = "0.13" +base64 = "0.21" bytes = "1.0" hyper = "0.14" prost = "0.11" diff --git a/tonic-web/tests/integration/src/lib.rs b/tonic-web/tests/integration/src/lib.rs index 3944dc1..3dcd12d 100644 --- a/tonic-web/tests/integration/src/lib.rs +++ b/tonic-web/tests/integration/src/lib.rs @@ -67,3 +67,22 @@ impl Test for Svc { )) } } + +pub mod util { + pub mod base64 { + use base64::{ + alphabet, + engine::{ + general_purpose::{GeneralPurpose, GeneralPurposeConfig}, + DecodePaddingMode, + }, + }; + + pub const STANDARD: GeneralPurpose = GeneralPurpose::new( + &alphabet::STANDARD, + GeneralPurposeConfig::new() + .with_encode_padding(true) + .with_decode_padding_mode(DecodePaddingMode::Indifferent), + ); + } +} diff --git a/tonic-web/tests/integration/tests/grpc_web.rs b/tonic-web/tests/integration/tests/grpc_web.rs index dc68ca2..e062a83 100644 --- a/tonic-web/tests/integration/tests/grpc_web.rs +++ b/tonic-web/tests/integration/tests/grpc_web.rs @@ -1,5 +1,6 @@ use std::net::SocketAddr; +use base64::Engine as _; use bytes::{Buf, BufMut, Bytes, BytesMut}; use hyper::http::{header, StatusCode}; use hyper::{Body, Client, Method, Request, Uri}; @@ -110,7 +111,9 @@ fn build_request(base_uri: String, content_type: &str, accept: &str) -> Request< let bytes = match content_type { "grpc-web" => encode_body(), - "grpc-web-text" => base64::encode(encode_body()).into(), + "grpc-web-text" => integration::util::base64::STANDARD + .encode(encode_body()) + .into(), _ => panic!("invalid content type {}", content_type), }; @@ -128,7 +131,10 @@ async fn decode_body(body: Body, content_type: &str) -> (Output, Bytes) { let mut body = hyper::body::to_bytes(body).await.unwrap(); if content_type == "application/grpc-web-text+proto" { - body = base64::decode(body).unwrap().into() + body = integration::util::base64::STANDARD + .decode(body) + .unwrap() + .into() } body.advance(1);