ESA JPIP server  0.1
response.h
Go to the documentation of this file.
1 #ifndef _HTTP_RESPONSE_H_
2 #define _HTTP_RESPONSE_H_
3 
4 
5 #include <map>
6 #include <string>
7 #include <sstream>
8 #include <iostream>
9 #include "protocol.h"
10 
11 
12 namespace http
13 {
14 
15  using namespace std;
16 
17 
24  class Response
25  {
26  private:
31  {
32  public:
34  };
35 
40 
41  public:
42  int code;
44 
51  static map<int, string> StatusCodes;
52 
53 
59  Response(int code = 200, const Protocol& protocol = Protocol(1, 1))
60  {
61  this->code = code;
62  this->protocol = protocol;
63  }
64 
65  friend ostream& operator << (ostream &out, const Response &response)
66  {
67  return out
68  << response.protocol << " "
69  << response.code << " "
71  }
72 
73  friend istream& operator >> (istream &in, Response &response)
74  {
75  string line, cad;
76 
77  if(getline(in, line)) {
78  if(line.size() <= 0) in.setstate(istream::failbit);
79  else {
80  istringstream in_str(line);
81 
82  if(!(in_str >> response.protocol >> response.code >> cad))
83  in.setstate(istream::failbit);
84  }
85  }
86 
87  return in;
88  }
89  };
90 
91 }
92 
93 
94 #endif /* _HTTP_RESPONSE_H_ */
Class used to identify a HTTP response.
Definition: response.h:24
int code
Status code.
Definition: response.h:42
Class used for the initializer.
Definition: response.h:30
STL namespace.
Protocol protocol
Protocol version.
Definition: response.h:43
static StatusCodesInitializer statusCodesInitializer
The initializer of the StatusCodes member.
Definition: response.h:39
static map< int, string > StatusCodes
Map with the strings associated to the most commonly used status codes.
Definition: response.h:51
Contains the definition of a set of classes for working easily with the protocol HTTP.
Definition: header.cc:4
Class used to identify the HTTP protocol.
Definition: protocol.h:20
Response(int code=200, const Protocol &protocol=Protocol(1, 1))
Initializes the response.
Definition: response.h:59
istream & operator>>(istream &in, Request &request)
Definition: request.cc:51
static const char CRLF[]
String with the characters 13 (CR) and 10 (LF), the line separator used in the HTTP protocol...
Definition: protocol.h:31
ostream & operator<<(ostream &out, const Request &request)
Definition: request.cc:65