Mercurial > hg > orthanc
comparison PalantirCppClient/HttpClient.cpp @ 43:9be852ad33d2
rename for c
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Sep 2012 09:59:34 +0200 |
parents | 042ac60f5bf9 |
children |
comparison
equal
deleted
inserted
replaced
42:ea48f38afe5f | 43:9be852ad33d2 |
---|---|
91 #if PALANTIR_SSL_ENABLED == 1 | 91 #if PALANTIR_SSL_ENABLED == 1 |
92 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0)); | 92 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_SSL_VERIFYPEER, 0)); |
93 #endif | 93 #endif |
94 | 94 |
95 url_ = ""; | 95 url_ = ""; |
96 method_ = HttpMethod_Get; | 96 method_ = Palantir_HttpMethod_Get; |
97 lastStatus_ = HttpStatus_200_Ok; | 97 lastStatus_ = Palantir_HttpStatus_200_Ok; |
98 isVerbose_ = false; | 98 isVerbose_ = false; |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 HttpClient::~HttpClient() | 102 HttpClient::~HttpClient() |
128 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); | 128 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); |
129 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, NULL)); | 129 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, NULL)); |
130 | 130 |
131 switch (method_) | 131 switch (method_) |
132 { | 132 { |
133 case HttpMethod_Get: | 133 case Palantir_HttpMethod_Get: |
134 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); | 134 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
135 break; | 135 break; |
136 | 136 |
137 case HttpMethod_Post: | 137 case Palantir_HttpMethod_Post: |
138 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); | 138 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
139 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); | 139 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); |
140 | 140 |
141 if (postData_.size() > 0) | 141 if (postData_.size() > 0) |
142 { | 142 { |
149 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); | 149 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); |
150 } | 150 } |
151 | 151 |
152 break; | 152 break; |
153 | 153 |
154 case HttpMethod_Delete: | 154 case Palantir_HttpMethod_Delete: |
155 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); | 155 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
156 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); | 156 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
157 break; | 157 break; |
158 | 158 |
159 case HttpMethod_Put: | 159 case Palantir_HttpMethod_Put: |
160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); | 160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
161 break; | 161 break; |
162 | 162 |
163 default: | 163 default: |
164 throw HttpException("HttpClient: Internal error"); | 164 throw HttpException("HttpClient: Internal error"); |
171 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status)); | 171 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status)); |
172 | 172 |
173 if (status == 0) | 173 if (status == 0) |
174 { | 174 { |
175 // This corresponds to a call to an inexistent host | 175 // This corresponds to a call to an inexistent host |
176 lastStatus_ = HttpStatus_500_InternalServerError; | 176 lastStatus_ = Palantir_HttpStatus_500_InternalServerError; |
177 } | 177 } |
178 else | 178 else |
179 { | 179 { |
180 lastStatus_ = static_cast<HttpStatus>(status); | 180 lastStatus_ = static_cast<Palantir_HttpStatus>(status); |
181 } | 181 } |
182 | 182 |
183 return (status >= 200 && status < 300); | 183 return (status >= 200 && status < 300); |
184 } | 184 } |
185 | 185 |