refactor encoding and charset parsing to incorporate new code in media type parsing