Skip to content

Commit

Permalink
Merge pull request #9287 from eclipse/jetty-12.0.x-multipartCleanups
Browse files Browse the repository at this point in the history
Issue #9076 - Cleanups and fixes for multipart in Jetty 12
  • Loading branch information
lachlan-roberts authored Feb 9, 2023
2 parents 3ed9302 + 820fbb7 commit 3259a55
Show file tree
Hide file tree
Showing 44 changed files with 1,050 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.jetty.client.Response.Listener;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StaticException;
import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -301,7 +302,7 @@ public int read(byte[] b, int offset, int length) throws IOException
break;

if (failure != null)
throw toIOException(failure);
throw new IOException(failure);

if (closed)
throw new AsynchronousCloseException();
Expand All @@ -327,14 +328,6 @@ public int read(byte[] b, int offset, int length) throws IOException
}
}

private IOException toIOException(Throwable failure)
{
if (failure instanceof IOException)
return (IOException)failure;
else
return new IOException(failure);
}

@Override
public void close() throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected HttpFields customizePartHeaders(MultiPart.Part part)
if (headers.contains(HttpHeader.CONTENT_TYPE))
return headers;

Content.Source partContent = part.getContent();
Content.Source partContent = part.getContentSource();
if (partContent instanceof Request.Content requestContent)
{
String contentType = requestContent.getContentType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void process(MultiPartFormData.Parts parts) throws Exception
int equal = contentType.lastIndexOf('=');
Charset charset = Charset.forName(contentType.substring(equal + 1));
assertEquals(encoding, charset);
assertEquals(value, Content.Source.asString(part.getContent(), charset));
assertEquals(value, Content.Source.asString(part.getContentSource(), charset));
}
});

Expand Down Expand Up @@ -169,7 +169,7 @@ protected void process(MultiPartFormData.Parts parts) throws Exception
MultiPart.Part part = parts.iterator().next();
assertEquals(name, part.getName());
assertEquals("text/plain", part.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertArrayEquals(data, Content.Source.asByteBuffer(part.getContent()).array());
assertArrayEquals(data, Content.Source.asByteBuffer(part.getContentSource()).array());
}
});

Expand Down Expand Up @@ -221,8 +221,8 @@ protected void process(MultiPartFormData.Parts parts) throws Exception
assertEquals(name, part.getName());
assertEquals(contentType, part.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertEquals(fileName, part.getFileName());
assertEquals(data.length, part.getContent().getLength());
assertArrayEquals(data, Content.Source.asByteBuffer(part.getContent()).array());
assertEquals(data.length, part.getContentSource().getLength());
assertArrayEquals(data, Content.Source.asByteBuffer(part.getContentSource()).array());
}
});

Expand Down Expand Up @@ -277,8 +277,8 @@ protected void process(MultiPartFormData.Parts parts) throws Exception
assertEquals(name, part.getName());
assertEquals(contentType, part.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertEquals(tmpPath.getFileName().toString(), part.getFileName());
assertEquals(Files.size(tmpPath), part.getContent().getLength());
assertEquals(data, Content.Source.asString(part.getContent(), encoding));
assertEquals(Files.size(tmpPath), part.getContentSource().getLength());
assertEquals(data, Content.Source.asString(part.getContentSource(), encoding));
}
});

Expand Down Expand Up @@ -329,14 +329,14 @@ protected void process(MultiPartFormData.Parts parts) throws Exception

assertEquals(field, fieldPart.getName());
assertEquals(contentType, fieldPart.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertEquals(value, Content.Source.asString(fieldPart.getContent(), encoding));
assertEquals(value, Content.Source.asString(fieldPart.getContentSource(), encoding));
assertEquals(headerValue, fieldPart.getHeaders().get(headerName));

assertEquals(fileField, filePart.getName());
assertEquals("application/octet-stream", filePart.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertEquals(tmpPath.getFileName().toString(), filePart.getFileName());
assertEquals(Files.size(tmpPath), filePart.getContent().getLength());
assertArrayEquals(data, Content.Source.asByteBuffer(filePart.getContent()).array());
assertEquals(Files.size(tmpPath), filePart.getContentSource().getLength());
assertArrayEquals(data, Content.Source.asByteBuffer(filePart.getContentSource()).array());
}
});

Expand Down Expand Up @@ -373,11 +373,11 @@ protected void process(MultiPartFormData.Parts parts) throws Exception
MultiPart.Part fieldPart = parts.get(0);
MultiPart.Part filePart = parts.get(1);

assertEquals(value, Content.Source.asString(fieldPart.getContent(), encoding));
assertEquals(value, Content.Source.asString(fieldPart.getContentSource(), encoding));
assertEquals("file", filePart.getName());
assertEquals("application/octet-stream", filePart.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertEquals("fileName", filePart.getFileName());
assertArrayEquals(fileData, Content.Source.asByteBuffer(filePart.getContent()).array());
assertArrayEquals(fileData, Content.Source.asByteBuffer(filePart.getContentSource()).array());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ public boolean isCommitted()
return _committed;
}

@Override
public Throwable consumeAvailable()
{
return HttpStream.consumeAvailable(this, _httpChannel.getConnectionMetaData().getHttpConfiguration());
}

@Override
public void succeeded()
{
Expand Down
Loading

0 comments on commit 3259a55

Please sign in to comment.