/src/muduo/muduo/net/http/HttpContext.h
Line | Count | Source |
1 | | // Copyright 2010, Shuo Chen. All rights reserved. |
2 | | // http://code.google.com/p/muduo/ |
3 | | // |
4 | | // Use of this source code is governed by a BSD-style license |
5 | | // that can be found in the License file. |
6 | | |
7 | | // Author: Shuo Chen (chenshuo at chenshuo dot com) |
8 | | // |
9 | | // This is an internal header file, you should not include this. |
10 | | |
11 | | #ifndef MUDUO_NET_HTTP_HTTPCONTEXT_H |
12 | | #define MUDUO_NET_HTTP_HTTPCONTEXT_H |
13 | | |
14 | | #include "muduo/base/copyable.h" |
15 | | |
16 | | #include "muduo/net/http/HttpRequest.h" |
17 | | |
18 | | namespace muduo |
19 | | { |
20 | | namespace net |
21 | | { |
22 | | |
23 | | class Buffer; |
24 | | |
25 | | class HttpContext : public muduo::copyable |
26 | | { |
27 | | public: |
28 | | enum HttpRequestParseState |
29 | | { |
30 | | kExpectRequestLine, |
31 | | kExpectHeaders, |
32 | | kExpectBody, |
33 | | kGotAll, |
34 | | }; |
35 | | |
36 | | HttpContext() |
37 | 1.58k | : state_(kExpectRequestLine) |
38 | 1.58k | { |
39 | 1.58k | } |
40 | | |
41 | | // default copy-ctor, dtor and assignment are fine |
42 | | |
43 | | // return false if any error |
44 | | bool parseRequest(Buffer* buf, Timestamp receiveTime); |
45 | | |
46 | | bool gotAll() const |
47 | 0 | { return state_ == kGotAll; } |
48 | | |
49 | | void reset() |
50 | 0 | { |
51 | 0 | state_ = kExpectRequestLine; |
52 | 0 | HttpRequest dummy; |
53 | 0 | request_.swap(dummy); |
54 | 0 | } |
55 | | |
56 | | const HttpRequest& request() const |
57 | 0 | { return request_; } |
58 | | |
59 | | HttpRequest& request() |
60 | 0 | { return request_; } |
61 | | |
62 | | private: |
63 | | bool processRequestLine(const char* begin, const char* end); |
64 | | |
65 | | HttpRequestParseState state_; |
66 | | HttpRequest request_; |
67 | | }; |
68 | | |
69 | | } // namespace net |
70 | | } // namespace muduo |
71 | | |
72 | | #endif // MUDUO_NET_HTTP_HTTPCONTEXT_H |