You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "Sayaka617 (via GitHub)" <gi...@apache.org> on 2023/07/05 07:56:30 UTC
[GitHub] [servicecomb-java-chassis] Sayaka617 opened a new issue, #3850: 通过ResponseEntity设置的Content-Type不生效
Sayaka617 opened a new issue, #3850:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3850
在接口返回值中设置responseEntity的content-type为image/png,但是请求接口时得到的content-type仍为application/octet-stream,导致浏览器无法直接呈现。
接口代码如下
```java
@GetMapping("/{mapId}/wms")
@ApiResponses(@ApiResponse(code = 200, response = File.class, message = ""))
public ResponseEntity<ByteArrayResource> wmsExport(WmsRenderRequest wmsRenderRequest,
@PathVariable("mapId") String mapId) {
ByteArrayResource byteArrayResource = new ByteArrayResource(
wmsMapRenderBusiness.getWmsMap(wmsRenderRequest, mapId));
return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE).body(byteArrayResource);
}
```
响应值header如下
```json
{connection=keep-alive, content-disposition=attachment;filename=;filename*=utf-8'', content-type=application/octet-stream, date=Wed, 05 Jul 2023 06:43:07 GMT, keep-alive=timeout=60, transfer-encoding=chunked;chunked}
```

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-java-chassis] Sayaka617 commented on issue #3850: 通过ResponseEntity设置的Content-Type不生效
Posted by "Sayaka617 (via GitHub)" <gi...@apache.org>.
Sayaka617 commented on issue #3850:
URL: https://github.com/apache/servicecomb-java-chassis/issues/3850#issuecomment-1622890525
经过分析,参考org.apache.catalina.connector.Response#setContentType
最终实际调用方法为
```java
public void setContentTypeNoCharset(String type) {
this.contentType = type;
}
```
在设置content-type时进行了特殊处理,并不会添加至header,而是设置this.contentType=contentType;
因此在org.apache.servicecomb.foundation.vertx.http.DownloadUtils#prepareDownloadHeader中获取时,应当尝试使用get方法,我将验证后提出PR修复此问题
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [servicecomb-java-chassis] Sayaka617 closed issue #3850: 通过ResponseEntity设置的Content-Type不生效
Posted by "Sayaka617 (via GitHub)" <gi...@apache.org>.
Sayaka617 closed issue #3850: 通过ResponseEntity设置的Content-Type不生效
URL: https://github.com/apache/servicecomb-java-chassis/issues/3850
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org