Skip to content

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

@joepio

Description

@joepio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-webproject: actix-webC-improvementCategory: an improvement to existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions