sploders101 opened a new issue #273:
URL: https://github.com/apache/couchdb-nano/issues/273
<!--- Provide a general summary of the issue in the Title above -->
## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work
-->
When using custom headers (example below), they should be merged with the
request headers before the request is sent.
## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected
behavior -->
<!--- If suggesting a change/improvement, explain the difference from
current behavior -->
When using custom headers (example below), they are not merged with the
request headers in changesReader. This results in incorrect headers being sent
in the final request.
```
## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->
The offending call is in `9.0.3` at `nano/lib/changesReader.js:248`, where
Object.assign is used instead of a deepMerge function. This *overwrites* the
headers field with the requestDefaults version rather than merging, resulting
in missing headers when a request is finally sent. If I replace the offending
code with this, it works.
```typescript
const req = Object.assign({
method: (opts.method || 'GET'),
headers: headers,
uri: cfg.url
}, {
...cfg.requestDefaults,
headers: Object.assign(headers, cfg.requestDefaults &&
cfg.requestDefaults.headers ? cfg.requestDefaults.headers : {}),
})
## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
1. Set up a couchdb connection
```typescript
export const couchdb = nano({
requestDefaults: {
headers: {
"X-Auth-CouchDB-UserName": "server",
"X-Auth-CouchDB-Roles": "_admin",
},
},
url: dbURL,
});
```
2. Use a request that utilizes headers. I am using `changesReader`, which
fails on start, so that's probably the easiest way to test.
## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful
in the real world -->
I am trying to use proxy authentication in CouchDB since I link to an AD
server for authentication for SSO. I have set up a simple authentication proxy
in my application, but use the code above to create a nano instance usable by
the server for privileged tasks.
## Your Environment
<!--- Include as many relevant details about the environment you experienced
the bug in -->
* Version used: 9.0.3
* Browser Name and version: N/A
* Operating System and version (desktop or mobile): Mac OS 11.4
* Link to your project: Private repository
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]