Skip to content

Commit

Permalink
Head should alway be written when we get the stream
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 5, 2017
1 parent 237eaa7 commit 6a56185
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions src/main/java/io/vertx/core/http/impl/HttpClientRequestImpl.java
Expand Up @@ -62,7 +62,6 @@ public class HttpClientRequestImpl extends HttpClientRequestBase implements Http
private Handler<Void> drainHandler;
private Handler<HttpClientRequest> pushHandler;
private Handler<HttpConnection> connectionHandler;
private boolean headWritten;
private boolean completed;
private Handler<Void> completionHandler;
private Long reset;
Expand Down Expand Up @@ -286,12 +285,7 @@ public HttpClientRequest sendHead(Handler<HttpVersion> completionHandler) {
checkComplete();
checkResponseHandler();
if (stream != null) {
if (!headWritten) {
writeHead();
if (completionHandler != null) {
completionHandler.handle(stream.version());
}
}
throw new IllegalStateException("Head already written");
} else {
connect(completionHandler);
}
Expand Down Expand Up @@ -716,31 +710,27 @@ private void connected(HttpClientStream stream, Handler<HttpVersion> headersComp

if (completed) {
// we also need to write the head so optimize this and write all out in once
writeHeadWithContent(pending, true);

stream.writeHeadWithContent(method, rawMethod, uri, headers, hostHeader(), chunked, pending, true);
conn.reportBytesWritten(written);

if (respHandler != null) {
this.stream.endRequest();
}
} else {
writeHeadWithContent(pending, false);
stream.writeHeadWithContent(method, rawMethod, uri, headers, hostHeader(), chunked, pending, false);
if (headersCompletionHandler != null) {
headersCompletionHandler.handle(stream.version());
}
}
} else {
if (completed) {
// we also need to write the head so optimize this and write all out in once
writeHeadWithContent(null, true);

stream.writeHeadWithContent(method, rawMethod, uri, headers, hostHeader(), chunked, null, true);
conn.reportBytesWritten(written);

if (respHandler != null) {
this.stream.endRequest();
}
} else {
writeHead();
stream.writeHead(method, rawMethod, uri, headers, hostHeader(), chunked);
if (headersCompletionHandler != null) {
headersCompletionHandler.handle(stream.version());
}
Expand All @@ -757,17 +747,6 @@ private boolean contentLengthSet() {
return headers != null && headers().contains(CONTENT_LENGTH);
}

private void writeHead() {
stream.writeHead(method, rawMethod, uri, headers, hostHeader(), chunked);
headWritten = true;
}

private void writeHeadWithContent(ByteBuf buf, boolean end) {
stream.writeHeadWithContent(method, rawMethod, uri, headers, hostHeader(), chunked, buf, end);
headWritten = true;
}


@Override
public void end(String chunk) {
end(Buffer.buffer(chunk));
Expand Down Expand Up @@ -860,11 +839,7 @@ private void _write(ByteBuf buff, boolean end) {
}
connect(null);
} else {
if (!headWritten) {
writeHeadWithContent(buff, end);
} else {
stream.writeBuffer(buff, end);
}
stream.writeBuffer(buff, end);
if (end) {
stream.connection().reportBytesWritten(written);
if (respHandler != null) {
Expand Down

0 comments on commit 6a56185

Please sign in to comment.