Skip to content

Commit

Permalink
TACO-131 addressing pr feedback - fixing typos (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
manimaul authored Apr 16, 2018
1 parent 42c9932 commit 3fbf304
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

/**
* A finite state machine to track the current HTTP/2 message session. This class exists to store
* the connection specific state of the message session
* the connection specific state of the message session per connection stream id.
*/
@Slf4j
public class Http2MessageSession {

private static final AttributeKey<Http2MessageSession> CHANNEL_MESSAGE_SESSION_KEY =
AttributeKey.newInstance("xio_channel_h2_message_session");

static Http2MessageSession contextMessageSession(ChannelHandlerContext ctx) {
static Http2MessageSession lazyCreateSession(ChannelHandlerContext ctx) {
Http2MessageSession session = ctx.channel().attr(CHANNEL_MESSAGE_SESSION_KEY).get();
if (session == null) {
session = new Http2MessageSession();
Expand All @@ -38,7 +38,9 @@ public void onRequest(Request request) {
streamIdRequests.put(
request.streamId(), new MessageMetaState(request, request.endOfMessage()));
} else {
log.error("Received an h2 message segment without a startOfMessage - request: {}", request);
log.error(
"Received an h2 message segment without initial startOfMessage == true - request: {}",
request);
}
} else {
initialRequest.requestFinished = request.endOfMessage();
Expand Down Expand Up @@ -99,8 +101,8 @@ public Request currentRequest(int streamId) {
}

/**
* Check if the message session has completed, if so remove state and prepare for the next
* session.
* Check if the message session has completed for a given streamId, if so remove the message
* state.
*/
public void flush(int streamId) {
MessageMetaState initialRequest = streamIdRequests.get(streamId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.xjeffrose.xio.http;

import static com.xjeffrose.xio.http.Http2MessageSession.contextMessageSession;
import static com.xjeffrose.xio.http.Http2MessageSession.lazyCreateSession;

import com.xjeffrose.xio.core.internal.UnstableApi;
import com.xjeffrose.xio.http.internal.FullHttp2Request;
Expand Down Expand Up @@ -28,7 +28,7 @@ Request wrapHeaders(Http2Headers headers, int streamId, boolean eos) {
}

Request wrapRequest(ChannelHandlerContext ctx, Http2Request msg) {
Http2MessageSession messageSession = contextMessageSession(ctx);
Http2MessageSession messageSession = lazyCreateSession(ctx);
if (msg.payload instanceof Http2Headers) {
Http2Headers headers = (Http2Headers) msg.payload;
if (msg.eos && headers.method() == null && headers.status() == null) {
Expand Down Expand Up @@ -75,7 +75,7 @@ void writeResponse(ChannelHandlerContext ctx, Response response, ChannelPromise
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
}

Http2MessageSession messageSession = contextMessageSession(ctx);
Http2MessageSession messageSession = lazyCreateSession(ctx);
int streamId = response.streamId();
Http2Headers headers = response.headers().http2Headers();

Expand All @@ -101,7 +101,7 @@ void writeResponse(ChannelHandlerContext ctx, Response response, ChannelPromise
}

void writeContent(ChannelHandlerContext ctx, SegmentedData data, ChannelPromise promise) {
Http2MessageSession messageSession = contextMessageSession(ctx);
Http2MessageSession messageSession = lazyCreateSession(ctx);
messageSession.onResponseData(data);

boolean dataEos = data.endOfMessage() && data.trailingHeaders().size() == 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ public void testInterleavedStreamingMessages() throws Exception {
// given an h2 request
Http2Request requestInitial1 =
Http2Request.build(streamIdOne, new DefaultHttp2Headers().method("GET").path("/"), false);
Http2Request requestSubsequential1 =
Http2Request requestSubSequential1 =
Http2Request.build(streamIdOne, new DefaultHttp2DataFrame(Unpooled.EMPTY_BUFFER), true);

// given another h2 request
Http2Request requestInitial2 =
Http2Request.build(streamIdTwo, new DefaultHttp2Headers().method("POST").path("/"), false);
Http2Request requestSubsequential2 =
Http2Request requestSubSequential2 =
Http2Request.build(streamIdTwo, new DefaultHttp2DataFrame(Unpooled.EMPTY_BUFFER), true);

// given an h2 response
Expand All @@ -379,16 +379,16 @@ public void testInterleavedStreamingMessages() throws Exception {
// when the 2 requests are interleaved
channel.writeInbound(requestInitial1);
channel.writeInbound(requestInitial2);
channel.writeInbound(requestSubsequential1);
channel.writeInbound(requestSubsequential2);
channel.writeInbound(requestSubSequential1);
channel.writeInbound(requestSubSequential2);
channel.runPendingTasks(); // blocks

// and responses are interleaved
channel.runPendingTasks(); // blocks
channel.writeOutbound(responseInitial1);
channel.writeOutbound(responseInitial2);
channel.writeOutbound(responseSubSequential1);
channel.writeOutbound(responseSubSequential2);
channel.runPendingTasks(); // blocks

// then the first stream id responses should be correct
{
Expand Down

0 comments on commit 3fbf304

Please sign in to comment.