2014-09-21 11:28:06 +02:00
|
|
|
/*
|
|
|
|
* nghttp2 - HTTP/2 C Library
|
|
|
|
*
|
2015-03-05 13:42:48 +01:00
|
|
|
* Copyright (c) 2015 Tatsuhiro Tsujikawa
|
2014-09-21 11:28:06 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2015-03-05 13:42:48 +01:00
|
|
|
#ifndef ASIO_SERVER_RESPONSE_IMPL_H
|
|
|
|
#define ASIO_SERVER_RESPONSE_IMPL_H
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
#include "nghttp2_config.h"
|
|
|
|
|
2015-03-03 18:43:13 +01:00
|
|
|
#include <nghttp2/asio_http2_server.h>
|
2014-09-21 11:28:06 +02:00
|
|
|
|
|
|
|
namespace nghttp2 {
|
|
|
|
namespace asio_http2 {
|
|
|
|
namespace server {
|
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
class stream;
|
2014-09-21 11:28:06 +02:00
|
|
|
|
2015-03-05 16:06:53 +01:00
|
|
|
enum class response_state {
|
|
|
|
INITIAL,
|
|
|
|
// response_impl::write_head() was called
|
|
|
|
HEADER_DONE,
|
|
|
|
// response_impl::end() was called
|
|
|
|
BODY_STARTED,
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
class response_impl {
|
2014-09-21 11:28:06 +02:00
|
|
|
public:
|
2015-03-05 13:42:48 +01:00
|
|
|
response_impl();
|
2015-03-14 07:54:55 +01:00
|
|
|
void write_head(unsigned int status_code, header_map h = header_map{});
|
2015-03-05 13:42:48 +01:00
|
|
|
void end(std::string data = "");
|
2015-03-05 17:47:55 +01:00
|
|
|
void end(generator_cb cb);
|
2015-03-07 11:26:42 +01:00
|
|
|
void write_trailer(header_map h);
|
2015-03-05 13:42:48 +01:00
|
|
|
void on_close(close_cb cb);
|
|
|
|
void resume();
|
|
|
|
|
|
|
|
void cancel(uint32_t error_code);
|
|
|
|
|
|
|
|
response *push(boost::system::error_code &ec, std::string method,
|
2015-03-14 07:54:55 +01:00
|
|
|
std::string raw_path_query, header_map) const;
|
2015-03-05 13:42:48 +01:00
|
|
|
|
|
|
|
boost::asio::io_service &io_service();
|
|
|
|
|
|
|
|
void start_response();
|
|
|
|
|
|
|
|
unsigned int status_code() const;
|
|
|
|
const header_map &header() const;
|
|
|
|
void pushed(bool f);
|
2015-03-05 16:06:53 +01:00
|
|
|
void push_promise_sent();
|
2015-03-05 13:42:48 +01:00
|
|
|
void stream(class stream *s);
|
2015-03-05 17:47:55 +01:00
|
|
|
generator_cb::result_type call_read(uint8_t *data, std::size_t len,
|
|
|
|
uint32_t *data_flags);
|
2015-03-05 13:42:48 +01:00
|
|
|
void call_on_close(uint32_t error_code);
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2014-09-21 11:28:06 +02:00
|
|
|
private:
|
2015-03-05 13:42:48 +01:00
|
|
|
class stream *strm_;
|
|
|
|
header_map header_;
|
2015-03-05 17:47:55 +01:00
|
|
|
generator_cb generator_cb_;
|
2015-03-05 13:42:48 +01:00
|
|
|
close_cb close_cb_;
|
|
|
|
unsigned int status_code_;
|
2015-03-05 16:06:53 +01:00
|
|
|
response_state state_;
|
2015-03-05 13:42:48 +01:00
|
|
|
// true if this is pushed stream's response
|
|
|
|
bool pushed_;
|
|
|
|
// true if PUSH_PROMISE is sent if this is response of a pushed
|
|
|
|
// stream
|
|
|
|
bool push_promise_sent_;
|
2014-09-21 11:28:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace server
|
|
|
|
} // namespace asio_http2
|
|
|
|
} // namespace nghttp2
|
|
|
|
|
2015-03-05 13:42:48 +01:00
|
|
|
#endif // ASIO_SERVER_RESPONSE_IMPL_H
|