Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the amount of dom code used outside the script crate. #11656

Merged
merged 8 commits into from Jun 7, 2016

Move trim_http_whitespace to net_traits.

  • Loading branch information
Ms2ger committed Jun 7, 2016
commit 80fc66673473910ec325eb35d1e2e040f9e5277a
@@ -573,3 +573,27 @@ pub enum NetworkError {
/// SSL validation error that has to be handled in the HTML parser
SslValidation(Url),
}

/// Normalize `slice`, as defined by
/// [the Fetch Spec](https://fetch.spec.whatwg.org/#concept-header-value-normalize).
pub fn trim_http_whitespace(mut slice: &[u8]) -> &[u8] {
const HTTP_WS_BYTES: &'static [u8] = b"\x09\x0A\x0D\x20";

loop {
match slice.split_first() {
Some((first, remainder)) if HTTP_WS_BYTES.contains(first) =>
slice = remainder,
_ => break,
}
}

loop {
match slice.split_last() {
Some((last, remainder)) if HTTP_WS_BYTES.contains(last) =>
slice = remainder,
_ => break,
}
}

slice
}
@@ -46,6 +46,7 @@ use js::jsapi::{JSContext, JS_ParseJSON, RootedValue};
use js::jsval::{JSVal, NullValue, UndefinedValue};
use msg::constellation_msg::{PipelineId, ReferrerPolicy};
use net_traits::CoreResourceMsg::Load;
use net_traits::trim_http_whitespace;
use net_traits::{AsyncResponseListener, AsyncResponseTarget, Metadata, NetworkError, RequestSource};
use net_traits::{LoadConsumer, LoadContext, LoadData, ResourceCORSData, CoreResourceThread, LoadOrigin};
use network_listener::{NetworkListener, PreInvoke};
@@ -1506,27 +1507,3 @@ pub fn is_field_value(slice: &[u8]) -> bool {
}
})
}

/// Normalize `self`, as defined by
/// [the Fetch Spec](https://fetch.spec.whatwg.org/#concept-header-value-normalize).
pub fn trim_http_whitespace(mut slice: &[u8]) -> &[u8] {
const HTTP_WS_BYTES: &'static [u8] = b"\x09\x0A\x0D\x20";

loop {
match slice.split_first() {
Some((first, remainder)) if HTTP_WS_BYTES.contains(first) =>
slice = remainder,
_ => break,
}
}

loop {
match slice.split_last() {
Some((last, remainder)) if HTTP_WS_BYTES.contains(last) =>
slice = remainder,
_ => break,
}
}

slice
}
@@ -5,3 +5,25 @@
extern crate net_traits;

#[cfg(test)] mod image;

#[test]
fn test_trim_http_whitespace() {
fn test_trim(in_: &[u8], out: &[u8]) {
let b = net_traits::trim_http_whitespace(in_);
assert_eq!(b, out);
}

test_trim(b"", b"");

test_trim(b" ", b"");
test_trim(b"a", b"a");
test_trim(b" a", b"a");
test_trim(b"a ", b"a");
test_trim(b" a ", b"a");

test_trim(b"\t", b"");
test_trim(b"a", b"a");
test_trim(b"\ta", b"a");
test_trim(b"a\t", b"a");
test_trim(b"\ta\t", b"a");
}

This file was deleted.

@@ -15,5 +15,4 @@ extern crate url;
#[cfg(test)] mod dom {
mod bindings;
mod blob;
mod xmlhttprequest;
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.