chore: upgrade percent-encoding 1.0.1 -> 2.0 (#262)
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ tracing = "0.1"
|
|||||||
http = "0.2"
|
http = "0.2"
|
||||||
base64 = "0.10"
|
base64 = "0.10"
|
||||||
|
|
||||||
percent-encoding = "1.0.1"
|
percent-encoding = "2.0"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
tokio-util = { version = "0.2", features = ["codec"] }
|
tokio-util = { version = "0.2", features = ["codec"] }
|
||||||
async-stream = "0.2"
|
async-stream = "0.2"
|
||||||
|
|||||||
+16
-14
@@ -1,9 +1,20 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use http::header::{HeaderMap, HeaderValue};
|
use http::header::{HeaderMap, HeaderValue};
|
||||||
use percent_encoding::{percent_decode, percent_encode, EncodeSet, DEFAULT_ENCODE_SET};
|
use percent_encoding::{percent_decode, percent_encode, AsciiSet, CONTROLS};
|
||||||
use std::{error::Error, fmt};
|
use std::{borrow::Cow, error::Error, fmt};
|
||||||
use tracing::{debug, trace, warn};
|
use tracing::{debug, trace, warn};
|
||||||
|
|
||||||
|
const ENCODING_SET: &AsciiSet = &CONTROLS
|
||||||
|
.add(b' ')
|
||||||
|
.add(b'"')
|
||||||
|
.add(b'#')
|
||||||
|
.add(b'<')
|
||||||
|
.add(b'>')
|
||||||
|
.add(b'`')
|
||||||
|
.add(b'?')
|
||||||
|
.add(b'{')
|
||||||
|
.add(b'}');
|
||||||
|
|
||||||
const GRPC_STATUS_HEADER_CODE: &str = "grpc-status";
|
const GRPC_STATUS_HEADER_CODE: &str = "grpc-status";
|
||||||
const GRPC_STATUS_MESSAGE_HEADER: &str = "grpc-message";
|
const GRPC_STATUS_MESSAGE_HEADER: &str = "grpc-message";
|
||||||
const GRPC_STATUS_DETAILS_HEADER: &str = "grpc-status-details-bin";
|
const GRPC_STATUS_DETAILS_HEADER: &str = "grpc-status-details-bin";
|
||||||
@@ -370,18 +381,9 @@ impl Status {
|
|||||||
header_map.insert(GRPC_STATUS_HEADER_CODE, self.code.to_header_value());
|
header_map.insert(GRPC_STATUS_HEADER_CODE, self.code.to_header_value());
|
||||||
|
|
||||||
if !self.message.is_empty() {
|
if !self.message.is_empty() {
|
||||||
let is_need_encode = self
|
let to_write = Bytes::copy_from_slice(
|
||||||
.message
|
Cow::from(percent_encode(&self.message().as_bytes(), ENCODING_SET)).as_bytes(),
|
||||||
.as_bytes()
|
);
|
||||||
.iter()
|
|
||||||
.any(|&x| DEFAULT_ENCODE_SET.contains(x));
|
|
||||||
let to_write = if is_need_encode {
|
|
||||||
percent_encode(&self.message().as_bytes(), DEFAULT_ENCODE_SET)
|
|
||||||
.to_string()
|
|
||||||
.into()
|
|
||||||
} else {
|
|
||||||
Bytes::copy_from_slice(self.message().as_bytes())
|
|
||||||
};
|
|
||||||
|
|
||||||
header_map.insert(
|
header_map.insert(
|
||||||
GRPC_STATUS_MESSAGE_HEADER,
|
GRPC_STATUS_MESSAGE_HEADER,
|
||||||
|
|||||||
Reference in New Issue
Block a user