Ticket #5677: requestheader.cpp

File requestheader.cpp, 2.4 KB (added by rohitvvv@…, 14 years ago)
Line 
1#include "networkbase.cpp"
2
3class httprequestheader : public haikuhttp
4{
5 public:
6 char* _method;
7 char* _path;
8 httprequestheader();
9 httprequestheader(const char *method ,const char *path ,
10 const char majorVer='1' ,char minorVer='1');
11 httprequestheader(string str);
12 void setRequest(const char* method ,const char *path ,
13 char majorVer='1',char minorVer='1');
14 const char* getmethod();
15 const char* getpath();
16 void printheader();
17};
18
19httprequestheader::httprequestheader(){
20//TODO
21//An empty http buffer should be constructed.
22}
23
24/*
25This constitutes the request header
26all the major fieds that constitute an http header can be handled
27here
28*/
29httprequestheader::httprequestheader(const char *method, const char *path ,
30 char majorVer , char minorVer){
31
32//The Appending code is fragile and hence default HTTP/1.1 is assumed
33 const char *http="HTTP/1.1";
34
35 _method=(char *)malloc(strlen(method));
36 _path=(char *)malloc(strlen(path));
37
38 buffer->AppendData((const void *)method , strlen(method));
39 buffer->AppendInt8(32);//ascii of space
40 buffer->AppendData((const void *)path ,strlen(path));
41 buffer->AppendInt8(32);//ascii of space
42 buffer->AppendData((const void*)http , strlen(http));
43//TODO
44//Need better handling of major and minor Version paramters.
45//Some bug in BNetbuffer library
46
47//Commnted code below has bugs
48// header->buffer->AppendInt8(1);
49// header->buffer->AppendData((const void *)'/',1);
50// header->buffer->AppendInt8(1);
51 buffer->AppendData(CRLF , 2);
52// addValue("Accept-Language","en-us");
53
54//The _mthod and _post char* are set to be used by getmethod and getpost
55//functions
56 _method=(char *)method;
57 _path=(char *)path;
58//prints the header string
59 tostring();
60}
61
62//An already constructed request header is passed.
63httprequestheader::httprequestheader(const string str){
64 //TODO
65 //The already constructed str(header) needs to be parsed for correctness.
66 buffer->AppendData((const void*)str.c_str(),strlen(str.c_str()));
67 tostring();
68}
69
70const char* httprequestheader::getmethod(){
71 return _method;
72}
73
74const char* httprequestheader::getpath(){
75 return _path;
76}
77
78
79/*
80Main for testing this class
81
82*/
83/*
84int main(){
85
86
87 httprequestheader requestline("GET","http://www.rediff.com",'1','1');
88// httprequestheader obj("GET http://www.rediff.com HTTP/1.2");
89 cout<<"Getmothod and GetPath \n";
90 cout<<requestline.getmethod();
91 cout<<" ";
92 cout<<requestline.getpath()<<"\n";
93 return 1;
94}
95*/
96