-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support Symfony profiler using gzip files and provide mailer collecto…
…r inside statusbar
- Loading branch information
Showing
12 changed files
with
199 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,36 +5,5 @@ | |
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
*/ | ||
public class MailMessage { | ||
|
||
@NotNull | ||
private final String message; | ||
|
||
@NotNull | ||
private final String title; | ||
|
||
@NotNull | ||
private final String format; | ||
|
||
public MailMessage(@NotNull String message, @NotNull String title, @NotNull String format) { | ||
this.message = message; | ||
this.title = title; | ||
this.format = format; | ||
} | ||
|
||
@NotNull | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
@NotNull | ||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
@NotNull | ||
public String getFormat() { | ||
return format; | ||
} | ||
|
||
public record MailMessage(@NotNull String message, @NotNull String title, @NotNull String format, @NotNull String panel) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,7 @@ | |
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.*; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
|
@@ -31,6 +29,7 @@ | |
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.zip.GZIPInputStream; | ||
|
||
/** | ||
* @author Daniel Espendiller <[email protected]> | ||
|
@@ -424,11 +423,18 @@ public static List<ProfilerRequestInterface> getProfilerRequestCollectorDecorate | |
* https://127.0.0.1:8000/app_dev.php | ||
*/ | ||
@Nullable | ||
public static String getBaseProfilerUrlFromRequest(@NotNull String requestUrl) { | ||
URL url; | ||
public static String getBaseProfilerUrlFromRequest(@NotNull ProfilerRequestInterface request) { | ||
URL url = null; | ||
try { | ||
url = new URL(requestUrl); | ||
url = new URL(request.getProfilerUrl()); | ||
} catch (MalformedURLException e) { | ||
try { | ||
url = new URL(request.getUrl()); | ||
} catch (MalformedURLException ignored) { | ||
} | ||
} | ||
|
||
if (url == null) { | ||
return null; | ||
} | ||
|
||
|
@@ -468,5 +474,70 @@ public static String formatProfilerRow(@NotNull ProfilerRequestInterface profile | |
|
||
return String.format("(%s) %s", statusCode == 0 ? "n/a" : statusCode, StringUtils.abbreviate(path, 35)); | ||
} | ||
|
||
public static String getContentForFile(@NotNull File file) { | ||
boolean isGzipFile; | ||
|
||
try { | ||
byte[] buffer = new byte[3]; | ||
|
||
InputStream is = new FileInputStream(file); | ||
int __ = is.read(buffer); | ||
|
||
// check gzip header | ||
isGzipFile = buffer[0] == 31 | ||
&& buffer[1] == -117 | ||
&& buffer[2] == 8; | ||
|
||
is.close(); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
|
||
if (isGzipFile) { | ||
return getProfilerContentGzdecode(file); | ||
} | ||
|
||
return getContentForRaw(file); | ||
} | ||
|
||
@Nullable | ||
private static String getContentForRaw(@NotNull File file) { | ||
StringBuilder content = new StringBuilder(); | ||
|
||
try { | ||
BufferedReader in = new BufferedReader(new FileReader(file)); | ||
String str; | ||
while ((str = in.readLine()) != null) { | ||
content.append(str); | ||
} | ||
in.close(); | ||
} catch (IOException ignored) { | ||
return null; | ||
} | ||
|
||
return content.toString(); | ||
} | ||
|
||
@Nullable | ||
private static String getProfilerContentGzdecode(File file) { | ||
try { | ||
InputStream in = new FileInputStream(file.getPath()); | ||
|
||
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(in.readAllBytes())); | ||
BufferedReader bf = new BufferedReader(new InputStreamReader(gis)); | ||
StringBuilder outStr = new StringBuilder(); | ||
|
||
String line; | ||
while ((line=bf.readLine())!=null) { | ||
outStr.append(line); | ||
} | ||
|
||
return outStr.toString(); | ||
} catch (IOException ignored) { | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.