maxcnunes / waitforit

Wait until an address become available.
MIT License
173 stars 26 forks source link

Headers : Authorization: Basic won't work - Authorization:Basic will... #24

Closed nsteinmetz closed 6 years ago

nsteinmetz commented 6 years ago

Hi @maxcnunes

Testing the auth headers, I had a small issue:

./waitforit -address=https://url.bigocrp.com:443 -header "Authorization: Basic [REDACTED]" -timeout=60 -debug
2018/09/27 11:09:24 Waiting 60 seconds
2018/09/27 11:09:24 Ping host: url.bigocrp.com:443
2018/09/27 11:09:24 Ping host: url.bigocrp.com:443
2018/09/27 11:09:24 Up: url.bigocrp.com:443
2018/09/27 11:09:24 Ping http address: https://url.bigocrp.com:443
2018/09/27 11:09:24 Adding header Authorization:  Basic [REDARCED]
2018/09/27 11:09:24 Ping http address https://url.bigocrp.com:443 401 Unauthorized

I noticed there are 2 spaces between Authorization and Basic in the debug output. So I changed for a no space version ie "Authorization:Basic in the args and it works :

./waitforit -address=https://url.bigocrp.com:443 -header "Authorization:Basic [REDACTED]" -timeout=60 -debug
2018/09/27 11:09:41 Waiting 60 seconds
2018/09/27 11:09:41 Ping host: url.bigocrp.com:443
2018/09/27 11:09:41 Ping host: url.bigocrp.com:443
2018/09/27 11:09:41 Up: url.bigocrp.com:443
2018/09/27 11:09:41 Ping http address: https://url.bigocrp.com:443
2018/09/27 11:09:41 Adding header Authorization: Basic [REDACTED]
2018/09/27 11:10:01 Ping http address https://url.bigocrp.com:443 200 OK

I quickly reviewed the code and did not find where the issue may be.

Or it's only the doc to update ?

Thanks, Nicolas

maxcnunes commented 6 years ago

Hi @nsteinmetz,

Good catch. I believe we have two options here:

nsteinmetz commented 6 years ago

Hi,

2nd option seems more logical/relevant for me - I will try to propose a fix this afternoon.

Nicolas

nsteinmetz commented 6 years ago

why not just do (naive approach)for line 98 :

                result := strings.SplitN(v, ": ", 2)

As triming spaces is not really an option as we need to keep the space between Basic and the based64 encoded credentials.

Reading this https://flaviocopes.com/http-response-headers/ and https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields - the pattern seems always : <Key>: <value> with value being almost everything possible

nsteinmetz commented 6 years ago

or

                headers[result[0]] = strings.TrimLeft(result[1], " ")

What whould you prefer ?

nsteinmetz commented 6 years ago

I suggested both then in the PR :-)

maxcnunes commented 6 years ago

The second option seems better since it allows people with or without the prefix white space.