summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/fetch/lib.rs6
-rw-r--r--ext/http/compressible.rs10
-rw-r--r--ext/http/lib.rs23
-rw-r--r--ext/net/ops_tls.rs6
-rw-r--r--ext/web/lib.rs13
5 files changed, 22 insertions, 36 deletions
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs
index b744a9bbd..c216d53fa 100644
--- a/ext/fetch/lib.rs
+++ b/ext/fetch/lib.rs
@@ -395,11 +395,7 @@ pub async fn op_fetch_send(
let url = res.url().to_string();
let mut res_headers = Vec::new();
for (key, val) in res.headers().iter() {
- let key_bytes: &[u8] = key.as_ref();
- res_headers.push((
- ByteString(key_bytes.to_owned()),
- ByteString(val.as_bytes().to_owned()),
- ));
+ res_headers.push((key.as_str().into(), val.as_bytes().into()));
}
let stream: BytesStream = Box::pin(res.bytes_stream().map(|r| {
diff --git a/ext/http/compressible.rs b/ext/http/compressible.rs
index 21cd42c76..b85f4a325 100644
--- a/ext/http/compressible.rs
+++ b/ext/http/compressible.rs
@@ -646,15 +646,13 @@ mod tests {
#[test]
fn non_compressible_content_type() {
- assert!(!is_content_compressible(Some(&ByteString(
- b"application/vnd.deno+json".to_vec()
- ))));
+ assert!(!is_content_compressible(Some(
+ &"application/vnd.deno+json".into()
+ )));
}
#[test]
fn ncompressible_content_type() {
- assert!(is_content_compressible(Some(&ByteString(
- b"application/json".to_vec()
- ))));
+ assert!(is_content_compressible(Some(&"application/json".into())));
}
}
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index d636e206c..f0b4588c6 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -470,15 +470,12 @@ fn req_headers(
} else {
let name: &[u8] = name.as_ref();
let value = value.as_bytes();
- headers.push((ByteString(name.to_owned()), ByteString(value.to_owned())));
+ headers.push((name.into(), value.into()));
}
}
if !cookies.is_empty() {
- headers.push((
- ByteString("cookie".as_bytes().to_owned()),
- ByteString(cookies.join(cookie_sep)),
- ));
+ headers.push(("cookie".into(), cookies.join(cookie_sep).into()));
}
headers
@@ -548,7 +545,7 @@ async fn op_http_write_headers(
vary_header = Some(value);
continue;
}
- builder = builder.header(key.as_ref(), value.as_ref());
+ builder = builder.header(key.as_slice(), value.as_slice());
}
if headers_allow_compression {
@@ -566,7 +563,7 @@ async fn op_http_write_headers(
// data to make sure cache services do not serve uncompressed data to
// clients that support compression.
let vary_value = if let Some(value) = vary_header {
- if let Ok(value_str) = std::str::from_utf8(value.as_ref()) {
+ if let Ok(value_str) = std::str::from_utf8(value.as_slice()) {
if !value_str.to_lowercase().contains("accept-encoding") {
format!("Accept-Encoding, {}", value_str)
} else {
@@ -598,14 +595,14 @@ async fn op_http_write_headers(
// If user provided a ETag header for uncompressed data, we need to
// ensure it is a Weak Etag header ("W/").
if let Some(value) = etag_header {
- if let Ok(value_str) = std::str::from_utf8(value.as_ref()) {
+ if let Ok(value_str) = std::str::from_utf8(value.as_slice()) {
if !value_str.starts_with("W/") {
builder = builder.header("etag", format!("W/{}", value_str));
} else {
- builder = builder.header("etag", value.as_ref());
+ builder = builder.header("etag", value.as_slice());
}
} else {
- builder = builder.header("etag", value.as_ref());
+ builder = builder.header("etag", value.as_slice());
}
}
@@ -636,7 +633,7 @@ async fn op_http_write_headers(
}
} else {
if let Some(value) = etag_header {
- builder = builder.header("etag", value.as_ref());
+ builder = builder.header("etag", value.as_slice());
}
// If a buffer was passed, but isn't compressible, we use it to
// construct a response body.
@@ -651,10 +648,10 @@ async fn op_http_write_headers(
// Set the user provided ETag & Vary headers for a streaming response
if let Some(value) = etag_header {
- builder = builder.header("etag", value.as_ref());
+ builder = builder.header("etag", value.as_slice());
}
if let Some(value) = vary_header {
- builder = builder.header("vary", value.as_ref());
+ builder = builder.header("vary", value.as_slice());
}
let (body_tx, body_rx) = Body::channel();
diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs
index 74301292b..d6b83e6e8 100644
--- a/ext/net/ops_tls.rs
+++ b/ext/net/ops_tls.rs
@@ -156,11 +156,7 @@ impl TlsStream {
}
fn get_alpn_protocol(&mut self) -> Option<ByteString> {
- self
- .inner_mut()
- .tls
- .alpn_protocol()
- .map(|s| ByteString(s.to_owned()))
+ self.inner_mut().tls.alpn_protocol().map(|s| s.into())
}
}
diff --git a/ext/web/lib.rs b/ext/web/lib.rs
index 21fa285ba..423e53c51 100644
--- a/ext/web/lib.rs
+++ b/ext/web/lib.rs
@@ -129,8 +129,7 @@ fn op_base64_decode(input: String) -> Result<ZeroCopyBuf, AnyError> {
}
#[op]
-fn op_base64_atob(s: ByteString) -> Result<ByteString, AnyError> {
- let mut s = s.0;
+fn op_base64_atob(mut s: ByteString) -> Result<ByteString, AnyError> {
s.retain(|c| !c.is_ascii_whitespace());
// If padding is expected, fail if not 4-byte aligned
@@ -140,7 +139,7 @@ fn op_base64_atob(s: ByteString) -> Result<ByteString, AnyError> {
);
}
- Ok(ByteString(b64_decode(&s)?))
+ Ok(b64_decode(&s)?.into())
}
fn b64_decode(input: &[u8]) -> Result<Vec<u8>, AnyError> {
@@ -185,7 +184,7 @@ fn op_base64_encode(s: ZeroCopyBuf) -> Result<String, AnyError> {
#[op]
fn op_base64_btoa(s: ByteString) -> Result<String, AnyError> {
- Ok(b64_encode(&s))
+ Ok(b64_encode(s))
}
fn b64_encode(s: impl AsRef<[u8]>) -> String {
@@ -270,7 +269,7 @@ fn op_encoding_decode(
.max_utf16_buffer_length(data.len())
.ok_or_else(|| range_error("Value too large to decode."))?;
- let mut output = U16String::with_zeroes(max_buffer_length);
+ let mut output = vec![0; max_buffer_length];
if fatal {
let (result, _, written) =
@@ -278,7 +277,7 @@ fn op_encoding_decode(
match result {
DecoderResult::InputEmpty => {
output.truncate(written);
- Ok(output)
+ Ok(output.into())
}
DecoderResult::OutputFull => {
Err(range_error("Provided buffer too small."))
@@ -293,7 +292,7 @@ fn op_encoding_decode(
match result {
CoderResult::InputEmpty => {
output.truncate(written);
- Ok(output)
+ Ok(output.into())
}
CoderResult::OutputFull => Err(range_error("Provided buffer too small.")),
}