doctrine / couchdb-client

CouchDB Client library
MIT License
122 stars 68 forks source link

Allow default headers to be set for clients #69

Closed damiankloip closed 6 years ago

damiankloip commented 7 years ago

We have a need to set arbitrary headers on requests using the couch client - for our purpose, it's for auth headers, using a Bearer token. This allows another auth server to act as a proxy for the couch database server.

This adds a 'headers' option to the CouchDBClient and the AbstractHTTPClient classes, and implements merging of default headers with passed in headers in the concrete SocketClient and StreamClient classes.

I added some option handling test coverage for this in CouchDBClientTest.

timmillwood commented 7 years ago

Think my only nit pick would be to use [] instead of array() but otherwise looks great.

The native CouchDB client supports a headers to be passed in when doing things like replication, so I guess we should support it in CouchDBClient too.

The test fails look to be unrelated, we will need a follow up to fix the test fails.

damiankloip commented 7 years ago

Added another commit to make the tests run more reliably. Removes the data in the tearDown method for the functional tests.

damiankloip commented 7 years ago

Thanks @timmillwood. I didn't add the [] array syntax as it looks like this library doesn't really use that anywhere else yet. I am happy to change if required though.

Related to your comment about couch headers, example replication request body:

{
  "source":"test_db_1",
  "target":{
    "url":"https://my.other-couch.server/test_db_2",
    "headers":{
      "Authorization":"Bearer TOKEN",
      "Other":"Header"
    }
  }
}
damiankloip commented 7 years ago

With my last change to the tests we shouldn't create the test DB in the travis config file anymore.