-rw-r--r-- | include/opkele/oauth/consumer.h | 5 | ||||
-rw-r--r-- | lib/oauth-consumer.cc | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/include/opkele/oauth/consumer.h b/include/opkele/oauth/consumer.h index 1e2784c..9196297 100644 --- a/include/opkele/oauth/consumer.h +++ b/include/opkele/oauth/consumer.h | |||
@@ -5,4 +5,5 @@ | |||
5 | #include <opkele/types.h> | 5 | #include <opkele/types.h> |
6 | #include <opkele/oauth.h> | 6 | #include <opkele/oauth.h> |
7 | #include <opkele/curl.h> | ||
7 | 8 | ||
8 | namespace opkele { | 9 | namespace opkele { |
@@ -42,6 +43,10 @@ namespace opkele { | |||
42 | string body; | 43 | string body; |
43 | 44 | ||
45 | util::curl_slist_t _curl_headers_list; | ||
46 | |||
44 | http_request_t(const string& m,const string& u) | 47 | http_request_t(const string& m,const string& u) |
45 | : method(m), url(u) { } | 48 | : method(m), url(u) { } |
49 | |||
50 | void setup_curl(CURL *curl); | ||
46 | }; | 51 | }; |
47 | 52 | ||
diff --git a/lib/oauth-consumer.cc b/lib/oauth-consumer.cc index d717ed3..0c4c9e3 100644 --- a/lib/oauth-consumer.cc +++ b/lib/oauth-consumer.cc | |||
@@ -223,4 +223,32 @@ namespace opkele { | |||
223 | } | 223 | } |
224 | 224 | ||
225 | void http_request_t::setup_curl(CURL *curl) { | ||
226 | CURLcode r; | ||
227 | r = curl_easy_setopt(curl,CURLOPT_URL,url.c_str()); | ||
228 | if(r) | ||
229 | throw exception_curl(OPKELE_CP_ "failed to set curly urlie",r); | ||
230 | if(method=="POST") { | ||
231 | (r = curl_easy_setopt(curl,CURLOPT_POST,1)) | ||
232 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDS,body.c_str())) | ||
233 | || (r = curl_easy_setopt(curl,CURLOPT_POSTFIELDSIZE,body.size())); | ||
234 | }else if(method=="GET") { | ||
235 | r = curl_easy_setopt(curl,CURLOPT_HTTPGET,1); | ||
236 | }else if(method=="HEAD") { | ||
237 | r = curl_easy_setopt(curl,CURLOPT_NOBODY,1); | ||
238 | }else /* TODO: specialize exception */ | ||
239 | throw exception(OPKELE_CP_ "don't know how to handle http method"); | ||
240 | if(r) | ||
241 | throw exception_curl(OPKELE_CP_ "failed to set curly options",r); | ||
242 | if(!authorize_header.empty()) { | ||
243 | r = curl_easy_setopt(curl,CURLOPT_HTTPHEADER,(curl_slist*)( | ||
244 | _curl_headers_list = curl_slist_append( | ||
245 | 0,string("Authorization: "+authorize_header).c_str() | ||
246 | ) | ||
247 | ) ); | ||
248 | if(r) | ||
249 | throw exception_curl(OPKELE_CP_ "failed to setup curlie header"); | ||
250 | } | ||
251 | } | ||
252 | |||
225 | 253 | ||
226 | const basic_provider_endpoints& simple_consumer::get_endpoints() const { | 254 | const basic_provider_endpoints& simple_consumer::get_endpoints() const { |