Refactor merge_kwargs

This refactors the `merge_kwargs` function for sessions to (hopefully) be clearer, and fix some bugs with it. It fixes #1321, as well as fixing an issue where arguments other than headers were being improperly merged case insensitively.