Helper function to post a request to "/api/v1" master endpoint and return the response.
| 144 | // Helper function to post a request to "/api/v1" master endpoint and return |
| 145 | // the response. |
| 146 | Future<v1::master::Response> post( |
| 147 | const process::PID<master::Master>& pid, |
| 148 | const v1::master::Call& call, |
| 149 | const ContentType& contentType, |
| 150 | const Credential& credential = DEFAULT_CREDENTIAL) |
| 151 | { |
| 152 | http::Headers headers = createBasicAuthHeaders(credential); |
| 153 | headers["Accept"] = stringify(contentType); |
| 154 | |
| 155 | return http::post( |
| 156 | pid, |
| 157 | "api/v1", |
| 158 | headers, |
| 159 | serialize(contentType, call), |
| 160 | stringify(contentType)) |
| 161 | .then([contentType](const http::Response& response) |
| 162 | -> Future<v1::master::Response> { |
| 163 | if (response.status != http::OK().status) { |
| 164 | return Failure("Unexpected response status " + response.status); |
| 165 | } |
| 166 | return deserialize<v1::master::Response>(contentType, response.body); |
| 167 | }); |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 |