Skip to content

Commit

Permalink
Merge pull request #128 from kiron1/client-does-not-send-fragment-of-url
Browse files Browse the repository at this point in the history
Client must not send fragment of URL
  • Loading branch information
yoshuawuyts authored Jul 20, 2020
2 parents a4ee5d0 + 8fe60a0 commit 5606a9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/client/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ impl Encoder {
let mut buf: Vec<u8> = vec![];

let mut url = req.url().path().to_owned();
if let Some(fragment) = req.url().fragment() {
url.push('#');
url.push_str(fragment);
}
if let Some(query) = req.url().query() {
url.push('?');
url.push_str(query);
Expand Down
18 changes: 18 additions & 0 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ async fn test_encode_request_with_connect() {

case.assert().await;
}

// The fragment of an URL is not send to the server, see RFC7230 and RFC3986.
#[async_std::test]
async fn test_encode_request_with_fragment() {
let case = TestCase::new_client(
"fixtures/request-with-fragment.txt",
"fixtures/response-with-host.txt",
)
.await;

let url = Url::parse("http://example.com/path?query#fragment").unwrap();
let req = Request::new(Method::Get, url);

let res = client::connect(case.clone(), req).await.unwrap();
assert_eq!(res.status(), StatusCode::Ok);

case.assert().await;
}
4 changes: 4 additions & 0 deletions tests/fixtures/request-with-fragment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GET /path?query HTTP/1.1
host: example.com
content-length: 0

0 comments on commit 5606a9d

Please sign in to comment.