aboutsummaryrefslogtreecommitdiffstats
path: root/icnet/http
diff options
context:
space:
mode:
Diffstat (limited to 'icnet/http')
-rw-r--r--icnet/http/icnet_http_client_connection.cc119
-rw-r--r--icnet/http/icnet_http_client_connection.h56
-rw-r--r--icnet/http/icnet_http_default_values.h30
-rw-r--r--icnet/http/icnet_http_facade.h22
-rw-r--r--icnet/http/icnet_http_request.cc101
-rw-r--r--icnet/http/icnet_http_request.h71
-rw-r--r--icnet/http/icnet_http_server_acceptor.cc171
-rw-r--r--icnet/http/icnet_http_server_acceptor.h62
-rw-r--r--icnet/http/icnet_http_server_publisher.cc79
-rw-r--r--icnet/http/icnet_http_server_publisher.h72
10 files changed, 783 insertions, 0 deletions
diff --git a/icnet/http/icnet_http_client_connection.cc b/icnet/http/icnet_http_client_connection.cc
new file mode 100644
index 00000000..1f0d8fd8
--- /dev/null
+++ b/icnet/http/icnet_http_client_connection.cc
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_client_connection.h"
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace icnet {
+
+namespace http {
+
+using namespace transport;
+
+HTTPClientConnection::HTTPClientConnection()
+ : consumer_(Name("ccnx:"), transport::TransportProtocolAlgorithms::RAAQM) {
+
+ consumer_.setSocketOption(GeneralTransportOptions::INTEREST_LIFETIME, 1001);
+ consumer_.setSocketOption(RaaqmTransportOptions::BETA_VALUE, DEFAULT_BETA);
+ consumer_.setSocketOption(RaaqmTransportOptions::DROP_FACTOR, DEFAULT_GAMMA);
+ consumer_.setSocketOption(GeneralTransportOptions::MAX_INTEREST_RETX, 200);
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
+ (ConsumerContentObjectVerificationCallback) std::bind(&HTTPClientConnection::verifyData,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED,
+ (ConsumerContentCallback) std::bind(&HTTPClientConnection::processPayload,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+}
+
+HTTPClientConnection &HTTPClientConnection::get(std::string &url, HTTPHeaders headers, HTTPPayload payload) {
+
+ HTTPRequest request(GET, url, headers, payload);
+
+ std::string &request_string = request.getRequestString();
+ std::string &locator = request.getLocator();
+ std::string &path = request.getPath();
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
+ (ConsumerInterestCallback) std::bind(&HTTPClientConnection::processLeavingInterest,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2,
+ request_string));
+
+ // Send content to producer piggybacking it through first interest (to fix)
+
+ response_.clear();
+
+ // Factor icn name
+
+ std::stringstream stream;
+
+ stream << "ccnx:/";
+ stream << locator << "/get";
+ stream << path;
+
+ consumer_.consume(Name(stream.str()));
+
+ consumer_.stop();
+
+ return *this;
+}
+
+HTTPResponse &&HTTPClientConnection::response() {
+ return std::move(response_);
+}
+
+void HTTPClientConnection::processPayload(transport::ConsumerSocket &c,
+ std::vector<uint8_t> &&payload) {
+ response_ = std::move(payload);
+}
+
+bool HTTPClientConnection::verifyData(transport::ConsumerSocket &c, const ContentObject &contentObject) {
+ if (contentObject.getPayloadType() == PayloadType::DATA) {
+ std::cout << "VERIFY CONTENT" << std::endl;
+ } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) {
+ std::cout << "VERIFY MANIFEST" << std::endl;
+ }
+
+ return true;
+}
+
+void HTTPClientConnection::processLeavingInterest(transport::ConsumerSocket &c,
+ const Interest &interest,
+ std::string &payload) {
+ if (interest.getName().get(-1).toSegment() == 0) {
+ Interest &int2 = const_cast<Interest &>(interest);
+ int2.setPayload((const uint8_t *) payload.data(), payload.size());
+ }
+}
+
+HTTPClientConnection& HTTPClientConnection::stop() {
+ // This is thread safe and can be called from another thread
+ consumer_.stop();
+
+ return *this;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_client_connection.h b/icnet/http/icnet_http_client_connection.h
new file mode 100644
index 00000000..5a009d88
--- /dev/null
+++ b/icnet/http/icnet_http_client_connection.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_utils_uri.h"
+#include "icnet_http_request.h"
+#include "icnet_http_default_values.h"
+
+#include <vector>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+class HTTPClientConnection {
+ public:
+ HTTPClientConnection();
+
+ HTTPClientConnection &get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+
+ HTTPResponse &&response();
+
+ HTTPClientConnection &stop();
+
+ private:
+
+ void processPayload(transport::ConsumerSocket &c, std::vector<uint8_t> &&payload);
+
+ bool verifyData(transport::ConsumerSocket &c, const transport::ContentObject &contentObject);
+
+ void processLeavingInterest(transport::ConsumerSocket &c, const transport::Interest &interest, std::string &payload);
+
+ HTTPResponse response_;
+ transport::ConsumerSocket consumer_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_default_values.h b/icnet/http/icnet_http_default_values.h
new file mode 100644
index 00000000..5aaf60d8
--- /dev/null
+++ b/icnet/http/icnet_http_default_values.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+namespace hicnet {
+
+namespace http {
+
+namespace default_values {
+
+const uint16_t ipv6_first_word = 0xb001; // Network byte order
+
+} // end namespace transport
+
+} // end namespace default_values
+
+} // end namespace hicnet
diff --git a/icnet/http/icnet_http_facade.h b/icnet/http/icnet_http_facade.h
new file mode 100644
index 00000000..f32eff73
--- /dev/null
+++ b/icnet/http/icnet_http_facade.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "icnet_http_server_acceptor.h"
+#include "icnet_http_server_publisher.h"
+#include "icnet_http_client_connection.h"
+
+namespace libl4 = icnet; \ No newline at end of file
diff --git a/icnet/http/icnet_http_request.cc b/icnet/http/icnet_http_request.cc
new file mode 100644
index 00000000..cd0c512f
--- /dev/null
+++ b/icnet/http/icnet_http_request.cc
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_request.h"
+#include "icnet_utils_uri.h"
+
+namespace icnet {
+
+namespace http {
+
+static std::map<HTTPMethod, std::string> method_map = {
+ {GET, "GET"},
+ {POST, "POST"},
+ {PUT, "PUT"},
+ {PATCH, "PATCH"},
+ {DELETE, "DELETE"},
+};
+
+//std::map<HTTPMethod, std::string> method_map
+
+HTTPRequest::HTTPRequest(HTTPMethod method, std::string &url, HTTPHeaders &headers, HTTPPayload &payload) {
+ utils::Uri uri;
+ uri.parse(url);
+
+ path_ = uri.getPath();
+ query_string_ = uri.getQueryString();
+ protocol_ = uri.getProtocol();
+ locator_ = uri.getLocator();
+ port_ = uri.getPort();
+
+ headers_ = headers;
+ payload_ = payload;
+
+ std::transform(locator_.begin(),
+ locator_.end(),
+ locator_.begin(),
+ ::tolower);
+
+ std::transform(protocol_.begin(),
+ protocol_.end(),
+ protocol_.begin(),
+ ::tolower);
+
+ std::stringstream stream;
+ stream << method_map[method] << " " << uri.getPath() << " HTTP/" << HTTP_VERSION << "\r\n";
+ for (auto &item : headers) {
+ stream << item.first << ": " << item.second << "\r\n";
+ }
+ stream << "\r\n";
+ stream << payload.data();
+
+ request_string_ = stream.str();
+}
+
+std::string &HTTPRequest::getPort() {
+ return port_;
+}
+
+std::string &HTTPRequest::getLocator() {
+ return locator_;
+}
+
+std::string &HTTPRequest::getProtocol() {
+ return protocol_;
+}
+
+std::string &HTTPRequest::getPath() {
+ return path_;
+}
+
+std::string &HTTPRequest::getQueryString() {
+ return query_string_;
+}
+
+HTTPHeaders &HTTPRequest::getHeaders() {
+ return headers_;
+}
+
+HTTPPayload &HTTPRequest::getPayload() {
+ return payload_;
+}
+
+std::string &HTTPRequest::getRequestString() {
+ return request_string_;
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_request.h b/icnet/http/icnet_http_request.h
new file mode 100644
index 00000000..985d7628
--- /dev/null
+++ b/icnet/http/icnet_http_request.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <sstream>
+#include <vector>
+#include <map>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+typedef enum {
+ GET,
+ POST,
+ PUT,
+ PATCH,
+ DELETE
+} HTTPMethod;
+
+typedef std::map<std::string, std::string> HTTPHeaders;
+typedef std::vector<uint8_t> HTTPPayload;
+typedef std::vector<uint8_t> HTTPResponse;
+
+class HTTPRequest {
+ public:
+
+ HTTPRequest(HTTPMethod method,
+ std::string &url, HTTPHeaders &headers, HTTPPayload &payload);
+
+ std::string &getQueryString();
+
+ std::string &getPath();
+
+ std::string &getProtocol();
+
+ std::string &getLocator();
+
+ std::string &getPort();
+
+ std::string &getRequestString();
+
+ HTTPHeaders &getHeaders();
+
+ HTTPPayload &getPayload();
+
+ private:
+ std::string query_string_, path_, protocol_, locator_, port_;
+ std::string request_string_;
+ HTTPHeaders headers_;
+ HTTPPayload payload_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_acceptor.cc b/icnet/http/icnet_http_server_acceptor.cc
new file mode 100644
index 00000000..9406955d
--- /dev/null
+++ b/icnet/http/icnet_http_server_acceptor.cc
@@ -0,0 +1,171 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_server_acceptor.h"
+#include "icnet_http_request.h"
+#include "icnet_errors.h"
+#include "icnet_utils_uri.h"
+#include "icnet_utils_hash.h"
+
+namespace icnet {
+
+namespace http {
+
+HTTPServerAcceptor::HTTPServerAcceptor(std::string &&server_locator, OnHttpRequest callback)
+ : HTTPServerAcceptor(server_locator, callback) {
+}
+
+HTTPServerAcceptor::HTTPServerAcceptor(std::string &server_locator, OnHttpRequest callback)
+ : callback_(callback) {
+ utils::Uri uri;
+
+ uri.parseProtocolAndLocator(server_locator);
+ std::string protocol = uri.getProtocol();
+ std::string locator = uri.getLocator();
+
+ std::transform(locator.begin(),
+ locator.end(),
+ locator.begin(),
+ ::tolower);
+
+ std::transform(protocol.begin(),
+ protocol.end(),
+ protocol.begin(),
+ ::tolower);
+
+ if (protocol != "http") {
+ throw errors::RuntimeException("Malformed server_locator. The locator format should be in the form http://locator");
+ }
+
+ std::stringstream ss;
+
+ ss << "ccnx:/";
+ ss << locator;
+
+ acceptor_producer_ = std::make_shared<transport::ProducerSocket>(ss.str());
+}
+
+void HTTPServerAcceptor::listen(bool async) {
+ acceptor_producer_->setSocketOption(icnet::transport::ProducerCallbacksOptions::INTEREST_INPUT,
+ (icnet::transport::ProducerInterestCallback) bind(&HTTPServerAcceptor::processIncomingInterest,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2));
+ acceptor_producer_->dispatch();
+
+ if (!async) {
+ acceptor_producer_->serveForever();
+ }
+}
+
+HttpRequest &&HTTPServerAcceptor::request() {
+ return std::move(request_);
+}
+
+void HTTPServerAcceptor::processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest) {
+ // Temporary solution
+
+ transport::Name complete_name = interest.getName();
+
+ transport::Name request_name = complete_name.get(-1).isSegment() ? complete_name.getPrefix(-1) : complete_name;
+ transport::Name prefix;
+ acceptor_producer_->getSocketOption(transport::GeneralTransportOptions::NAME_PREFIX, prefix);
+
+ // Get the name of the HTTP method to compute
+ std::string method = request_name.get(prefix.getSegmentCount()).toString();
+ std::transform(method.begin(), method.end(), method.begin(), ::toupper);
+ std::string path;
+ std::string url_begin;
+
+ // This is done for getting rid of useless name components such as ccnx: or ndn:
+ if (request_name.getSegmentCount() > 2) {
+ std::string raw_path = request_name.getSubName(prefix.getSegmentCount() + 1).toString();
+ std::size_t pos = raw_path.find("/");
+ path = raw_path.substr(pos);
+ url_begin = prefix.getSubName(0).toString().substr(pos);
+ }
+
+ std::stringstream ss;
+ ss << "http:/" << url_begin << path;
+
+ std::string url = ss.str();
+ HTTPHeaders headers = {};
+ HTTPPayload payload = {};
+
+ if (method == "GET") {
+ HTTPRequest request(GET, url, headers, payload);
+ auto publisher = std::make_shared<HTTPServerPublisher>(request_name);
+ callback_(publisher, (uint8_t *) request.getRequestString().data(), request.getRequestString().size());
+ }
+}
+
+//void HTTPServerConnection::sendResponse() {
+//
+// std::thread t([]() {
+//
+// // Get the name of the HTTP method to compute
+// std::string method = request_name.get(1).toString();
+// std::transform(method.begin(), method.end(), method.begin(), ::toupper);
+// std::string path;
+//
+// // This is done for getting rid of useless name components such as ccnx: or ndn:
+// if (request_name.getSegmentCount() > 2) {
+// std::string rawPath = request_name.getSubName(2).toString();
+// std::size_t pos = rawPath.find("/");
+// path = rawPath.substr(pos);
+// }
+//
+// // Create new producer
+//
+// // Create timer for response availability
+// std::shared_ptr<core::Portal> portal;
+// po->getSocketOption(icnet::GeneralTransportOptions::PORTAL, portal);
+// boost::asio::io_service &ioService = portal->getIoService();
+//
+// boost::asio::deadline_timer t(ioService, boost::posix_time::seconds(5));
+//
+// std::function<void(const boost::system::error_code e)>
+// wait_callback = [&ioService](const boost::system::error_code e) {
+// if (!e) {
+// // Be sure to delete the timer before the io_service, otherwise we'll get some strange behavior!
+// ioService.stop();
+// }
+// };
+//
+// std::function<void(transport::ProducerSocket, const core::Interest &interest)>
+// interest_enter_callback = [this, &wait_callback, &t]
+// (transport::ProducerSocket &p, const core::Interest &interest) {
+// t.cancel();
+// t.expires_from_now(boost::posix_time::seconds(5));
+// t.async_wait(wait_callback);
+// };
+//
+// p->setSocketOption(transport::ProducerCallbacksOptions::INTEREST_INPUT,
+// (transport::ProducerInterestCallback) interest_enter_callback);
+//
+// t.async_wait(wait_callback);
+//
+// p->serveForever();
+//
+// std::unique_lock<std::mutex> lock(thread_list_mtx_);
+// icn_producers_.erase(request_name);
+// });
+//
+// t.detach();
+//}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_acceptor.h b/icnet/http/icnet_http_server_acceptor.h
new file mode 100644
index 00000000..2d0b7f25
--- /dev/null
+++ b/icnet/http/icnet_http_server_acceptor.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_http_default_values.h"
+#include "icnet_http_server_publisher.h"
+
+#include <vector>
+#include <functional>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+//typedef std::vector<uint8_t> HTTPResponse;
+typedef std::vector<uint8_t> HttpRequest;
+typedef std::function<void(std::shared_ptr<HTTPServerPublisher> &, const uint8_t *, std::size_t)> OnHttpRequest;
+
+class HTTPServerAcceptor {
+ public:
+ HTTPServerAcceptor(std::string &&server_locator, OnHttpRequest callback);
+ HTTPServerAcceptor(std::string &server_locator, OnHttpRequest callback);
+
+ void listen(bool async);
+
+ HttpRequest &&request();
+
+// void asyncSendResponse();
+
+// HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+//
+// HTTPResponse&& response();
+
+ private:
+
+ void processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest);
+
+ OnHttpRequest callback_;
+ HttpRequest request_;
+ std::shared_ptr<transport::ProducerSocket> acceptor_producer_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_publisher.cc b/icnet/http/icnet_http_server_publisher.cc
new file mode 100644
index 00000000..8ff86459
--- /dev/null
+++ b/icnet/http/icnet_http_server_publisher.cc
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_http_server_publisher.h"
+
+namespace icnet {
+
+namespace http {
+
+HTTPServerPublisher::HTTPServerPublisher(const transport::Name &content_name)
+ : content_name_(content_name) {
+ // Create a new publisher
+ producer_ = std::unique_ptr<transport::ProducerSocket>(new transport::ProducerSocket(content_name));
+ producer_->attach();
+}
+
+HTTPServerPublisher::~HTTPServerPublisher() {
+ this->timer_->cancel();
+}
+
+HTTPServerPublisher &HTTPServerPublisher::setTimeout(uint32_t timeout) {
+ std::shared_ptr<transport::Portal> portal;
+ producer_->getSocketOption(transport::GeneralTransportOptions::PORTAL, portal);
+ timer_ = std::unique_ptr<boost::asio::deadline_timer>(new boost::asio::deadline_timer(portal->getIoService(),
+ boost::posix_time::seconds(
+ timeout)));
+
+ wait_callback_ = [this](const boost::system::error_code e) {
+ if (!e) {
+ producer_->stop();
+ }
+ };
+
+ interest_enter_callback_ = [this, timeout](transport::ProducerSocket &p, const transport::Interest &interest) {
+ this->timer_->cancel();
+ this->timer_->expires_from_now(boost::posix_time::seconds(timeout));
+ this->timer_->async_wait(wait_callback_);
+ };
+
+ producer_->setSocketOption(transport::ProducerCallbacksOptions::INTEREST_INPUT,
+ (transport::ProducerInterestCallback) interest_enter_callback_);
+
+ timer_->async_wait(wait_callback_);
+
+ return *this;
+}
+
+void HTTPServerPublisher::publishContent(const uint8_t *buf, size_t buffer_size, const int response_id, bool is_last) {
+ if (producer_) {
+ std::cout << "Replying to " << content_name_ << std::endl;
+ producer_->produce(content_name_, buf, buffer_size, response_id, is_last);
+ }
+}
+
+void HTTPServerPublisher::serveClients() {
+ producer_->serveForever();
+}
+
+void HTTPServerPublisher::stop() {
+ std::shared_ptr<transport::Portal> portal_ptr;
+ producer_->getSocketOption(transport::GeneralTransportOptions::PORTAL, portal_ptr);
+ portal_ptr->getIoService().stop();
+}
+
+}
+
+} \ No newline at end of file
diff --git a/icnet/http/icnet_http_server_publisher.h b/icnet/http/icnet_http_server_publisher.h
new file mode 100644
index 00000000..933d20c8
--- /dev/null
+++ b/icnet/http/icnet_http_server_publisher.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include "icnet_transport_socket_consumer.h"
+#include "icnet_transport_socket_producer.h"
+#include "icnet_http_default_values.h"
+
+#include <vector>
+#include <functional>
+
+#define HTTP_VERSION "1.0"
+
+namespace icnet {
+
+namespace http {
+
+typedef std::vector<uint8_t> HttpRequest;
+typedef std::function<void(const boost::system::error_code e)> DeadlineTimerCallback;
+
+class HTTPServerPublisher {
+ public:
+ HTTPServerPublisher(const transport::Name &content_name);
+
+ ~HTTPServerPublisher();
+
+ void publishContent(const uint8_t *buf,
+ size_t buffer_size,
+ const int response_id,
+ bool is_last);
+
+ void serveClients();
+
+ void stop();
+
+ HTTPServerPublisher &setTimeout(uint32_t timeout);
+
+// HttpRequest&& request();
+
+// void sendResponse();
+
+// HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {}, HTTPPayload payload = {});
+//
+// HTTPResponse&& response();
+
+ private:
+
+ void processIncomingInterest(transport::ProducerSocket &p, const transport::Interest &interest);
+
+ transport::Name content_name_;
+ std::unique_ptr<boost::asio::deadline_timer> timer_;
+ std::unique_ptr<transport::ProducerSocket> producer_;
+ transport::ProducerInterestCallback interest_enter_callback_;
+ DeadlineTimerCallback wait_callback_;
+};
+
+} // end namespace http
+
+} // end namespace icnet \ No newline at end of file