tailhook / rotor-http

The mio/rotor based http server library for rust (UNMAINTAINED, use tk-http)
MIT License
110 stars 11 forks source link

Improve Message to be more correct. #41

Closed pyfisch closed 8 years ago

pyfisch commented 8 years ago

Improved documentation, restructured the Message state machine. Now if a method of the machine is called it will move the FSM to another state and always the same state except if an error occurs. For this reason the new FSM is more understandable. Also it occupies 8 bytes less of storage.

Which messages contain a body in defined in RFC 7230

I have also created a graph of the state machine. It could be included in the documentation once rustdoc gains support for embedding images. message-fsm

Source code:

digraph Message {
    ResponseStart -> FinalResponseStart [label=response_continue]
    ResponseStart -> Headers [label=response_status]
    FinalResponseStart -> Headers [label=response_status]

    RequestStart -> Headers [label=request_line]

    Headers -> Headers [label=add_header]
    ChunkedHeaders -> ChunkedHeaders [label=add_header]
    FixedHeaders -> FixedHeaders [label=add_header]
    Headers -> FixedHeaders [label=add_length]
    Headers -> ChunkedHeaders [label=add_chunked]

    Headers -> Bodyless [label=done_headers]
    FixedHeaders -> FixedBody [label=done_headers]
    ChunkedHeaders -> ChunkedBody [label=done_headers]

    FixedBody -> FixedBody [label=write_body]
    ChunkedBody -> ChunkedBody [label=write_body]

    Bodyless -> Done [label=done]
    FixedBody -> Done [label=done]
    ChunkedBody -> Done [label=done]

    Done [peripheries=2]
    Done -> Done [label=done]

    {rank = same; RequestStart; ResponseStart;}
    Request_invis [shape=plaintext label=start]
    Request_invis -> RequestStart
    Response_invis [shape=plaintext label=start]
    Response_invis -> ResponseStart

    ResponseStart [tooltip="ResponseStart { version: Version, body: Body, close: bool }"]
    FinalResponseStart [tooltip="FinalResponseStart { version: Version, body: Body, close: bool }"]
    Headers [tooltip="Headers { body: Body, close: bool }"]
    FixedHeaders [tooltip="FixedHeaders { is_head: bool, close: bool, content_length: u64 }"]
    ChunkedHeaders [tooltip="ChunkedHeaders { is_head: bool, close: bool }"]
    Bodyless [tooltip="Bodyless"]
    FixedBody [tooltip="FixedBody { is_head: bool, content_length: u64 }"]
    ChunkedBody [tooltip="ChunkedBody { is_head: bool }"]

}
tailhook commented 8 years ago

Looks great! Thanks.