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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*************************************************************************
*
* HTCd - Copyright (C) 1998-2006 Henrik Rydberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <http/http.h>
#include <mime/mailbox.h>
httpReq::httpReq()
{
}
int httpReq::Special(sref line)
{
sref first,rest=line;
Split(first,rest);
method=first;
Split(first,rest);
uri=first;
arg.clear();
Split(first,rest);
version=first;
int pos=uri.find('?');
if(pos>=0) { arg=uri.right(pos+1); uri.resize(pos); }
return 1;
}
int httpReq::Handle(const sref& name,
const sref& rawval,
const sref& val,
const rrpile& opts)
{
if(HTTP::Handle(name,rawval,val,opts)) return 1;
else if(eqn(name,auth_tag)) auth=val;
else if(eqn(name,expect_tag)) expect=val;
else if(eqn(name,from_tag)) from=val;
else if(eqn(name,host_tag)) host=val;
else if(eqn(name,if_match_tag)) if_match=val;
else if(eqn(name,if_mod_tag)) if_mod=val;
else if(eqn(name,if_none_tag)) if_none=val;
else if(eqn(name,if_range_tag)) if_range=val;
else if(eqn(name,if_unmod_tag)) if_unmod=val;
else if(eqn(name,max_forwards_tag)) max_forwards=val;
else if(eqn(name,proxy_tag)) proxy=val;
else if(eqn(name,range_tag)) range=val;
else if(eqn(name,referer_tag)) referer=val;
else if(eqn(name,te_tag)) te=val;
else if(eqn(name,user_agent_tag)) user_agent=val;
else if(eqn(name,cookie_tag)) {
for(rrpile::const_iterator p=opts.begin();p!=opts.end();p++)
cookies.push_back(sstring(p->first,p->second));
}
else return 0;
return 1;
}
void httpReq::putHead(mstream& out) const
{
out<<method<<" "<<uri;
if(arg.nempty()) out<<"?"<<arg;
out<<" "<<version<<CRLF;
if(putval(out,auth_tag,auth)) putend(out);
if(putval(out,expect_tag,expect)) putend(out);
if(putval(out,from_tag,from)) putend(out);
if(putval(out,host_tag,host)) putend(out);
if(putval(out,if_match_tag,if_match)) putend(out);
if(putval(out,if_mod_tag,if_mod)) putend(out);
if(putval(out,if_none_tag,if_none)) putend(out);
if(putval(out,if_range_tag,if_range)) putend(out);
if(putval(out,if_unmod_tag,if_unmod)) putend(out);
if(putval(out,max_forwards_tag,max_forwards)) putend(out);
if(putval(out,proxy_tag,proxy)) putend(out);
if(putval(out,range_tag,range)) putend(out);
if(putval(out,referer_tag,referer)) putend(out);
if(putval(out,te_tag,te)) putend(out);
if(putval(out,user_agent_tag,user_agent)) putend(out);
HTTP::putHead(out);
if(!cookies.empty()) {
out<<cookie_tag<<": ";
for(sspile::const_iterator p=cookies.begin();p!=cookies.end();p++) {
if(p==cookies.begin()) putopt1(out,p->first,p->second);
else putopt(out,p->first,p->second);
}
putend(out);
}
}
|