10 #include "metacube2.h"
14 class HTTPInput : public Input {
16 HTTPInput(const std::string &url, Input::Encoding encoding);
18 // Serialization/deserialization.
19 HTTPInput(const InputProto &serialized);
20 virtual InputProto serialize() const;
22 virtual void close_socket();
24 virtual std::string get_url() const { return url; }
26 virtual void add_destination(int stream_index);
28 virtual InputStats get_stats() const;
31 // Actually does the download.
32 virtual void do_work();
34 // Open a socket that connects to the given host and port. Does DNS resolving.
35 int lookup_and_connect(const std::string &host, const std::string &port);
37 // Parses a HTTP response. Returns false if it not a 200.
38 bool parse_response(const std::string &response);
40 // Stores the given data, looks for Metacube blocks (skipping data if needed),
41 // and calls process_block() for each one.
42 void process_data(char *ptr, size_t bytes);
44 // Drops <num_bytes> bytes from the head of <pending_data>,
45 // and outputs a warning.
46 void drop_pending_data(size_t num_bytes);
48 void process_metacube_metadata_block(const metacube2_block_header &hdr, const char *payload, uint32_t payload_size);
55 CLOSING_SOCKET, // Due to error.
59 std::vector<int> stream_indices;
61 // The URL and its parsed components.
63 std::string host, port, path;
65 // What the input stream is to be interpreted as (normally Metacube).
66 Input::Encoding encoding;
68 // The HTTP request, with headers and all.
69 // Only relevant for SENDING_REQUEST.
72 // How many bytes we've sent of the request so far.
73 // Only relevant for SENDING_REQUEST.
74 size_t request_bytes_sent;
76 // The HTTP response we've received so far. Only relevant for RECEIVING_HEADER.
79 // The HTTP response headers we want to give clients for this input.
80 std::string http_header;
82 // The stream heder we want to give clients for this input.
83 std::string stream_header;
85 // Data we have received but not fully processed yet.
86 std::vector<char> pending_data;
88 // If <pending_data> starts with a Metacube header,
90 bool has_metacube_header;
92 // The socket we are downloading on (or -1).
95 // Mutex protecting <stats>.
96 mutable pthread_mutex_t stats_mutex;
98 // The current statistics for this connection. Protected by <stats_mutex>.
101 // Number of (started) connection attempts since last data byte was successfully read.
102 unsigned num_connection_attempts;
104 // If set, don't log anything related to connections.
105 // (Only set if we've had enough unsuccessful connection attempts.)
106 bool suppress_logging;
108 // Last time we made a connection with logging enabled.
109 // (Initially at some point before the epoch.)
110 timespec last_verbose_connection;
113 #endif // !defined(_HTTPINPUT_H)