Headache relieved by pooping - why?

When it happens, it’s the same kind of slightly dizzy headache that I would associate with a hangover (often with some distortion of vision - blurring or haloes), and it goes away within a minute or two of defecation.

Is it possible that some bacterial fermentation process in the bowel could be producing a byproduct to which I am sensitive?