Skip to content

Commit

Permalink
Merge pull request #1101 from amvanbaren/bugfix/streaming-response-body
Browse files Browse the repository at this point in the history
Create new StreamingResponseBody
  • Loading branch information
amvanbaren authored Feb 4, 2025
2 parents 45a1471 + 41296d3 commit 90cbad1
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public class LocalVSCodeService implements IVSCodeService {
private final WebResourceService webResources;
private final CacheService cache;

private final StreamingResponseBody builtinExtensionResponse = outputStream -> {
var message = "Built-in extension namespace '" + BuiltInExtensionUtil.getBuiltInNamespace() + "' not allowed";
outputStream.write(message.getBytes(StandardCharsets.UTF_8));
};

@Value("${ovsx.webui.url:}")
String webuiUrl;

Expand Down Expand Up @@ -284,7 +279,7 @@ public ResponseEntity<StreamingResponseBody> getAsset(
String restOfTheUrl
) {
if(BuiltInExtensionUtil.isBuiltIn(namespace)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(builtinExtensionResponse);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(builtinExtensionResponse());
}

var asset = (restOfTheUrl != null && !restOfTheUrl.isEmpty()) ? (assetType + "/" + restOfTheUrl) : assetType;
Expand Down Expand Up @@ -352,6 +347,10 @@ private String builtinExtensionMessage() {
return "Built-in extension namespace '" + BuiltInExtensionUtil.getBuiltInNamespace() + "' not allowed";
}

private StreamingResponseBody builtinExtensionResponse() {
return (out) -> out.write(builtinExtensionMessage().getBytes(StandardCharsets.UTF_8));
}

@Override
public String getItemUrl(String namespaceName, String extensionName) {
if(BuiltInExtensionUtil.isBuiltIn(namespaceName)) {
Expand Down Expand Up @@ -396,7 +395,7 @@ public String download(String namespaceName, String extensionName, String versio
@Override
public ResponseEntity<StreamingResponseBody> browse(String namespaceName, String extensionName, String version, String path) {
if(BuiltInExtensionUtil.isBuiltIn(namespaceName)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(builtinExtensionResponse);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(builtinExtensionResponse());
}

var file = getWebResource(namespaceName, extensionName, null, version, path, true);
Expand Down

0 comments on commit 90cbad1

Please sign in to comment.