-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReadChunked.h
64 lines (49 loc) · 1.48 KB
/
ReadChunked.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* File: ReadChunkedBodyHttpServlet.h
* Author: try
*
* Created on 2011年7月17日, 上午12:27
*/
#ifndef READCHUNKEDBODYHTTPSERVLET_H
#define READCHUNKEDBODYHTTPSERVLET_H
#include <evhttp/HttpServlet.h>
#include <evhttp/ChunkedBodyBuilder.h>
class ReadChunked : public HttpServlet, public ChunkedBodyBuilder{
public:
ReadChunked():readBodyDone(false), bodyError(false){}
virtual ~ReadChunked(){}
virtual bool onReadBodyEvent(const char* buff, size_t n){
if(request->isChunkedTransferEncoding){
build(buff, n);
if(bodyError){
response->setStatus(400, "body data error");
return true;
}else if(readBodyDone){
return true;
}
}else{
response->setStatus(400, "Content-Type not is ChunkedTransferEncoding");
return true;
}
return false;
}
virtual void service(Request& req, Response& resp){
}
protected:
virtual bool onBuildCompletionEvent(const BodyBuildCompletionEvent* e){
if(e->length > 0){
//在此处理读到的数据
}else if(e->length == 0){
readBodyDone = true;
return true;
}else{
bodyError = true;
return true;
}
return false;
}
private:
bool readBodyDone;
bool bodyError;
};
#endif /* READCHUNKEDBODYHTTPSERVLET_H */