Handle flags even if no other headers

Also add rspec tests to verify. The rspec testing commit is the same as included in my other pull request. I'll rebase that one against this change.