Skip to content

Commit b380599

Browse files
committed
Incremental fox for AsyncHttpClient#258.
Update logic for basicPutTest. We need to calculate the transfer deltas ourselves as Grizzly only provides the total written.
1 parent 27e0f00 commit b380599

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider {
155155
private final static Logger LOGGER = LoggerFactory.getLogger(GrizzlyAsyncHttpProvider.class);
156156
private static final boolean SEND_FILE_SUPPORT;
157157
static {
158-
SEND_FILE_SUPPORT = /*configSendFileSupport();*/ false;
158+
SEND_FILE_SUPPORT = configSendFileSupport();
159159
}
160160
private final Attribute<HttpTransactionContext> REQUEST_STATE_ATTR =
161161
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(HttpTransactionContext.class.getName());
@@ -398,7 +398,7 @@ public void onTimeout(Connection connection) {
398398
}
399399
fcb.add(eventFilter);
400400
fcb.add(clientFilter);
401-
401+
402402
if (providerConfig != null) {
403403
final TransportCustomizer customizer = (TransportCustomizer)
404404
providerConfig.getProperty(TRANSPORT_CUSTOMIZER);
@@ -433,7 +433,29 @@ void touchConnection(final Connection c, final Request request) {
433433

434434

435435
// --------------------------------------------------------- Private Methods
436-
436+
437+
private static boolean configSendFileSupport() {
438+
439+
return !((System.getProperty("os.name").equalsIgnoreCase("linux")
440+
&& !linuxSendFileSupported())
441+
|| System.getProperty("os.name").equalsIgnoreCase("HP-UX"));
442+
}
443+
444+
445+
private static boolean linuxSendFileSupported() {
446+
final String version = System.getProperty("java.version");
447+
if (version.startsWith("1.6")) {
448+
int idx = version.indexOf('_');
449+
if (idx == -1) {
450+
return false;
451+
}
452+
final int patchRev = Integer.parseInt(version.substring(idx + 1));
453+
return (patchRev >= 18);
454+
} else {
455+
return version.startsWith("1.7") || version.startsWith("1.8");
456+
}
457+
}
458+
437459
private void doDefaultTransportConfig() {
438460
final ExecutorService service = clientConfig.executorService();
439461
if (service != null) {
@@ -515,7 +537,7 @@ boolean sendRequest(final FilterChainContext ctx,
515537
throws IOException {
516538

517539
boolean isWriteComplete = true;
518-
540+
519541
if (requestHasEntityBody(request)) {
520542
final HttpTransactionContext context = getHttpTransactionContext(ctx.getConnection());
521543
BodyHandler handler = bodyHandlerFactory.getBodyHandler(request);
@@ -529,7 +551,7 @@ boolean sendRequest(final FilterChainContext ctx,
529551
ctx.write(requestPacket, ctx.getTransportContext().getCompletionHandler());
530552
}
531553
LOGGER.debug("REQUEST: {}", requestPacket);
532-
554+
533555
return isWriteComplete;
534556
}
535557

@@ -585,7 +607,7 @@ final class HttpTransactionContext {
585607
String lastRedirectURI;
586608
AtomicLong totalBodyWritten = new AtomicLong();
587609
AsyncHandler.STATE currentState;
588-
610+
589611
String wsRequestURI;
590612
boolean isWSRequest;
591613
HandShake handshake;
@@ -883,9 +905,9 @@ private boolean sendAsGrizzlyRequest(final Request request,
883905
}
884906

885907
if (proxy.getPrincipal() != null && proxy.isBasic()) {
886-
requestPacket.setHeader(Header.ProxyAuthorization, AuthenticatorUtils.computeBasicAuthentication(proxy));
908+
requestPacket.setHeader(Header.ProxyAuthorization, AuthenticatorUtils.computeBasicAuthentication(proxy));
887909
}
888-
910+
889911
}
890912
}
891913
final AsyncHandler h = httpCtx.handler;
@@ -909,7 +931,7 @@ private boolean isWSRequest(final String requestUri) {
909931
return (requestUri.charAt(0) == 'w' && requestUri.charAt(1) == 's');
910932
}
911933

912-
934+
913935
private void convertToUpgradeRequest(final HttpTransactionContext ctx) {
914936
final int colonIdx = ctx.requestUrl.indexOf(':');
915937

@@ -1224,7 +1246,7 @@ protected void onHttpHeadersParsed(HttpHeader httpHeader,
12241246
}
12251247
}
12261248
final HttpTransactionContext context = provider.getHttpTransactionContext(ctx.getConnection());
1227-
1249+
12281250
if (httpHeader.isSkipRemainder() || (context.establishingTunnel && context.statusHandler==null)) {
12291251
return;
12301252
}
@@ -2132,7 +2154,7 @@ public boolean doHandle(final FilterChainContext ctx,
21322154
content.setLast(true);
21332155
ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
21342156
}
2135-
2157+
21362158
return true;
21372159
}
21382160

@@ -2197,7 +2219,9 @@ public boolean doHandle(final FilterChainContext ctx,
21972219
final File f = request.getFile();
21982220
requestPacket.setContentLengthLong(f.length());
21992221
final HttpTransactionContext context = getHttpTransactionContext(ctx.getConnection());
2200-
if (!SEND_FILE_SUPPORT || requestPacket.isSecure()) {
2222+
if (!SEND_FILE_SUPPORT
2223+
|| requestPacket.isSecure()) {
2224+
//|| requestPacket.getHeaders().contains(Header.TransferEncoding)) {
22012225
final FileInputStream fis = new FileInputStream(request.getFile());
22022226
final MemoryManager mm = ctx.getMemoryManager();
22032227
AtomicInteger written = new AtomicInteger();
@@ -2236,7 +2260,10 @@ public void updated(WriteResult result) {
22362260
final AsyncHandler handler = context.handler;
22372261
if (handler != null) {
22382262
if (TransferCompletionHandler.class.isAssignableFrom(handler.getClass())) {
2239-
final long written = result.getWrittenSize();
2263+
// WriteResult keeps a track of the total amount written,
2264+
// so we need to calculate the delta ourselves.
2265+
final long resultTotal = result.getWrittenSize();
2266+
final long written = resultTotal - context.totalBodyWritten.get();
22402267
final long total = context.totalBodyWritten.addAndGet(written);
22412268
((TransferCompletionHandler) handler).onContentWriteProgress(
22422269
written,

0 commit comments

Comments
 (0)