forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.h
More file actions
93 lines (72 loc) · 2.13 KB
/
http.h
File metadata and controls
93 lines (72 loc) · 2.13 KB
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
// Copyright (c) 2015 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Author: shichengyi (Shi Chengyi)
#ifndef _TRIDENT_HTTP_H_
#define _TRIDENT_HTTP_H_
#include <map>
#include <string>
#include <trident/buffer.h>
namespace trident {
/**
* @brief request from http client, include http headers, query_params, and so
* on.
*/
struct HTTPRequest
{
enum Type
{
GET = 1,
POST = 2
};
// method in http header
Type type;
// PATH field in http request
// for example, http://www./s?k=123
// path is "/s"
std::string path;
// query parameters
// http://www./s?k=123
// will be parsed to {"k":"123"}
const std::map<std::string, std::string>* query_params;
// http request headers
const std::map<std::string, std::string>* headers;
// server ip adddress
std::string server_ip;
// server port
uint16_t server_port;
// client ip address
std::string client_ip;
// client port
uint16_t client_port;
// the body field describes HTTP post body
// using body->ToString() to get the std::string
ReadBufferPtr body;
HTTPRequest() : type(GET)
, query_params(NULL)
, headers(NULL)
, server_port(0)
, client_port(0)
{}
};
/**
* @brief http response to client or web browser
*/
struct HTTPResponse
{
// HTTP server status line, reference to RFC2616
// default value is 200 OK, means this request dealed normally
std::string status_line;
// content-type field in http response header
// default is "text/html", return a plain text to http client
std::string content_type;
// page content will return to http client which maybe a web browser
// using content->Append(std::string) to set response body
WriteBufferPtr content;
HTTPResponse() : status_line("HTTP/1.1 200 OK")
, content_type("text/html; charset=UTF-8")
, content(new WriteBuffer())
{}
};
} // namespace trident
#endif // _TRIDENT_HTTP_H_