]> git.sesse.net Git - cubemap/blob - httpinput.cpp
Fix verbosity checks on deserialization.
[cubemap] / httpinput.cpp
1 #include <assert.h>
2 #include <errno.h>
3 #include <netdb.h>
4 #include <netinet/in.h>
5 #include <poll.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/ioctl.h>
10 #include <sys/socket.h>
11 #include <sys/time.h>
12 #include <time.h>
13 #include <unistd.h>
14 #include <map>
15 #include <string>
16 #include <utility>
17 #include <vector>
18
19 #include "httpinput.h"
20 #include "log.h"
21 #include "metacube2.h"
22 #include "mutexlock.h"
23 #include "parse.h"
24 #include "serverpool.h"
25 #include "state.pb.h"
26 #include "stream.h"
27 #include "timespec.h"
28 #include "util.h"
29 #include "version.h"
30
31 using namespace std;
32
33 namespace {
34
35 string host_header(const string &host, const string &port)
36 {
37         if (port == "http" || atoi(port.c_str()) == 80) {
38                 return host;
39         } else {
40                 return host + ":" + port;
41         }
42 }
43
44 }  // namespace
45
46 extern ServerPool *servers;
47
48 HTTPInput::HTTPInput(const string &url, Input::Encoding encoding)
49         : state(NOT_CONNECTED),
50           url(url),
51           encoding(encoding),
52           has_metacube_header(false),
53           sock(-1),
54           num_connection_attempts(0),
55           suppress_logging(false)
56 {
57         pthread_mutex_init(&stats_mutex, NULL);
58         stats.url = url;
59         stats.bytes_received = 0;
60         stats.data_bytes_received = 0;
61         stats.connect_time = -1;
62
63         last_verbose_connection.tv_sec = -3600;
64         last_verbose_connection.tv_nsec = 0;
65 }
66
67 HTTPInput::HTTPInput(const InputProto &serialized)
68         : state(State(serialized.state())),
69           url(serialized.url()),
70           encoding(serialized.is_metacube_encoded() ?
71                    Input::INPUT_ENCODING_METACUBE :
72                    Input::INPUT_ENCODING_RAW),
73           request(serialized.request()),
74           request_bytes_sent(serialized.request_bytes_sent()),
75           response(serialized.response()),
76           http_header(serialized.http_header()),
77           stream_header(serialized.stream_header()),
78           has_metacube_header(serialized.has_metacube_header()),
79           sock(serialized.sock()),
80           num_connection_attempts(0),
81           suppress_logging(false)
82 {
83         pending_data.resize(serialized.pending_data().size());
84         memcpy(&pending_data[0], serialized.pending_data().data(), serialized.pending_data().size());
85
86         string protocol, user;
87         parse_url(url, &protocol, &user, &host, &port, &path);  // Don't care if it fails.
88
89         pthread_mutex_init(&stats_mutex, NULL);
90         stats.url = url;
91         stats.bytes_received = serialized.bytes_received();
92         stats.data_bytes_received = serialized.data_bytes_received();
93         if (serialized.has_connect_time()) {
94                 stats.connect_time = serialized.connect_time();
95         } else {
96                 stats.connect_time = time(NULL);
97         }
98
99         last_verbose_connection.tv_sec = -3600;
100         last_verbose_connection.tv_nsec = 0;
101 }
102
103 void HTTPInput::close_socket()
104 {
105         if (sock != -1) {
106                 safe_close(sock);
107                 sock = -1;
108         }
109
110         MutexLock lock(&stats_mutex);
111         stats.connect_time = -1;
112 }
113
114 InputProto HTTPInput::serialize() const
115 {
116         InputProto serialized;
117         serialized.set_state(state);
118         serialized.set_url(url);
119         serialized.set_request(request);
120         serialized.set_request_bytes_sent(request_bytes_sent);
121         serialized.set_response(response);
122         serialized.set_http_header(http_header);
123         serialized.set_stream_header(stream_header);
124         serialized.set_pending_data(string(pending_data.begin(), pending_data.end()));
125         serialized.set_has_metacube_header(has_metacube_header);
126         serialized.set_sock(sock);
127         serialized.set_bytes_received(stats.bytes_received);
128         serialized.set_data_bytes_received(stats.data_bytes_received);
129         serialized.set_connect_time(stats.connect_time);
130         if (encoding == Input::INPUT_ENCODING_METACUBE) {
131                 serialized.set_is_metacube_encoded(true);
132         } else {
133                 assert(encoding == Input::INPUT_ENCODING_RAW);
134                 serialized.set_is_metacube_encoded(false);
135         }
136         return serialized;
137 }
138
139 int HTTPInput::lookup_and_connect(const string &host, const string &port)
140 {
141         addrinfo *ai;
142         int err = getaddrinfo(host.c_str(), port.c_str(), NULL, &ai);
143         if (err != 0) {
144                 if (!suppress_logging) {
145                         log(WARNING, "[%s] Lookup of '%s' failed (%s).",
146                                 url.c_str(), host.c_str(), gai_strerror(err));
147                 }
148                 return -1;
149         }
150
151         addrinfo *base_ai = ai;
152
153         // Connect to everything in turn until we have a socket.
154         for ( ; ai && !should_stop(); ai = ai->ai_next) {
155                 int sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
156                 if (sock == -1) {
157                         // Could be e.g. EPROTONOSUPPORT. The show must go on.
158                         continue;
159                 }
160
161                 // Now do a non-blocking connect. This is important because we want to be able to be
162                 // woken up, even though it's rather cumbersome.
163
164                 // Set the socket as nonblocking.
165                 int one = 1;
166                 if (ioctl(sock, FIONBIO, &one) == -1) {
167                         log_perror("ioctl(FIONBIO)");
168                         safe_close(sock);
169                         return -1;                      
170                 }
171
172                 // Do a non-blocking connect.
173                 do {
174                         err = connect(sock, ai->ai_addr, ai->ai_addrlen);
175                 } while (err == -1 && errno == EINTR);
176
177                 if (err == -1 && errno != EINPROGRESS) {
178                         log_perror("connect");
179                         safe_close(sock);
180                         continue;
181                 }
182
183                 // Wait for the connect to complete, or an error to happen.
184                 for ( ;; ) {
185                         bool complete = wait_for_activity(sock, POLLIN | POLLOUT, NULL);
186                         if (should_stop()) {
187                                 safe_close(sock);
188                                 return -1;
189                         }
190                         if (complete) {
191                                 break;
192                         }
193                 }
194
195                 // Check whether it ended in an error or not.
196                 socklen_t err_size = sizeof(err);
197                 if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &err_size) == -1) {
198                         log_perror("getsockopt");
199                         safe_close(sock);
200                         continue;
201                 }
202
203                 errno = err;
204
205                 if (err == 0) {
206                         // Successful connect.
207                         freeaddrinfo(base_ai);
208                         return sock;
209                 }
210
211                 safe_close(sock);
212         }
213
214         // Give the last one as error.
215         if (!suppress_logging) {
216                 log(WARNING, "[%s] Connect to '%s' failed (%s)",
217                         url.c_str(), host.c_str(), strerror(errno));
218         }
219         freeaddrinfo(base_ai);
220         return -1;
221 }
222         
223 bool HTTPInput::parse_response(const string &request)
224 {
225         vector<string> lines = split_lines(response);
226         if (lines.empty()) {
227                 if (!suppress_logging) {
228                         log(WARNING, "[%s] Empty HTTP response from input.", url.c_str());
229                 }
230                 return false;
231         }
232
233         vector<string> first_line_tokens = split_tokens(lines[0]);
234         if (first_line_tokens.size() < 2) {
235                 if (!suppress_logging) {
236                         log(WARNING, "[%s] Malformed response line '%s' from input.",
237                                 url.c_str(), lines[0].c_str());
238                 }
239                 return false;
240         }
241
242         int response = atoi(first_line_tokens[1].c_str());
243         if (response != 200) {
244                 if (!suppress_logging) {
245                         log(WARNING, "[%s] Non-200 response '%s' from input.",
246                                 url.c_str(), lines[0].c_str());
247                 }
248                 return false;
249         }
250
251         multimap<string, string> parameters = extract_headers(lines, url);
252
253         // Remove “Content-encoding: metacube”.
254         // TODO: Make case-insensitive.
255         multimap<string, string>::iterator encoding_it =
256                 parameters.find("Content-encoding");
257         if (encoding_it != parameters.end() && encoding_it->second == "metacube") {
258                 parameters.erase(encoding_it);
259         }
260
261         // Change “Server: foo” to “Server: metacube/0.1 (reflecting: foo)”
262         // TODO: Make case-insensitive.
263         // XXX: Use a Via: instead?
264         if (parameters.count("Server") == 0) {
265                 parameters.insert(make_pair("Server", SERVER_IDENTIFICATION));
266         } else {
267                 for (multimap<string, string>::iterator it = parameters.begin();
268                      it != parameters.end();
269                      ++it) {
270                         if (it->first != "Server") {
271                                 continue;
272                         }
273                         it->second = SERVER_IDENTIFICATION " (reflecting: " + it->second + ")";
274                 }
275         }
276
277         // Set “Connection: close”.
278         // TODO: Make case-insensitive.
279         parameters.erase("Connection");
280         parameters.insert(make_pair("Connection", "close"));
281
282         // Construct the new HTTP header.
283         http_header = "HTTP/1.0 200 OK\r\n";
284         for (multimap<string, string>::iterator it = parameters.begin();
285              it != parameters.end();
286              ++it) {
287                 http_header.append(it->first + ": " + it->second + "\r\n");
288         }
289
290         for (size_t i = 0; i < stream_indices.size(); ++i) {
291                 servers->set_header(stream_indices[i], http_header, stream_header);
292         }
293
294         return true;
295 }
296
297 void HTTPInput::do_work()
298 {
299         timespec last_activity;
300
301         // TODO: Make the timeout persist across restarts.
302         if (state == SENDING_REQUEST || state == RECEIVING_HEADER || state == RECEIVING_DATA) {
303                 int err = clock_gettime(CLOCK_MONOTONIC_COARSE, &last_activity);
304                 assert(err != -1);
305         }
306
307         while (!should_stop()) {
308                 if (state == SENDING_REQUEST || state == RECEIVING_HEADER || state == RECEIVING_DATA) {
309                         // Give the socket 30 seconds since last activity before we time out.
310                         static const int timeout_secs = 30;
311
312                         timespec now;
313                         int err = clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
314                         assert(err != -1);
315
316                         timespec elapsed = clock_diff(last_activity, now);
317                         if (elapsed.tv_sec >= timeout_secs) {
318                                 // Timeout!
319                                 if (!suppress_logging) {
320                                         log(ERROR, "[%s] Timeout after %d seconds, closing.", url.c_str(), elapsed.tv_sec);
321                                 }
322                                 state = CLOSING_SOCKET;
323                                 continue;
324                         }
325
326                         // Basically calculate (30 - (now - last_activity)) = (30 + (last_activity - now)).
327                         // Add a second of slack to account for differences between clocks.
328                         timespec timeout = clock_diff(now, last_activity);
329                         timeout.tv_sec += timeout_secs + 1;
330                         assert(timeout.tv_sec > 0 || (timeout.tv_sec >= 0 && timeout.tv_nsec > 0));
331
332                         bool activity = wait_for_activity(sock, (state == SENDING_REQUEST) ? POLLOUT : POLLIN, &timeout);
333                         if (activity) {
334                                 err = clock_gettime(CLOCK_MONOTONIC_COARSE, &last_activity);
335                                 assert(err != -1);
336                         } else {
337                                 // OK. Most likely, should_stop was set, or we have timed out.
338                                 continue;
339                         }
340                 }
341
342                 switch (state) {
343                 case NOT_CONNECTED:
344                         request.clear();
345                         request_bytes_sent = 0;
346                         response.clear();
347                         pending_data.clear();
348                         has_metacube_header = false;
349                         for (size_t i = 0; i < stream_indices.size(); ++i) {
350                                 servers->set_header(stream_indices[i], "", "");
351                         }
352
353                         {
354                                 string protocol, user;  // Thrown away.
355                                 if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
356                                         if (!suppress_logging) {
357                                                 log(WARNING, "[%s] Failed to parse URL '%s'", url.c_str(), url.c_str());
358                                         }
359                                         break;
360                                 }
361
362                                 // Remove the brackets around IPv6 address literals.
363                                 // TODO: See if we can join this with the code in parse_ip_address(),
364                                 // or maybe even more it into parse_url().
365                                 if (!host.empty() && host[0] == '[' && host[host.size() - 1] == ']') {
366                                         host = host.substr(1, host.size() - 2);
367                                 }
368                         }
369
370                         if (suppress_logging) {
371                                 // See if there's more than one minute since last time we made a connection
372                                 // with logging enabled. If so, turn it on again.
373                                 timespec now;
374                                 int err = clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
375                                 assert(err != -1);
376
377                                 double elapsed = now.tv_sec - last_verbose_connection.tv_sec +
378                                         1e-9 * (now.tv_nsec - last_verbose_connection.tv_nsec);
379                                 if (elapsed > 60.0) {
380                                         suppress_logging = false;
381                                 }
382                         }
383                         if (!suppress_logging) {
384                                 int err = clock_gettime(CLOCK_MONOTONIC_COARSE, &last_verbose_connection);
385                                 assert(err != -1);
386                         }
387                         ++num_connection_attempts;
388                         sock = lookup_and_connect(host, port);
389                         if (sock != -1) {
390                                 // Yay, successful connect. Try to set it as nonblocking.
391                                 int one = 1;
392                                 if (ioctl(sock, FIONBIO, &one) == -1) {
393                                         log_perror("ioctl(FIONBIO)");
394                                         state = CLOSING_SOCKET;
395                                 } else {
396                                         state = SENDING_REQUEST;
397                                         request = "GET " + path + " HTTP/1.0\r\nHost: " + host_header(host, port) + "\r\nUser-Agent: cubemap\r\n\r\n";
398                                         request_bytes_sent = 0;
399                                 }
400
401                                 MutexLock lock(&stats_mutex);
402                                 stats.connect_time = time(NULL);
403                                 clock_gettime(CLOCK_MONOTONIC_COARSE, &last_activity);
404                         }
405                         break;
406                 case SENDING_REQUEST: {
407                         size_t to_send = request.size() - request_bytes_sent;
408                         int ret;
409
410                         do {
411                                 ret = write(sock, request.data() + request_bytes_sent, to_send);
412                         } while (ret == -1 && errno == EINTR);
413
414                         if (ret == -1) {
415                                 log_perror("write");
416                                 state = CLOSING_SOCKET;
417                                 continue;
418                         }
419
420                         assert(ret >= 0);
421                         request_bytes_sent += ret;
422
423                         if (request_bytes_sent == request.size()) {
424                                 state = RECEIVING_HEADER;
425                         }
426                         break;
427                 }
428                 case RECEIVING_HEADER: {
429                         char buf[4096];
430                         int ret;
431
432                         do {
433                                 ret = read(sock, buf, sizeof(buf));
434                         } while (ret == -1 && errno == EINTR);
435
436                         if (ret == -1) {
437                                 log_perror("read");
438                                 state = CLOSING_SOCKET;
439                                 continue;
440                         }
441
442                         if (ret == 0) {
443                                 // This really shouldn't happen...
444                                 if (!suppress_logging) {
445                                         log(ERROR, "[%s] Socket unexpectedly closed while reading header",
446                                                    url.c_str());
447                                 }
448                                 state = CLOSING_SOCKET;
449                                 continue;
450                         }
451                         
452                         RequestParseStatus status = wait_for_double_newline(&response, buf, ret);
453                         
454                         if (status == RP_OUT_OF_SPACE) {
455                                 if (!suppress_logging) {
456                                         log(WARNING, "[%s] Server sent overlong HTTP response!", url.c_str());
457                                 }
458                                 state = CLOSING_SOCKET;
459                                 continue;
460                         } else if (status == RP_NOT_FINISHED_YET) {
461                                 continue;
462                         }
463         
464                         // OK, so we're fine, but there might be some of the actual data after the response.
465                         // We'll need to deal with that separately.
466                         string extra_data;
467                         if (status == RP_EXTRA_DATA) {
468                                 char *ptr = static_cast<char *>(
469                                         memmem(response.data(), response.size(), "\r\n\r\n", 4));
470                                 assert(ptr != NULL);
471                                 extra_data = string(ptr + 4, &response[0] + response.size());
472                                 response.resize(ptr - response.data());
473                         }
474
475                         if (!parse_response(response)) {
476                                 state = CLOSING_SOCKET;
477                                 continue;
478                         }
479
480                         if (!extra_data.empty()) {
481                                 process_data(&extra_data[0], extra_data.size());
482                         }
483
484                         if (!suppress_logging) {
485                                 if (encoding == Input::INPUT_ENCODING_RAW) {
486                                         log(INFO, "[%s] Connected to '%s', receiving raw data.",
487                                                    url.c_str(), url.c_str());
488                                 } else {
489                                         assert(encoding == Input::INPUT_ENCODING_METACUBE);
490                                         log(INFO, "[%s] Connected to '%s', receiving data.",
491                                                    url.c_str(), url.c_str());
492                                 }
493                         }
494                         state = RECEIVING_DATA;
495                         break;
496                 }
497                 case RECEIVING_DATA: {
498                         char buf[4096];
499                         int ret;
500
501                         do {
502                                 ret = read(sock, buf, sizeof(buf));
503                         } while (ret == -1 && errno == EINTR);
504
505                         if (ret == -1) {
506                                 log_perror("read");
507                                 state = CLOSING_SOCKET;
508                                 continue;
509                         }
510
511                         if (ret == 0) {
512                                 // This really shouldn't happen...
513                                 if (!suppress_logging) {
514                                         log(ERROR, "[%s] Socket unexpectedly closed while reading data",
515                                                    url.c_str());
516                                 }
517                                 state = CLOSING_SOCKET;
518                                 continue;
519                         }
520
521                         num_connection_attempts = 0;  // Reset, since we have a successful read.
522                         if (suppress_logging) {
523                                 // This was suppressed earlier, so print it out now.
524                                 if (encoding == Input::INPUT_ENCODING_RAW) {
525                                         log(INFO, "[%s] Connected to '%s', receiving raw data.",
526                                                    url.c_str(), url.c_str());
527                                 } else {
528                                         assert(encoding == Input::INPUT_ENCODING_METACUBE);
529                                         log(INFO, "[%s] Connected to '%s', receiving data.",
530                                                    url.c_str(), url.c_str());
531                                 }
532                                 suppress_logging = false;
533                         }
534
535                         process_data(buf, ret);
536                         break;
537                 }
538                 case CLOSING_SOCKET: {
539                         close_socket();
540                         state = NOT_CONNECTED;
541                         break;
542                 }
543                 default:
544                         assert(false);
545                 }
546
547                 // If we are still in NOT_CONNECTED, either something went wrong,
548                 // or the connection just got closed.
549                 // The earlier steps have already given the error message, if any.
550                 if (state == NOT_CONNECTED && !should_stop()) {
551                         if (!suppress_logging) {
552                                 log(INFO, "[%s] Waiting 0.2 seconds and restarting...", url.c_str());
553                         }
554
555                         if (num_connection_attempts >= 3 && !suppress_logging) {
556                                 log(INFO, "[%s] %d failed connection attempts, suppressing logging for one minute.",
557                                         url.c_str(), num_connection_attempts);
558                                 suppress_logging = true;
559                         }
560                         timespec timeout_ts;
561                         timeout_ts.tv_sec = 0;
562                         timeout_ts.tv_nsec = 200000000;
563                         wait_for_wakeup(&timeout_ts);
564                 }
565         }
566 }
567
568 void HTTPInput::process_data(char *ptr, size_t bytes)
569 {
570         {
571                 MutexLock mutex(&stats_mutex);
572                 stats.bytes_received += bytes;
573         }
574
575         if (encoding == Input::INPUT_ENCODING_RAW) {
576                 for (size_t i = 0; i < stream_indices.size(); ++i) {
577                         servers->add_data(stream_indices[i], ptr, bytes, /*metacube_flags=*/0);
578                 }
579                 return;
580         }
581
582         assert(encoding == Input::INPUT_ENCODING_METACUBE);
583         pending_data.insert(pending_data.end(), ptr, ptr + bytes);
584
585         for ( ;; ) {
586                 // If we don't have enough data (yet) for even the Metacube header, just return.
587                 if (pending_data.size() < sizeof(metacube2_block_header)) {
588                         return;
589                 }
590
591                 // Make sure we have the Metacube sync header at the start.
592                 // We may need to skip over junk data (it _should_ not happen, though).
593                 if (!has_metacube_header) {
594                         char *ptr = static_cast<char *>(
595                                 memmem(pending_data.data(), pending_data.size(),
596                                        METACUBE2_SYNC, strlen(METACUBE2_SYNC)));
597                         if (ptr == NULL) {
598                                 // OK, so we didn't find the sync marker. We know then that
599                                 // we do not have the _full_ marker in the buffer, but we
600                                 // could have N-1 bytes. Drop everything before that,
601                                 // and then give up.
602                                 drop_pending_data(pending_data.size() - (strlen(METACUBE2_SYNC) - 1));
603                                 return;
604                         } else {
605                                 // Yay, we found the header. Drop everything (if anything) before it.
606                                 drop_pending_data(ptr - pending_data.data());
607                                 has_metacube_header = true;
608
609                                 // Re-check that we have the entire header; we could have dropped data.
610                                 if (pending_data.size() < sizeof(metacube2_block_header)) {
611                                         return;
612                                 }
613                         }
614                 }
615
616                 // Now it's safe to read the header.
617                 metacube2_block_header hdr;
618                 memcpy(&hdr, pending_data.data(), sizeof(hdr));
619                 assert(memcmp(hdr.sync, METACUBE2_SYNC, sizeof(hdr.sync)) == 0);
620                 uint32_t size = ntohl(hdr.size);
621                 uint16_t flags = ntohs(hdr.flags);
622                 uint16_t expected_csum = metacube2_compute_crc(&hdr);
623
624                 if (expected_csum != ntohs(hdr.csum)) {
625                         log(WARNING, "[%s] Metacube checksum failed (expected 0x%x, got 0x%x), "
626                                 "not reading block claiming to be %d bytes (flags=%x).",
627                                 url.c_str(), expected_csum, ntohs(hdr.csum),
628                                 size, flags);
629
630                         // Drop only the first byte, and let the rest of the code handle resync.
631                         pending_data.erase(pending_data.begin(), pending_data.begin() + 1);
632                         has_metacube_header = false;
633                         continue;
634                 }
635                 if (size > 10485760) {
636                         log(WARNING, "[%s] Metacube block of %d bytes (flags=%x); corrupted header??",
637                                 url.c_str(), size, flags);
638                 }
639
640                 // See if we have the entire block. If not, wait for more data.
641                 if (pending_data.size() < sizeof(metacube2_block_header) + size) {
642                         return;
643                 }
644
645                 // Send this block on to the servers.
646                 {
647                         MutexLock lock(&stats_mutex);
648                         stats.data_bytes_received += size;
649                 }
650                 char *inner_data = pending_data.data() + sizeof(metacube2_block_header);
651                 if (flags & METACUBE_FLAGS_HEADER) {
652                         stream_header = string(inner_data, inner_data + size);
653                         for (size_t i = 0; i < stream_indices.size(); ++i) {
654                                 servers->set_header(stream_indices[i], http_header, stream_header);
655                         }
656                 }
657                 for (size_t i = 0; i < stream_indices.size(); ++i) {
658                         servers->add_data(stream_indices[i], inner_data, size, flags);
659                 }
660
661                 // Consume the block. This isn't the most efficient way of dealing with things
662                 // should we have many blocks, but these routines don't need to be too efficient
663                 // anyway.
664                 pending_data.erase(pending_data.begin(), pending_data.begin() + sizeof(metacube2_block_header) + size);
665                 has_metacube_header = false;
666         }
667 }
668
669 void HTTPInput::drop_pending_data(size_t num_bytes)
670 {
671         if (num_bytes == 0) {
672                 return;
673         }
674         log(WARNING, "[%s] Dropping %lld junk bytes; not a Metacube2 stream, or data was dropped from the middle of the stream.",
675                 url.c_str(), (long long)num_bytes);
676         assert(pending_data.size() >= num_bytes);
677         pending_data.erase(pending_data.begin(), pending_data.begin() + num_bytes);
678 }
679
680 void HTTPInput::add_destination(int stream_index)
681 {
682         stream_indices.push_back(stream_index);
683         servers->set_header(stream_index, http_header, stream_header);
684 }
685
686 InputStats HTTPInput::get_stats() const
687 {
688         MutexLock lock(&stats_mutex);
689         return stats;
690 }