Permalink
Browse files

Adding wrapper to onion_response_add_cookie in C++ binding

1 parent 5623450 commit 31c3ed5c1e04bca80fb555afcb458bbfc31ad522 Omar Givernaud committed with May 7, 2017
Showing with 33 additions and 1 deletion.
  1. +33 −1 src/bindings/cpp/response.hpp
@@ -84,7 +84,39 @@ namespace Onion{
void setLength(size_t length){
onion_response_set_length(ptr,length);
}
-
+
+ /**
+ * @short Sets a new cookie into the response.
+ * @ingroup response
+ *
+ * @param cookiename Name for the cookie
+ * @param cookievalue Value for the cookis
+ * @param validity_t Seconds this cookie is valid (added to current datetime). -1 to do not expire, 0 to expire inmediatly.
+ * @param path Cookie valid only for this path
+ * @param Domain Cookie valid only for this domain (www.example.com, or *.example.com).
+ * @param flags Flags from onion_cookie_flags_t, for example OC_SECURE or OC_HTTP_ONLY
+ *
+ *
+ * If validity is 0, cookie is set to expire right now.
+ */
+ void addCookie(const std::string cookiename,
+ const std::string cookievalue,
+ time_t validity_t,
+ const std::string path,
+ const std::string domain,
+ int flags) {
+
+ const char *_path = ((path.empty())?NULL:path.c_str());
+ const char *_domain = ((domain.empty())?NULL:domain.c_str());
+ onion_response_add_cookie(ptr,
+ cookiename.c_str(),
+ cookievalue.c_str(),
+ validity_t,
+ _path,
+ _domain,
+ flags);
+ }
+
/**
* @short Sets the response code, by default 200.
*/

0 comments on commit 31c3ed5

Please sign in to comment.