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

Request.uri() returns the Path instead of the full URL #2895

Closed
joepio opened this issue Sep 27, 2022 · 1 comment · Fixed by #3096
Closed

Request.uri() returns the Path instead of the full URL #2895

joepio opened this issue Sep 27, 2022 · 1 comment · Fixed by #3096
Labels
A-web project: actix-web C-improvement Category: an improvement to existing functionality

Comments

@joepio
Copy link

joepio commented Sep 27, 2022

Expected Behavior

I need the full URL in a response handler.
Request.uri() should print the full URL (e.g. https://example.com/hello-world).

Current Behavior

Prints the path (/hello-world), which is not a valid URI.

Possible Solution

Suggestion:

  • The URI struct should always be a valid URI, which means it must have a schema + host + origin.
  • The current behavior of req.uri() returns the path of the URI. I think a .path() method is a better name for this. Add a full_uri() method that returns the full URI.

Steps to Reproduce (for bugs)

pub async fn handle_get_resource(
    req: actix_web::HttpRequest,
) -> AtomicServerResult<HttpResponse> {
    println!("URL: {}", req.uri());

Your Environment

  • Rust Version (I.e, output of rustc -V): rustc 1.63.0 (4b91a6ea7 2022-08-08)
  • Actix Web Version: 4.1.0
@robjtede robjtede added B-semver-minor A-web project: actix-web C-improvement Category: an improvement to existing functionality and removed B-semver-minor labels Sep 27, 2022
@joepio
Copy link
Author

joepio commented Sep 27, 2022

From discord @robjtede:

the key here is that Uri is designed to be used in the request-target location eg:

GET /my/path
    ^^^^^^^^ this bit

but in HTTP/2 you have to put the full URI here instead of using the Host header
i feel like a solution would be a new method .full_uri() which tries to build the whole thing from host and path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web C-improvement Category: an improvement to existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants