Basically the idea of the state machine is to avoid needing to allocate any memory for common headers. If the parser can match a well known header (such as Host for instance) it will return a constant, rather than allocating a new string.
You can't actually give the corresponding Java, as it uses goto which is not part of the language, but basically there are three states:
- Multiple possible headers can match.This state basically has a big switch statement, that looks at the next character and determines which state is next.
- Only one header can match. After the first fre characters have been matched you are generally only left with one option, in this state it just compares the request bytes to the rest of the header, and if they match it will return the constant value.
- No match. In this state it just stores the header in a buffer and returns a new HttpString
Stuart