| 226 | } |
| 227 | |
| 228 | void ParseURI(StringPiece remaining, StringPiece* scheme, StringPiece* host, |
| 229 | StringPiece* path) { |
| 230 | // 0. Parse scheme |
| 231 | // Make sure scheme matches [a-zA-Z][0-9a-zA-Z.]* |
| 232 | // TODO(keveman): Allow "+" and "-" in the scheme. |
| 233 | // Keep URI pattern in tensorboard/backend/server.py updated accordingly |
| 234 | if (!strings::Scanner(remaining) |
| 235 | .One(strings::Scanner::LETTER) |
| 236 | .Many(strings::Scanner::LETTER_DIGIT_DOT) |
| 237 | .StopCapture() |
| 238 | .OneLiteral("://") |
| 239 | .GetResult(&remaining, scheme)) { |
| 240 | // If there's no scheme, assume the entire string is a path. |
| 241 | *scheme = StringPiece(remaining.begin(), 0); |
| 242 | *host = StringPiece(remaining.begin(), 0); |
| 243 | *path = remaining; |
| 244 | return; |
| 245 | } |
| 246 | |
| 247 | // 1. Parse host |
| 248 | if (!strings::Scanner(remaining).ScanUntil('/').GetResult(&remaining, host)) { |
| 249 | // No path, so the rest of the URI is the host. |
| 250 | *host = remaining; |
| 251 | *path = StringPiece(remaining.end(), 0); |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | // 2. The rest is the path |
| 256 | *path = remaining; |
| 257 | } |
| 258 | |
| 259 | string CreateURI(StringPiece scheme, StringPiece host, StringPiece path) { |
| 260 | if (scheme.empty()) { |