Added download speed-test endpoint

This commit is contained in:
Max W. 2024-02-06 23:38:23 +01:00
parent e3f14801e9
commit cd19477153
2 changed files with 34 additions and 1 deletions

View File

@ -5,7 +5,7 @@ plugins {
}
group = 'de.w665'
version = '0.0.1'
version = '0.0.2'
java {
sourceCompatibility = '21'

View File

@ -0,0 +1,33 @@
package de.w665.sharepulse.rest.mappings;
import de.w665.sharepulse.rest.ApiRestController;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
@Slf4j
@RestController
public class SpeedTest extends ApiRestController {
/**
* This method is used to test the download speed of the client. 1MB of dummy data is sent to the client.
* @param response
*/
@GetMapping("/speed-test")
public void speedTest(HttpServletResponse response) {
byte[] dummyData = new byte[1024 * 1024];
response.setContentType("application/octet-stream");
response.setContentLength(dummyData.length);
response.setStatus(HttpServletResponse.SC_OK);
try {
response.getOutputStream().write(dummyData);
response.getOutputStream().flush();
} catch (IOException e) {
log.error("Speed test failed.");
return;
}
}
}