Avoid file extension detection in Spring MVC request mapping with floating point number in URI

前端 未结 3 879
时光取名叫无心
时光取名叫无心 2021-01-15 13:07

I used Spring Boot to implement a REST application. I have one resource that is mapped like this

@RequestMapping(value = \"/{fromLat}/{fromLon}/{toLat}/{toL         


        
相关标签:
3条回答
  • 2021-01-15 13:47

    I had similar issues with Spring Boot as described here.

    What worked for me is the following configuration:

    @Configuration
    public class WebMvcConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.setUseSuffixPatternMatch(false);
    
        }
    
    
    }
    
    0 讨论(0)
  • 2021-01-15 13:48

    In Spring Framework 4.1.9 and 4.2.3 the Content-Disposition header was fixed to use the "inline" type which only suggests a file download name, should the content end up being downloaded. It won't force a Save As dialog any more.

    Note also that the reason for the Content-Disposition header in the first place is to protect applications against RFD attacks. This is a very complex issue but you can see a summary in the CVE-2015-5211 report.

    0 讨论(0)
  • 2021-01-15 13:52

    Did you try to set:

    1) Content-Disposition: inline; -> you can use:

    return new ResponseEntity(body, headers, statusCode); and set Content-Disposition in headers. Look here: How to set 'Content-Disposition' and 'Filename' when using FileSystemResource to force a file download file? and Return a stream with Spring MVC's ResponseEntity

    2) text/x-json - Experimental MIME type for JSON before application/json got officially registered.

    @RequestMapping(value = "/{fromLat}/{fromLon}/{toLat}/{toLon:.+}", method = {RequestMethod.GET},
                    produces = {"text/x-json"})
    

    It will try to display the content instead of downloading it.

    Hope it will help.

    0 讨论(0)
提交回复
热议问题