iron / iron

An Extensible, Concurrent Web Framework for Rust
MIT License
6.14k stars 402 forks source link

URL Parser Unable to Handle IPv6 Addresses #609

Open sstelfox opened 5 years ago

sstelfox commented 5 years ago

This seems to be a regression between 0.6.0 and master. The issue currently exists on master and I'm not exactly sure why, but it is very easy to reproduce.

extern crate iron;
extern crate hyper;

use hyper::StatusCode;
use iron::prelude::*;

fn test_handler(_: &mut Request) -> IronResult<Response> {
    Ok(Response::with((StatusCode::OK, "Test response\n")))
}

fn main() {
    Iron::new(test_handler).http("[::1]:9292");
}

Running the code above has Iron successfully listen on the port. Using curl the request fails with a 400 Bad Request like so:

$ curl -v http://[::1]:9292/
*   Trying ::1...
* TCP_NODELAY set
* Connected to ::1 (::1) port 9292 (#0)
> GET / HTTP/1.1
> Host: [::1]:9292
> User-Agent: curl/7.59.0
> Accept: */*
> 
< HTTP/1.1 400 Bad Request
< content-length: 0
< date: Sun, 31 Mar 2019 22:01:34 GMT
< 
* Connection #0 to host ::1 left intact

And the server produces the following error when I setup and configure the rust logger:

ERROR 2019-03-31T22:01:01Z: iron::iron: Error creating request:
    Couldn't parse requested URL: invalid IPv6 address
Abhinesh612 commented 6 months ago

on my system it work perfectly

curl outptut curl -v http://[::1]9292

*   Trying [::1]:9292...
* Connected to ::1 (::1) port 9292
> GET / HTTP/1.1
> Host: [::1]:9292
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 14
< Content-Type: text/plain
< Date: Fri, 12 Apr 2024 17:34:27 GMT
<
Test response
* Connection #0 to host ::1 left intact

rust code

extern crate iron;

use iron::prelude::*;
use iron::status;

fn test_handler(_: &mut Request) -> IronResult<Response> {
    Ok(Response::with((status::Ok, "Test response\n")))
}

fn main() {
    Iron::new(test_handler).http("[::1]:9292");
}