staticlib_http  1.3.2
 All Classes Namespaces Files Functions Variables
session.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017, alex at staticlibs.net
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /*
18  * File: session.hpp
19  * Author: alex
20  *
21  * Created on March 25, 2017, 5:29 PM
22  */
23 
24 #ifndef STATICLIB_HTTP_SESSION_HPP
25 #define STATICLIB_HTTP_SESSION_HPP
26 
27 #include <istream>
28 #include <memory>
29 #include <streambuf>
30 
31 #include "staticlib/config.hpp"
32 #include "staticlib/io.hpp"
33 #include "staticlib/pimpl.hpp"
34 
39 
40 namespace staticlib {
41 namespace http {
42 
43 class session : public sl::pimpl::object {
44 protected:
48  class impl;
49 
56 
57 public:
63  PIMPL_CONSTRUCTOR(session)
64 
65 
73  const std::string& url,
75 
85  const std::string& url,
86  std::streambuf* post_data,
88 
97  template<typename PostDataSource,
98  class = typename std::enable_if<!std::is_lvalue_reference<PostDataSource>::value>::type>
100  const std::string& url,
101  PostDataSource&& post_data,
102  request_options opts = request_options{}) {
103  std::unique_ptr<std::istream> sbuf{
104  staticlib::io::make_source_istream_ptr(std::move(post_data))
105  };
106  return open_url(url, std::move(sbuf), std::move(opts));
107  }
108 
117  template<typename PostDataSource>
119  const std::string& url,
120  PostDataSource& post_data,
121  request_options opts = request_options{}) {
122  std::unique_ptr<std::istream> sbuf{
123  staticlib::io::make_source_istream_ptr(post_data)
124  };
125  return open_url(url, std::move(sbuf), std::move(opts));
126  }
127 
136  virtual resource open_url(
137  const std::string& url,
138  std::unique_ptr<std::istream> post_data,
139  request_options opts = request_options{}) = 0;
140 
141 };
142 
143 } // namespace
144 }
145 
146 #endif /* STATICLIB_HTTP_SESSION_HPP */
147