benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 113 forks source link

HTTP Basic support needed for changes feed #39

Closed jhs closed 13 years ago

jhs commented 13 years ago

Actually, anything that uses couchbeam:server_url/1.

Naive implementation is at http://github.com/jhs/couchbeam trunk. Thanks!

benoitc commented 13 years ago

It's already supported: Host = "localhost", Port = 5984, Prefix = "", UserName = "guest", Password = "test", Options = [{basic_auth, {UserName, Password}], S1 = couchbeam:server_connection(Host, Port, Prefix, Options).

More info here: http://benoitc.github.com/couchbeam/

This is applied to all objects using server_url, could be overriden in the Db too. Also oauth is supported too.

jhs commented 13 years ago

I did that however it does not work for changes_feeds.

couchbeam:changes_wait calls couchbeam:make_url which calls couchbeam:server_url which forgets to add username:password@ prefix to the hostname.

Please see patch (and merge/fast-forward if possible) at http://github.com/jhs/couchbeam/commit/9a77bc6a0385d72b78fb9f40b78722de0755dde7

benoitc commented 13 years ago

Options should be passed in the url, ibrowse should understand this option: http://github.com/cmullaparthi/ibrowse/blob/master/src/ibrowse.erl#L261

&

http://github.com/cmullaparthi/ibrowse/blob/master/src/ibrowse_http_client.erl#L757

What is your error & ibrowse version ?

benoitc commented 13 years ago

tested but can't reproduce.

1> S = couchbeam:server_connection("127.0.0.1", 5984, "", [{basic_auth, {"testdb", "testdb"}}]).
{server,"127.0.0.1",5984,[],
        [{basic_auth,{"testdb","testdb"}}]}
2> {ok, Db} = couchbeam:open_db(S, "testdb").
{ok,{db,{server,"127.0.0.1",5984,[],
                [{basic_auth,{"testdb","testdb"}}]},
        "testdb",
        [{basic_auth,{"testdb","testdb"}}]}}
3> coucheam:db_info(Db).
{error,{ok,"401",
           [{"Server","CouchDB/1.1.0a572fdd0-git (Erlang OTP/R13B)"},
            {"Date","Mon, 01 Nov 2010 20:18:54 GMT"},
            {"Content-Type","application/json"},
            {"Content-Length","67"},
            {"Cache-Control","must-revalidate"}],
           <<"{\"error\":\"unauthorized\",\"reason\":\"Name or password is incorrect.\"}\n">>}}
4> S1 = couchbeam:server_connection("127.0.0.1", 5984, "", [{basic_auth, {"test", "test"}}]).   
{server,"127.0.0.1",5984,[],[{basic_auth,{"test","test"}}]}
5> {ok, Db1} = couchbeam:open_db(S1, "testdb").
{ok,{db,{server,"127.0.0.1",5984,[],
                [{basic_auth,{"test","test"}}]},
        "testdb",
        [{basic_auth,{"test","test"}}]}}
6> 11> couchbeam:db_info(Db1).
{ok,{[{<<"db_name">>,<<"testdb">>},
      {<<"doc_count">>,7130},
      {<<"doc_del_count">>,0},
      {<<"update_seq">>,7132},
      {<<"purge_seq">>,0},
      {<<"compact_running">>,false},
      {<<"disk_size">>,18428003},
      {<<"instance_start_time">>,<<"1288641963975075">>},
      {<<"disk_format_version">>,5},
      {<<"committed_update_seq">>,7132}]}}
7> ChangesFun = fun(ReqId, F) ->
7>     receive
7>         {ReqId, done} ->
7>             ok;
7>         {ReqId, {change, Change}} ->
7>             io:format("change ~p ~n", [Change]),
7>             F(ReqId, F);    
7>         {ReqId, {error, E}}->
7>             io:format("error ? ~p ~n", [E])
7>     end
7> end,
7> Pid = self(),
7> Options = [{heartbeat, "true"}],
7> {ok, ReqId} = couchbeam:changes_wait(Db1, Pid, Options),
7> ChangesFun(ReqId, ChangesFun)
....

change {[{<<"seq">>,7129},
         {<<"id">>,<<"FF7F2322-5056-9023-58671A40BC646C56">>},
         {<<"changes">>,
          [{[{<<"rev">>,<<"1-7ec586a36521d9e6fe2c71a427aa93b8">>}]}]}]} 
change {[{<<"seq">>,7131},
         {<<"id">>,<<"_design/warlogs">>},
         {<<"changes">>,
          [{[{<<"rev">>,<<"2-b442b496519d470968eba773283d2c04">>}]}]}]}