| 105 | : DataEncoder(encode(message)) {} |
| 106 | |
| 107 | static std::string encode(const Message& message) |
| 108 | { |
| 109 | std::ostringstream out; |
| 110 | |
| 111 | out << "POST "; |
| 112 | // Nothing keeps the 'id' component of a PID from being an empty |
| 113 | // string which would create a malformed path that has two |
| 114 | // '//' unless we check for it explicitly. |
| 115 | // TODO(benh): Make the 'id' part of a PID optional so when it's |
| 116 | // missing it's clear that we're simply addressing an ip:port. |
| 117 | if (message.to.id != "") { |
| 118 | out << "/" << message.to.id; |
| 119 | } |
| 120 | |
| 121 | out << "/" << message.name << " HTTP/1.1\r\n" |
| 122 | << "User-Agent: libprocess/" << message.from << "\r\n" |
| 123 | << "Libprocess-From: " << message.from << "\r\n" |
| 124 | << "Connection: Keep-Alive\r\n" |
| 125 | << "Host: \r\n"; |
| 126 | |
| 127 | if (message.body.size() > 0) { |
| 128 | out << "Transfer-Encoding: chunked\r\n\r\n" |
| 129 | << std::hex << message.body.size() << "\r\n"; |
| 130 | out.write(message.body.data(), message.body.size()); |
| 131 | out << "\r\n" |
| 132 | << "0\r\n" |
| 133 | << "\r\n"; |
| 134 | } else { |
| 135 | out << "\r\n"; |
| 136 | } |
| 137 | |
| 138 | return out.str(); |
| 139 | } |
| 140 | }; |
| 141 | |
| 142 | |