Line 0
Link Here
|
|
|
1 |
--- plugins/check_http.c.orig 2020-02-20 19:14:52 UTC |
2 |
+++ plugins/check_http.c |
3 |
@@ -608,11 +608,9 @@ enable_ssl: |
4 |
|
5 |
|
6 |
|
7 |
-/* Returns 0 if we're still retrieving the headers. |
8 |
- * Otherwise, returns the length of the header (not including the final newlines) |
9 |
- */ |
10 |
+/* Returns 1 if we're done processing the document body; 0 to keep going */ |
11 |
static int |
12 |
-document_headers_done (const char *full_page) |
13 |
+document_headers_done (char *full_page) |
14 |
{ |
15 |
const char *body; |
16 |
|
17 |
@@ -624,7 +622,8 @@ document_headers_done (const char *full_ |
18 |
if (!*body) |
19 |
return 0; /* haven't read end of headers yet */ |
20 |
|
21 |
- return body - full_page; |
22 |
+ full_page[body - full_page] = 0; |
23 |
+ return 1; |
24 |
} |
25 |
|
26 |
static time_t |
27 |
@@ -1014,10 +1013,6 @@ check_http (void) |
28 |
char *page; |
29 |
char *auth; |
30 |
int http_status; |
31 |
- int header_end; |
32 |
- int content_length; |
33 |
- int content_start; |
34 |
- int seen_length; |
35 |
int i = 0; |
36 |
size_t pagesize = 0; |
37 |
char *full_page; |
38 |
@@ -1200,40 +1195,11 @@ check_http (void) |
39 |
full_page = full_page_new; |
40 |
pagesize += i; |
41 |
|
42 |
- header_end = document_headers_done(full_page); |
43 |
- if (header_end) { |
44 |
+ if (no_body && document_headers_done (full_page)) { |
45 |
i = 0; |
46 |
break; |
47 |
} |
48 |
} |
49 |
- |
50 |
- if (no_body) { |
51 |
- full_page[header_end] = '\0'; |
52 |
- } |
53 |
- else { |
54 |
- content_length = get_content_length(full_page); |
55 |
- |
56 |
- content_start = header_end + 1; |
57 |
- while (full_page[content_start] == '\n' || full_page[content_start] == '\r') { |
58 |
- content_start += 1; |
59 |
- } |
60 |
- seen_length = pagesize - content_start; |
61 |
- /* Continue receiving the body until content-length is met */ |
62 |
- while (seen_length < content_length |
63 |
- && (i = my_recv(buffer, MAX_INPUT_BUFFER-1) > 0)) { |
64 |
- |
65 |
- buffer[i] = '\0'; |
66 |
- |
67 |
- if ((full_page_new = realloc(full_page, pagesize + i + 1)) == NULL) |
68 |
- die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate memory for full_page\n")); |
69 |
- memmove(&full_page_new[pagesize], buffer, i); |
70 |
- full_page = full_page_new; |
71 |
- |
72 |
- pagesize += i; |
73 |
- seen_length = pagesize - content_start; |
74 |
- } |
75 |
- } |
76 |
- |
77 |
microsec_transfer = deltime (tv_temp); |
78 |
elapsed_time_transfer = (double)microsec_transfer / 1.0e6; |
79 |
|