RE: REST API upload requests are processed incorrectly when chunked

Jan Tošovský, modified 1 Year ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts

In HTTP 1.1 a special "Transfer-Encoding: chunked" header enables splitting the request to smaller parts.

When this mode is enabled, Multipart requests used for uploading data via REST API are handled incorrectly.

  1. Create a new KB Article
  2. In IDEA, add Vulcan Impl dependency to any custom module to be able to set a breakpoint, see next step 
    implementation 'com.liferay:com.liferay.portal.vulcan.impl:5.0.68'
  3. In IDEA set a breakpoint inside readFrom() method of the MultipartBodyMessageBodyReader class
  4. Add KB article attachment using REST API with and without checked encoding:

    (for demonstration purposes just key=value form params are passed):

    curl -X POST "http://localhost:8080/o/headless-delivery/v1.0/knowledge-base-articles/84163002/knowledge-base-attachments" -H "Content-Type: multipart/form-data" -F "key=value" -u "test@liferay.com:test"

    curl -X POST "http://localhost:8080/o/headless-delivery/v1.0/knowledge-base-articles/84163002/knowledge-base-attachments" -H "Content-Type: multipart/form-data" -F "key=value" -H "Transfer-Encoding: chunked" -u "test@liferay.com:test"
     
  5. When the breakpoint is hit, inspect the fileItems list returned by this line:
    List<FileItem> fileItems = servletFileUpload.parseRequest( _httpServletRequest);

When chunked encoding is used, the list is empty. It means any passed params are discarded.

In some clients, like standard Java 11 HttpClient, it is not possible to disable that chunked encoding, so this client cannot be used for REST API calls at the moment. 

 

thumbnail
Jamie Sammons, modified 1 Year ago. Expert Posts: 367 Join Date: 9/5/14 Recent Posts

Bug Report Created: https://liferay.atlassian.net/browse/LPS-203472

thumbnail
Jan Tošovský, modified 1 Year ago. Expert Posts: 367 Join Date: 9/5/14 Recent Posts

Hi Jan, this has been fixed and I can confirm it is in 112 which is currently planned to be the basis for the 2024 Q1 release.