v icon indicating copy to clipboard operation
v copied to clipboard

http and https are incorrectly recognized

Open Bowero opened this issue 7 years ago • 4 comments

V version: V 0.1.18 OS: Arch Linux

Description If you try to create a HTTP request with basic HTTP authentication, http or https, won't be the first characters in your URL.

An example is:

h7pPEI6skeOL2g:V5Ph2a9b2m0csBzQkitFB1P-Y34@https://www.reddit.com/api/v1/access_token&grant_type=password&username=Bowero&password=9lzTREM4ukhY

Because of this, the current http module will give you an error, this one to be specific:

V panic: http.request.do: unsupported scheme: h7pPEI6skeOL2g

This is not correct. The module should therefore try to recognize if http or https is part of the string, instead of trying to check if it starts with that.

The problem can be found in this function:

https://github.com/vlang/v/blob/57880aed185e9b81e8c66a47c975d61e5d0eaaa3/vlib/http/http.v#L124-L143

All of the credentials and tokens have been modified, don't bother trying.

Bowero avatar Aug 24 '19 16:08 Bowero

Even better would be to have a way to authenticate without modifying the URL scheme.

Bowero avatar Aug 24 '19 16:08 Bowero

@Bowero your example is invalid I'm pretty sure the url format should be in https://joe:[email protected]

you can try this demo to see:

module main

import net.urllib

fn main() {
    test_url := 'https://joe:[email protected]:8080/som/url?param1=test1&param2=test2&foo=bar#testfragment'
    u := urllib.parse(test_url) or {
	panic('error parsing url')
    }
    println('scheme is: $url.scheme');
}

take a look at section 3.1 https://www.ietf.org/rfc/rfc1738.txt

joe-conigliaro avatar Aug 25 '19 07:08 joe-conigliaro

Oh, how stupid. I am sorry and thank you for looking into this!

Bowero avatar Aug 25 '19 07:08 Bowero

@Bowero hehe I do things like that all the time :D

joe-conigliaro avatar Aug 25 '19 07:08 joe-conigliaro