File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed
app/src/main/java/hexlet/code/controller Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,25 @@ public static void check(Context ctx) throws SQLException {
2727 .asString ();
2828
2929 int statusCode = response .getStatus ();
30+ String body = response .getBody ();
31+
32+ if (statusCode >= 300 && statusCode < 400 ) {
33+ String redirectUrl = response .getHeaders ().getFirst ("Location" );
34+ if (redirectUrl != null && !redirectUrl .isEmpty ()) {
35+ response = Unirest .get (redirectUrl )
36+ .header ("User-Agent" , "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" )
37+ .asString ();
38+ statusCode = response .getStatus ();
39+ body = response .getBody ();
40+ }
41+ }
42+
3043 String h1 = "" ;
3144 String title = "" ;
3245 String description = "" ;
3346
34- if (statusCode == 200 ) {
35- var doc = Jsoup .parse (response . getBody () );
47+ if (body != null && ! body . isEmpty () ) {
48+ var doc = Jsoup .parse (body );
3649 var h1El = doc .selectFirst ("h1" );
3750 var descEl = doc .selectFirst ("meta[name~=(?i)description]" );
3851
You can’t perform that action at this time.
0 commit comments