Skip to content

Commit a0f9982

Browse files
committed
feat: update code
1 parent a7063fe commit a0f9982

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

base/src/main/java/com/tinyengine/it/mcp/tools/GitFileReaderService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,16 @@ public static byte[] fetchBytes(String urlString) throws IOException {
174174
URL url = new URL(urlString);
175175
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
176176
connection.setRequestMethod("GET");
177+
connection.setInstanceFollowRedirects(false);
177178
connection.setConnectTimeout(CONNECT_TIMEOUT);
178179
connection.setReadTimeout(READ_TIMEOUT);
179180
connection.setRequestProperty("User-Agent", "Java-URL-Client");
180181

181182
try {
182183
int responseCode = connection.getResponseCode();
184+
if (responseCode >= 300 && responseCode < 400) {
185+
throw new IOException("Redirect responses are not allowed");
186+
}
183187
if (responseCode != HttpURLConnection.HTTP_OK) {
184188
throw new IOException("HTTP response code: " + responseCode);
185189
}

0 commit comments

Comments
 (0)