mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-16 16:50:42 +08:00
Add Content-Disposition to all endpoints
Prior to this commit, the browser was "guessing" the file name to use for Maven and Gradle build files. This commit harmonizes the endpoints so that they provide a Content-Disposition header with a preferred file name.
This commit is contained in:
parent
8f1ce31035
commit
09f91aa53b
@ -81,14 +81,14 @@ class MainController extends AbstractInitializrController {
|
||||
@ResponseBody
|
||||
ResponseEntity<byte[]> pom(ProjectRequest request) {
|
||||
def mavenPom = projectGenerator.generateMavenPom(request)
|
||||
new ResponseEntity<byte[]>(mavenPom, ['Content-Type': 'application/octet-stream'] as HttpHeaders, HttpStatus.OK)
|
||||
createResponseEntity(mavenPom, 'application/octet-stream', 'pom.xml')
|
||||
}
|
||||
|
||||
@RequestMapping('/build')
|
||||
@ResponseBody
|
||||
ResponseEntity<byte[]> gradle(ProjectRequest request) {
|
||||
def gradleBuild = projectGenerator.generateGradleBuild(request)
|
||||
new ResponseEntity<byte[]>(gradleBuild, ['Content-Type': 'application/octet-stream'] as HttpHeaders, HttpStatus.OK)
|
||||
createResponseEntity(gradleBuild, 'application/octet-stream', 'build.gradle')
|
||||
}
|
||||
|
||||
@RequestMapping('/starter.zip')
|
||||
@ -124,12 +124,17 @@ class MainController extends AbstractInitializrController {
|
||||
|
||||
private ResponseEntity<byte[]> upload(File download, File dir, String fileName, String contentType) {
|
||||
log.info("Uploading: ${download} (${download.bytes.length} bytes)")
|
||||
String contentDispositionValue = "attachment; filename=\"$fileName\""
|
||||
def result = new ResponseEntity<byte[]>(download.bytes,
|
||||
['Content-Type': contentType,
|
||||
'Content-Disposition': contentDispositionValue] as HttpHeaders, HttpStatus.OK)
|
||||
ResponseEntity<byte[]> result = createResponseEntity(download.bytes, contentType, fileName)
|
||||
projectGenerator.cleanTempFiles(dir)
|
||||
result
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> createResponseEntity(byte[] content, String contentType, String fileName) {
|
||||
String contentDispositionValue = "attachment; filename=\"$fileName\""
|
||||
def result = new ResponseEntity<byte[]>(content,
|
||||
['Content-Type' : contentType,
|
||||
'Content-Disposition': contentDispositionValue] as HttpHeaders, HttpStatus.OK)
|
||||
result
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user