Fix NPE with cookies and headers processing

Related to #817