12 class HTTPInput : public Input {
14 HTTPInput(const std::string &url);
16 // Serialization/deserialization.
17 HTTPInput(const InputProto &serialized);
18 virtual InputProto serialize() const;
20 virtual void close_socket();
22 virtual std::string get_url() const { return url; }
24 virtual void add_destination(int stream_index);
26 virtual InputStats get_stats() const;
29 // Actually does the download.
30 virtual void do_work();
32 // Open a socket that connects to the given host and port. Does DNS resolving.
33 int lookup_and_connect(const std::string &host, const std::string &port);
35 // Parses a HTTP response. Returns false if it not a 200.
36 bool parse_response(const std::string &response);
38 // Stores the given data, looks for Metacube blocks (skipping data if needed),
39 // and calls process_block() for each one.
40 void process_data(char *ptr, size_t bytes);
42 // Drops <num_bytes> bytes from the head of <pending_data>,
43 // and outputs a warning.
44 void drop_pending_data(size_t num_bytes);
51 CLOSING_SOCKET, // Due to error.
55 std::vector<int> stream_indices;
57 // The URL and its parsed components.
59 std::string host, port, path;
61 // The HTTP request, with headers and all.
62 // Only relevant for SENDING_REQUEST.
65 // How many bytes we've sent of the request so far.
66 // Only relevant for SENDING_REQUEST.
67 size_t request_bytes_sent;
69 // The HTTP response we've received so far. Only relevant for RECEIVING_HEADER.
72 // The HTTP response headers we want to give clients for this input.
73 std::string http_header;
75 // The stream heder we want to give clients for this input.
76 std::string stream_header;
78 // Data we have received but not fully processed yet.
79 std::vector<char> pending_data;
81 // If <pending_data> starts with a Metacube header,
83 bool has_metacube_header;
85 // The socket we are downloading on (or -1).
88 // Mutex protecting <stats>.
89 mutable pthread_mutex_t stats_mutex;
91 // The current statistics for this connection. Protected by <stats_mutex>.
95 #endif // !defined(_HTTPINPUT_H)