@@ -7,7 +7,7 @@ use regex::Regex;
7
7
use super :: Banner ;
8
8
9
9
// TODO: read from args
10
- static HTTP_HEADERS_OF_INTEREST : & [ & str ] = & [ "server" , "x-powered-by" , "location" ] ;
10
+ static HTTP_HEADERS_OF_INTEREST : & [ & str ] = & [ "server" , "x-powered-by" , "location" , "content-type" ] ;
11
11
12
12
lazy_static ! {
13
13
static ref HTML_TITLE_PARSER : Regex =
@@ -85,19 +85,33 @@ pub(crate) async fn http_grabber(
85
85
if let Ok ( resp) = resp {
86
86
// TODO: find a way to collect certificate information if ssl
87
87
88
+ let mut content_type = String :: from ( "text/html" ) ;
89
+
88
90
// collect headers
89
91
for ( name, value) in resp. headers ( ) {
90
92
let name = name. to_string ( ) ;
93
+ let value = value. to_str ( ) . unwrap ( ) ;
94
+
95
+ if name == "content-type" {
96
+ content_type = value. to_owned ( ) ;
97
+ }
91
98
if HTTP_HEADERS_OF_INTEREST . contains ( & name. as_str ( ) ) {
92
- banner. insert ( name, value. to_str ( ) . unwrap ( ) . to_owned ( ) ) ;
99
+ banner. insert ( name, value. to_owned ( ) ) ;
93
100
}
94
101
}
95
102
96
103
// collect info from html
97
104
let body = resp. text ( ) . await ;
98
105
if let Ok ( body) = body {
99
- if let Some ( caps) = HTML_TITLE_PARSER . captures ( & body) {
100
- banner. insert ( "title" . to_owned ( ) , caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_owned ( ) ) ;
106
+ if content_type == "text/html" {
107
+ if let Some ( caps) = HTML_TITLE_PARSER . captures ( & body) {
108
+ banner. insert (
109
+ "html.title" . to_owned ( ) ,
110
+ caps. get ( 1 ) . unwrap ( ) . as_str ( ) . to_owned ( ) ,
111
+ ) ;
112
+ }
113
+ } else if content_type == "application/json" {
114
+ banner. insert ( "body" . to_owned ( ) , body. to_owned ( ) ) ;
101
115
}
102
116
} else {
103
117
log:: error!(
0 commit comments