fixed bug in validating cookie data, also set cookie header for downstream in case we created new cookie
consolidate v1 and v2 validation to make program shorter
move to C++ style to avoid malloc/free as much as we can