Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented function which returns full uri #3096

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions actix-web/CHANGES.md
Expand Up @@ -9,6 +9,7 @@
- Add `web::Payload::to_bytes[_limited]()` helper methods.
- Add missing constructors on `HttpResponse` for several status codes.
- Add `http::header::ContentLength` typed header.
- Add `HttpRequest::full_uri()` method to get the full uri of an incoming request.

### Changed

Expand Down
19 changes: 19 additions & 0 deletions actix-web/src/request.rs
Expand Up @@ -91,6 +91,18 @@ impl HttpRequest {
&self.head().uri
}

/// Request's full uri (scheme + host + origin).
#[inline]
pub fn full_uri(&self) -> Uri {
let uri: Uri = Uri::builder()
.scheme(self.connection_info().scheme())
.authority(self.connection_info().host())
.path_and_query(self.uri().to_string())
.build()
.unwrap();
uri
}

/// Read the Request method.
#[inline]
pub fn method(&self) -> &Method {
Expand Down Expand Up @@ -963,4 +975,11 @@ mod tests {

assert!(format!("{:?}", req).contains(location_header));
}

#[test]
fn check_full_uri() {
let req = TestRequest::with_uri("/api?id=4&name=foo").to_http_request();

assert_eq!(req.full_uri(), "http://localhost:8080/api?id=4&name=foo");
}
}