| 119 | } |
| 120 | return offset; |
| 121 | } |
| 122 | |
| 123 | static size_t readAuthToken(SC::Span<const char> bytes, size_t offset, size_t end) |
| 124 | { |
| 125 | while (offset < end and isHttpTokenCharacter(bytes[offset])) |
| 126 | { |
| 127 | offset += 1; |
| 128 | } |
| 129 | return offset; |
| 130 | } |
| 131 | |
| 132 | static bool asciiStartsWith(SC::StringSpan text, SC::StringSpan prefix) |
| 133 | { |
| 134 | if (text.sizeInBytes() < prefix.sizeInBytes()) |
| 135 | { |
| 136 | return false; |
| 137 | } |
| 138 | const SC::Span<const char> textBytes = text.toCharSpan(); |
| 139 | const SC::Span<const char> prefixBytes = prefix.toCharSpan(); |
| 140 | return ::memcmp(textBytes.data(), prefixBytes.data(), prefixBytes.sizeInBytes()) == 0; |
| 141 | } |
| 142 | |
| 143 | static bool sessionIsAsciiWhiteSpace(char c) { return c == ' ' or c == '\t' or c == '\r' or c == '\n'; } |
| 144 | |
| 145 | static bool sessionHasHttpHeaderUnsafeBytes(SC::StringSpan value) |
| 146 | { |
| 147 | const SC::Span<const char> bytes = value.toCharSpan(); |
| 148 | for (size_t idx = 0; idx < bytes.sizeInBytes(); ++idx) |
| 149 | { |
| 150 | if (bytes[idx] == '\r' or bytes[idx] == '\n' or bytes[idx] == '\0') |
| 151 | { |
| 152 | return true; |
| 153 | } |
| 154 | } |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | static SC::StringSpan trimAsciiWhiteSpace(SC::StringSpan text) |
| 159 | { |
| 160 | const SC::Span<const char> bytes = text.toCharSpan(); |
| 161 | size_t start = 0; |
| 162 | size_t end = bytes.sizeInBytes(); |
| 163 | while (start < end and sessionIsAsciiWhiteSpace(bytes[start])) |
| 164 | { |
| 165 | start += 1; |
| 166 | } |
| 167 | while (end > start and sessionIsAsciiWhiteSpace(bytes[end - 1])) |
| 168 | { |
| 169 | end -= 1; |
| 170 | } |
| 171 | return {{bytes.data() + start, end - start}, false, SC::StringEncoding::Ascii}; |
| 172 | } |
| 173 | |
| 174 | static SC::StringSpan sliceString(SC::StringSpan text, size_t start, size_t end) |
| 175 | { |
| 176 | const SC::Span<const char> bytes = text.toCharSpan(); |
no test coverage detected