I am writing a program which can detects protocols used in network packets. For every packet receives it will try to detect protocols in layers such network and transport. Detecting protocols in these two layer was very easy because somewhere in the packet we have some bytes which tell us about protocols. But for application layers, it's much harder as I know. No where in a HTTP packet is not mentioned the protocol (as far as I know). And another difficulty during detecting application layer protocols is that it is possible that a whole HTTP request or response takes more than one packet, and it's lot harder to concatenate multiple packets.
I want to know theoretically how can I detect these protocols.