Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 18, 2016
2 parents a750b64 + 9fd6c11 commit 3223ab8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/takes/rq/RqMultipart.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ private Request make(final byte[] boundary) throws IOException {
} finally {
channel.close();
}
return new RqLive(
new CapInputStream(
new FileInputStream(file),
file.length()
)
return new RqWithHeader(
new RqLive(
new CapInputStream(
new FileInputStream(file),
file.length()
)
),
"Content-Length",
String.valueOf(file.length())
);
}
/**
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/takes/rq/RqMultipartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.takes.Request;
import org.takes.Response;
import org.takes.Take;
import org.takes.facets.hamcrest.HmRqHeader;
import org.takes.http.FtRemote;
import org.takes.misc.PerformanceTests;
import org.takes.rs.RsText;
Expand Down Expand Up @@ -472,6 +473,40 @@ public void notDistortContent() throws IOException {
temp.delete();
}

/**
* RqMultipart.Base can produce parts with Content-Length.
* @throws IOException If some problem inside
*/
@Test
public void producesPartsWithContentLength() throws IOException {
final RqMultipart.Base multipart = new RqMultipart.Base(
new RqFake(
Arrays.asList(
"POST /h?a=4 HTTP/1.1",
"Host: rtw.example.com",
"Content-Type: multipart/form-data; boundary=AaB01x",
"Content-Length: 100007"
),
Joiner.on("\r\n").join(
"--AaB01x",
"Content-Disposition: form-data; name=\"t2\"",
"",
"447 N Wolfe Rd, Sunnyvale, CA 94085",
"--AaB01x"
)
)
);
MatcherAssert.assertThat(
multipart.part("t2")
.iterator()
.next(),
new HmRqHeader(
"content-length",
"102"
)
);
}

/**
* Format Content-Disposition header.
* @param dsp Disposition
Expand Down

0 comments on commit 3223ab8

Please sign in to comment.