diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-08-10 23:35:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-10 15:35:01 -0600 |
commit | 634f5ccd49d3b998a9b96af2ad8c4d0ed2235700 (patch) | |
tree | ba3641569e19fae8706550a82a8733603f25ba6d /ext/http/http_next.rs | |
parent | 69387f0b0c4ac3be4ce88f9139d141cbc7da277b (diff) |
perf(http): use Cow<[u8]> for setting header (#20112)
Diffstat (limited to 'ext/http/http_next.rs')
-rw-r--r-- | ext/http/http_next.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 3c3724924..2e9b315ca 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -385,18 +385,23 @@ pub fn op_http_read_request_body( state.resource_table.add_rc(body_resource) } -#[op2] +#[op2(fast)] pub fn op_http_set_response_header( #[smi] slab_id: SlabId, - #[serde] name: ByteString, - #[serde] value: ByteString, + #[string(onebyte)] name: Cow<[u8]>, + #[string(onebyte)] value: Cow<[u8]>, ) { let mut http = slab_get(slab_id); let resp_headers = http.response().headers_mut(); // These are valid latin-1 strings let name = HeaderName::from_bytes(&name).unwrap(); - // SAFETY: These are valid latin-1 strings - let value = unsafe { HeaderValue::from_maybe_shared_unchecked(value) }; + let value = match value { + Cow::Borrowed(bytes) => HeaderValue::from_bytes(bytes).unwrap(), + // SAFETY: These are valid latin-1 strings + Cow::Owned(bytes_vec) => unsafe { + HeaderValue::from_maybe_shared_unchecked(bytes::Bytes::from(bytes_vec)) + }, + }; resp_headers.append(name, value); } |