summaryrefslogtreecommitdiff
path: root/src/http/req.cc
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/http/req.cc
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/http/req.cc')
-rw-r--r--src/http/req.cc100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/http/req.cc b/src/http/req.cc
new file mode 100644
index 0000000..acb2105
--- /dev/null
+++ b/src/http/req.cc
@@ -0,0 +1,100 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <http/http.h>
21#include <mime/mailbox.h>
22
23httpReq::httpReq()
24{
25}
26
27int httpReq::Special(sref line)
28{
29 sref first,rest=line;
30 Split(first,rest);
31 method=first;
32 Split(first,rest);
33 uri=first;
34 arg.clear();
35 Split(first,rest);
36 version=first;
37 int pos=uri.find('?');
38 if(pos>=0) { arg=uri.right(pos+1); uri.resize(pos); }
39 return 1;
40}
41
42int httpReq::Handle(const sref& name,
43 const sref& rawval,
44 const sref& val,
45 const rrpile& opts)
46{
47 if(HTTP::Handle(name,rawval,val,opts)) return 1;
48 else if(eqn(name,auth_tag)) auth=val;
49 else if(eqn(name,expect_tag)) expect=val;
50 else if(eqn(name,from_tag)) from=val;
51 else if(eqn(name,host_tag)) host=val;
52 else if(eqn(name,if_match_tag)) if_match=val;
53 else if(eqn(name,if_mod_tag)) if_mod=val;
54 else if(eqn(name,if_none_tag)) if_none=val;
55 else if(eqn(name,if_range_tag)) if_range=val;
56 else if(eqn(name,if_unmod_tag)) if_unmod=val;
57 else if(eqn(name,max_forwards_tag)) max_forwards=val;
58 else if(eqn(name,proxy_tag)) proxy=val;
59 else if(eqn(name,range_tag)) range=val;
60 else if(eqn(name,referer_tag)) referer=val;
61 else if(eqn(name,te_tag)) te=val;
62 else if(eqn(name,user_agent_tag)) user_agent=val;
63 else if(eqn(name,cookie_tag)) {
64 for(rrpile::const_iterator p=opts.begin();p!=opts.end();p++)
65 cookies.push_back(sstring(p->first,p->second));
66 }
67 else return 0;
68 return 1;
69}
70
71void httpReq::putHead(mstream& out) const
72{
73 out<<method<<" "<<uri;
74 if(arg.nempty()) out<<"?"<<arg;
75 out<<" "<<version<<CRLF;
76 if(putval(out,auth_tag,auth)) putend(out);
77 if(putval(out,expect_tag,expect)) putend(out);
78 if(putval(out,from_tag,from)) putend(out);
79 if(putval(out,host_tag,host)) putend(out);
80 if(putval(out,if_match_tag,if_match)) putend(out);
81 if(putval(out,if_mod_tag,if_mod)) putend(out);
82 if(putval(out,if_none_tag,if_none)) putend(out);
83 if(putval(out,if_range_tag,if_range)) putend(out);
84 if(putval(out,if_unmod_tag,if_unmod)) putend(out);
85 if(putval(out,max_forwards_tag,max_forwards)) putend(out);
86 if(putval(out,proxy_tag,proxy)) putend(out);
87 if(putval(out,range_tag,range)) putend(out);
88 if(putval(out,referer_tag,referer)) putend(out);
89 if(putval(out,te_tag,te)) putend(out);
90 if(putval(out,user_agent_tag,user_agent)) putend(out);
91 HTTP::putHead(out);
92 if(!cookies.empty()) {
93 out<<cookie_tag<<": ";
94 for(sspile::const_iterator p=cookies.begin();p!=cookies.end();p++) {
95 if(p==cookies.begin()) putopt1(out,p->first,p->second);
96 else putopt(out,p->first,p->second);
97 }
98 putend(out);
99 }
100}