summaryrefslogtreecommitdiffhomepage
path: root/NetEx/HttpRequest.h
blob: 861cd2fee4389f058d2df6996bbe1b4701bda029 (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
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.
*/

#ifndef HttpRequest_h
#define HttpRequest_h

#include "HttpParam.h"
#include "List.h"
#include "NetAddr.h"


class HttpRequest
{
public:
    static const char* TYPENAME() { return "HttpRequest"; }

    enum METHOD {
        HTTP_OPTIONS,
        HTTP_GET,
        HTTP_HEAD,
        HTTP_POST,
        HTTP_PUT,
        HTTP_DELETE,
        HTTP_TRACE,
        HTTP_CONNECT
    };

    HttpRequest(const char* request=nullptr);
    ~HttpRequest();

    operator Text();

    void              ParseRequest(Text request);
    void              ParseCookie(const char* param);

    int               Method()       const { return method;        }
    Text              URI()          const { return uri;           }
    Text              Content()      const { return content;       }
    Text              RequestLine()  const { return request_line;  }

    List<HttpParam>&  GetQuery()           { return query;         }
    List<HttpParam>&  GetHeaders()         { return headers;       }
    List<HttpParam>&  GetCookies()         { return cookies;       }

    NetAddr           GetClientAddr()            const { return client_addr; }
    void              SetClientAddr(const NetAddr& a)  { client_addr = a;    }

    Text              GetParam(const char* name);

    Text              GetHeader(const char* name);
    void              SetHeader(const char* name, const char* value);
    void              AddHeader(const char* name, const char* value);
    Text              GetCookie(const char* name);
    void              SetCookie(const char* name, const char* value);
    void              AddCookie(const char* name, const char* value);

    Text              DecodeParam(const char* value);
    static Text       EncodeParam(const char* value);

private:
    int               method;
    Text              uri;
    Text              content;
    Text              request_line;
    NetAddr           client_addr;

    List<HttpParam>   query;
    List<HttpParam>   headers;
    List<HttpParam>   cookies;
};


#endif  // HttpRequest_h