Add saving cookie state.
Fix setting cookies.
Merge branch 'cookie-state'