Support setting and getting of custom metadata.

It's not yet complete, but it's functional enough for basic use.
Refactor: Custom header prefix checks in a single place
Refactor metadata map into unique type for easy reuse.