Add unit tests for _encode_meta_headers

Also move it to a module level function.
Change-Id: I2da64876815619a6db7ff208061df2191767806c