aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/bindings/str.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2014-05-28 11:28:33 +0530
committerManish Goregaokar <manishsmail@gmail.com>2014-05-28 20:49:13 +0530
commit5f860bb61221d9fc1afce35e896db2805e4cdb5b (patch)
treefd93bbe8d2b24b2689e62e47dc93b5da775c7077 /src/components/script/dom/bindings/str.rs
parent096eea8369fbd15f2412d52988259eb598b7d306 (diff)
downloadservo-5f860bb61221d9fc1afce35e896db2805e4cdb5b.tar.gz
servo-5f860bb61221d9fc1afce35e896db2805e4cdb5b.zip
Request header and postdata support for XHR
Diffstat (limited to 'src/components/script/dom/bindings/str.rs')
-rw-r--r--src/components/script/dom/bindings/str.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/components/script/dom/bindings/str.rs b/src/components/script/dom/bindings/str.rs
index e0ac5e57a2e..a662470aeab 100644
--- a/src/components/script/dom/bindings/str.rs
+++ b/src/components/script/dom/bindings/str.rs
@@ -37,6 +37,7 @@ impl ByteString {
}
}).collect())
}
+
pub fn is_token(&self) -> bool {
let ByteString(ref vec) = *self;
vec.iter().all(|&x| {
@@ -51,6 +52,55 @@ impl ByteString {
}
})
}
+
+ pub fn is_field_value(&self) -> bool {
+ // Classifications of characters necessary for the [CRLF] (SP|HT) rule
+ #[deriving(Eq)]
+ enum PreviousCharacter {
+ Other,
+ CR,
+ LF,
+ SP_HT // SP or HT
+ }
+ let ByteString(ref vec) = *self;
+ let mut prev = Other; // The previous character
+ vec.iter().all(|&x| {
+ // http://tools.ietf.org/html/rfc2616#section-2.2
+ match x {
+ 13 => { // CR
+ if prev == Other || prev == SP_HT {
+ prev = CR;
+ true
+ } else {
+ false
+ }
+ },
+ 10 => { // LF
+ if prev == CR {
+ prev = LF;
+ true
+ } else {
+ false
+ }
+ },
+ 32 | 9 => { // SP | HT
+ if prev == LF || prev == SP_HT {
+ prev = SP_HT;
+ true
+ } else {
+ false
+ }
+ },
+ 0..31 | 127 => false, // CTLs
+ x if x > 127 => false, // non ASCII
+ _ if prev == Other || prev == SP_HT => {
+ prev = Other;
+ true
+ },
+ _ => false // Previous character was a CR/LF but not part of the [CRLF] (SP|HT) rule
+ }
+ })
+ }
}
impl Hash for ByteString {