summaryrefslogtreecommitdiff
path: root/src/http/http.h
blob: 8bd4d236d774ee9a0faf7c3e6042b8b7a18d0958 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*************************************************************************
 *
 * 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
 */

#ifndef HTTPH
#define HTTPH

#include <http/mime.h>

///////////////////////////////////////////////////////////////////

const mstring http_mime_default="application/octet-stream";

const mstring HTTP_V10="HTTP/1.0";
const mstring HTTP_V11="HTTP/1.1";

///////////////////////////////////////////////////////////////////
// Request types
const mstring HTTP_OPTIONS="OPTIONS";
const mstring HTTP_GET="GET";
const mstring HTTP_HEAD="HEAD";
const mstring HTTP_POST="POST";
const mstring HTTP_PUT="PUT";
const mstring HTTP_DELETE="DELETE";
const mstring HTTP_TRACE="TRACE";
const mstring HTTP_CONNECT="CONNECT";

class httpReq : public HTTP {
public:
  httpReq();
  httpReq(const sref& msg) { Init(msg); }

  mstring method,uri,arg,version;
  mstring auth,expect,from,host;
  mstring if_match,if_mod,if_none,if_range,if_unmod;
  mstring max_forwards,proxy,range;
  mstring referer,te,user_agent;
  sspile cookies;

  void putHead(mstream& out) const;
protected:
  int Special(sref line);
  int Handle(const sref& name,
             const sref& rawval,
             const sref& val,
             const rrpile& opts);
};

///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
// Informational 1xx
const mstring HTTP_100="100 Continue";
const mstring HTTP_101="101 Switching Protocols";
// Successful 2xx
const mstring HTTP_200="200 OK";
const mstring HTTP_201="201 Created";
const mstring HTTP_202="202 Accepted";
const mstring HTTP_203="203 Non-Authoritative Information";
const mstring HTTP_204="204 No Content";
const mstring HTTP_205="205 Reset Content";
const mstring HTTP_206="206 Partial Content";
// Redirection 3xx
const mstring HTTP_300="300 Multiple Choices";
const mstring HTTP_301="301 Moved Permanently";
const mstring HTTP_302="302 Found";
const mstring HTTP_303="303 See Other";
const mstring HTTP_304="304 Not Modified";
const mstring HTTP_305="305 Use Proxy";
const mstring HTTP_306="306 (Unused)";
const mstring HTTP_307="307 Temporary Redirect";
// Client Error 4xx
const mstring HTTP_400="400 Bad Request";
const mstring HTTP_401="401 Unauthorized";
const mstring HTTP_402="402 Payment Required";
const mstring HTTP_403="403 Forbidden";
const mstring HTTP_404="404 Not Found";
const mstring HTTP_405="405 Method Not Allowed";
const mstring HTTP_406="406 Not Acceptable";
const mstring HTTP_407="407 Proxy Authentication Required";
const mstring HTTP_408="408 Request Timeout";
const mstring HTTP_409="409 Conflict";
const mstring HTTP_410="410 Gone";
const mstring HTTP_411="411 Length Required";
const mstring HTTP_412="412 Precondition Failed";
const mstring HTTP_413="413 Request Entity Too Large";
const mstring HTTP_414="414 Request-URI Too Long";
const mstring HTTP_415="415 Unsupported Media Type";
const mstring HTTP_416="416 Requested Range Not Satisfiable";
const mstring HTTP_417="417 Expectation Failed";
// Server Error 5xx
const mstring HTTP_500="500 Internal Server Error";
const mstring HTTP_501="501 Not Implemented";
const mstring HTTP_502="502 Bad Gateway";
const mstring HTTP_503="503 Service Unavailable";
const mstring HTTP_504="504 Gateway Timeout";
const mstring HTTP_505="505 HTTP Version Not Supported";

struct cookie_t {
  mstring name,val,options;
  cookie_t() {}
  cookie_t(const sref& n,const sref& v) : name(n),val(v) {}
  cookie_t(const sref& n,const sref& v,const sref& o) :
    name(n),val(v),options(o) {}
};

class httpResp : public HTTP {
public:
  httpResp();
  httpResp(const sref& msg) { Init(msg); }

  mstring version,status;
  mstring age,etag,location;
  mstring proxy_authent,retry,server,vary,authent;
  msvec<cookie_t> set_cookies;

  void putHead(mstream& out) const;
protected:
  int Special(sref line);
  int Handle(const sref& name,
             const sref& rawval,
             const sref& val,
             const rrpile& opts);
};

///////////////////////////////////////////////////////////////////

#endif