Skip to content

Commit 37a5499

Browse files
committed
Parse urlencoed URI path
1 parent 6b70a56 commit 37a5499

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
Cargo.lock
33

44
.vscode
5+
/.idea
6+

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ tracing-error = "0.2.0"
6363
tracing-futures = "0.2.5"
6464
tracing-subscriber = { version = "0.3.5", optional = true, features = ["env-filter", "time"] }
6565
transform-stream = "0.2.0"
66+
urlencoding = "2.1.0"
6667
uuid = { version = "0.8.2", features = ["v4"] }
6768
xml-rs = "0.8.3"
6869

src/service.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::streams::multipart::{self, Multipart};
1515
use crate::utils::{crypto, Apply};
1616
use crate::{Body, BoxStdError, Method, Mime, Request, Response};
1717

18+
use std::borrow::Cow;
1819
use std::fmt::{self, Debug};
1920
use std::io;
2021
use std::mem;
@@ -143,7 +144,8 @@ impl S3Service {
143144
/// Returns an `Err` if any component failed
144145
pub async fn handle(&self, mut req: Request) -> S3Result<Response> {
145146
let body = mem::take(req.body_mut());
146-
let path = extract_s3_path(&req)?;
147+
let uri_path = decode_uri_path(&req)?;
148+
let path = extract_s3_path(&uri_path)?;
147149
let headers = extract_headers(&req)?;
148150
let query_strings = extract_qs(&req)?;
149151
let mime = extract_mime(&headers)?;
@@ -177,9 +179,15 @@ impl S3Service {
177179
}
178180
}
179181

182+
/// Extract urlencoded URI from Request
183+
fn decode_uri_path(req: &Request) -> S3Result<Cow<'_, str>> {
184+
urlencoding::decode(req.uri().path())
185+
.map_err(|e| code_error!(InvalidURI, "Cannot url decode uri path", e))
186+
}
187+
180188
/// util function
181-
fn extract_s3_path(req: &Request) -> S3Result<S3Path<'_>> {
182-
let result = S3Path::try_from_path(req.uri().path());
189+
fn extract_s3_path(uri_path: &str) -> S3Result<S3Path<'_>> {
190+
let result = S3Path::try_from_path(uri_path);
183191
let err = try_err!(result);
184192
let (code, msg) = match *err.kind() {
185193
S3PathErrorKind::InvalidPath => {

0 commit comments

Comments
 (0)