Added more error handling and logic for cleaning and canonicalizing the header key and value like http.Header.write() does.