| 184 | } |
| 185 | |
| 186 | std::string Uri::path() const { |
| 187 | const auto& segments = impl_->path_segments_; |
| 188 | |
| 189 | bool must_prepend_slash = impl_->is_absolute_path_; |
| 190 | #ifdef _WIN32 |
| 191 | // On Windows, "file:///C:/foo" should have path "C:/foo", not "/C:/foo", |
| 192 | // despite it being absolute. |
| 193 | // (see https://tools.ietf.org/html/rfc8089#page-13) |
| 194 | if (impl_->is_absolute_path_ && impl_->is_file_uri_ && segments.size() > 0 && |
| 195 | IsDriveSpec(segments[0])) { |
| 196 | must_prepend_slash = false; |
| 197 | } |
| 198 | #endif |
| 199 | |
| 200 | std::stringstream ss; |
| 201 | if (must_prepend_slash) { |
| 202 | ss << "/"; |
| 203 | } |
| 204 | bool first = true; |
| 205 | for (const auto& seg : segments) { |
| 206 | if (!first) { |
| 207 | ss << "/"; |
| 208 | } |
| 209 | first = false; |
| 210 | ss << UriUnescape(seg); |
| 211 | } |
| 212 | return std::move(ss).str(); |
| 213 | } |
| 214 | |
| 215 | std::string Uri::query_string() const { return TextRangeToString(impl_->uri_.query); } |
| 216 | |