Kapelianovych / couchdb_dart

A library for Dart developers for work with CouchDB
https://pub.dev/packages/couchdb
Other
47 stars 18 forks source link

Client fails silently if host includes protocol #8

Closed nmfisher closed 5 years ago

nmfisher commented 5 years ago

If the host is specified with a protocol prefix (i.e. "http://10.0.2.2" rather than "10.0.2.2", any operations will fail silently

var dbHost = "http://10.0.2.2"
var client = CouchDbClient(host: dbHost);
docModel.insertDoc("_users", "org.couchdb.user:foo", "bar").then((resp) {
            print(resp.toString());
        }).catchError((err) {
            print(err.toString());
        });

For some reason this doesn't trigger catchError (or maybe it's stuck in a retry/timeout loop and I never waited long enough for the callback to resolve). Either way, given CouchDbClient prepends "http://" to the connect URI, which doesn't get picked up by Uri.parse (presumably it's actually a valid URI, just obviously not the one we wanted).

Is it worthwhile adding a check for this?

Kapelianovych commented 5 years ago

@nmfisher hello. You get this issue because connection URI is created in the getter connectUri as 'http://$host:$port';. And if you prepend the protocol to host parameter, then connection URI will be like 'http://http://10.0.2.2:$port';. This isn't checking right now because for connection mostly is used HTTP/1.1 protocol without SSL. So it's no reason to pass protocol prefix. I haven't created an opportunity to choose between http:// and https://, but I will make it.

nmfisher commented 5 years ago

Thanks @YevhenKap - I'd still suggest adding a URI sanity check, even if only http is supported. It prevents developers like me from doing stupid things :) Silent errors suck, and malformed config parameters are an easy mistake to make when you're trying out a new library.

I have a few other issues I've come across (e.g. a null username/password should be treated as anonyous authentication and shouldn't set any Authorization header). Did you want me to raise issues as I find them?

Kapelianovych commented 5 years ago

@nmfisher yes, of course, you can raise issues) Even more I need it)

nmfisher commented 5 years ago

Are you also OK for me to submit PRs for these issues?

Kapelianovych commented 5 years ago

You can do this. Read CONTRIBUTING.md.

Kapelianovych commented 5 years ago

I fix this issue - 0.5.0