Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove body argument to header functions #1542

Closed
paulmelnikow opened this issue May 6, 2019 · 9 comments
Closed

Remove body argument to header functions #1542

paulmelnikow opened this issue May 6, 2019 · 9 comments

Comments

@paulmelnikow
Copy link
Member

Currently the third argument to header functions receives a buffer containing the response body. I can't think of a reason why this would be helpful.

I could imagine the request body being helpful, though that should be accessible from the request.

I'm inclined to remove this parameter from the function in a breaking change.

See #1541 where I added a test covering the current behavior.

@gr2m
Copy link
Member

gr2m commented May 6, 2019

If this is undocumented and untested, I’d be okay to remove it without a breaking change.

If it breaks someone’s code it’s fair play to say it was never documented / tested ¯\_(ツ)_/¯ Documenting it as breaking change is going the extra mile. Go if you like, but I don’t feel like we have to

@paulmelnikow
Copy link
Member Author

It is tested and documented – just not useful!

Like many of the tests, the intention of the test (which I changed in #1541) was not quite clear, and I can't say it left me confident someone intended to pass the response body to the callback, vs the test containing a bug.

The behavior is documented, ambiguously:

… you can use a function to generate the headers values. The function will be passed the request, response, and body (if available). The body will be either a buffer, a stream, or undefined.

paulmelnikow added a commit that referenced this issue May 6, 2019
@paulmelnikow paulmelnikow reopened this May 6, 2019
@paulmelnikow
Copy link
Member Author

Oops! I accidentally pushed this branch and it let me. I stopped the Travis builld which should prevent the release, though I can't force push because of branch protection.

Should I turn it off temporarily and force push the commit before?

Can we turn on branch protection so I can try to prevent a repeat performance? 😝

@gr2m
Copy link
Member

gr2m commented May 6, 2019

Sure, go ahead 👍

@paulmelnikow
Copy link
Member Author

Okay, done.

I can't find an option to prevent accidentally pushing to the branch. I can be careful… though I'd rather find a way to do that. Am I missing something? Is it only possible to do that if "Include administrators" is checked?

I can try to be more careful about it…

@paulmelnikow
Copy link
Member Author

Huh, there's a test that's failing in #1544. In this one it's super clear that the response body is intended to be passed to the header function.

test('default reply headers as functions work', async t => {
const date = new Date().toUTCString()
const message = 'A message.'
nock('http://example.test')
.defaultReplyHeaders({
'Content-Length': (req, res, body) => body.length,
Date: () => date,
Foo: () => 'foo',
})
.get('/')
.reply(200, message, { foo: 'bar' })
const { headers } = await got('http://example.test')
t.deepEqual(headers, {
'content-length': message.length,
date,
foo: 'bar',
})
})

Before removing this, I want to see if I can find any more information about why this use case was added. I'm still inclined to remove it as it seems very specific and something that can be accomplished around in other ways.

@paulmelnikow
Copy link
Member Author

paulmelnikow commented May 19, 2019

Okay, tracked this down. This was added in #315 in response to #263. I can see for the Content-Length use case that it would be useful to have the processed response available. Instead of removing this behavior, I'm updating #1544 to improve the documentation, tests, and examples.

@nockbot
Copy link
Collaborator

nockbot commented May 21, 2019

🎉 This issue has been resolved in version 11.0.0-beta.16 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nockbot
Copy link
Collaborator

nockbot commented Aug 13, 2019

🎉 This issue has been resolved in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this issue Sep 4, 2019
gr2m pushed a commit that referenced this issue Sep 4, 2019
gr2m pushed a commit that referenced this issue Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants