简体   繁体   中英

White-space issue between multipart/form-data; & boundary in Content-Type Header

I've developed Spring boot(v1.5.2) rest api and using spring-boot-starter-undertow embedded server to run the application. One of the operation has upload file feature (method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE).

The application is working fine as expected when testing with postman with auto-generated headers like Content-Type, Content-Length, etc..

But the issue is, client/consumer app is sending the Content-Type as multipart/form-dat a;b oundary=----xyz---- (without space between multipart/form-data; & boundary) and the request is failing with 400 Bad request and it's not reaching the controller.

But the auto-generated postman header has white-space. (multipart/form-dat a; b oundary=----xyz---) which is working fine and when we override this header to have that whitespace then it's not working in postman too. So the issue is with the pattern of the Content-Type.

Few things I tried are, I added Filters and override the HttpServletRequestWrapper to modify the content-type header before the request reach the controller but the solution is not working. I tried AOP as well but there are not setHeader method to set/update request headers.

Could you please share your experiences or ideas on how to handle this scenario in server application(producer) without touching the consumer application.

I still couldn't figure out the issue/root-cause with undertow, but when I changed the embedded server to spring-boot-starter-jetty then my requests with/without white space between multipart/form-data; & boundary in content-type is working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM