It may be possible to reuse existing implementations. You might want to have a look at the Symfony HTTP Foundation Component.