Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public boolean isEarlyTerminated() {
}

public String toString() {
return "DeafultIcapChunk: [isPreviewChunk=" + preview + "] [wasEarlyTerminated=" + earlyTerminated + "] [data=" + getContent().readableBytes() + "]";
return "DefaultIcapChunk: [isPreviewChunk=" + preview + "] [wasEarlyTerminated=" + earlyTerminated + "] [data=" + getContent().readableBytes() + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public boolean isEarlyTerminated() {
}

public String toString() {
return "DeafultIcapChunkTrailer: [isPreviewChunk=" + preview + "] [wasEarlyTerminated=" + earlyTerminated + "]";
return "DefaultIcapChunkTrailer: [isPreviewChunk=" + preview + "] [wasEarlyTerminated=" + earlyTerminated + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
ctx.sendUpstream(e);
} else {
IcapChunkTrailer trailer = (IcapChunkTrailer)msg;
if (trailer.isEarlyTerminated()) {
LOG.debug("chunk trailer is early terminated, removing PREVIEW header");
message.getIcapMessage().removeHeader(IcapHeaders.Names.PREVIEW);
}
if(trailer.getHeaderNames().size() > 0) {
for(String name : trailer.getHeaderNames()) {
message.addHeader(name,trailer.getHeader(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ public void removeHeader(String name) {
after.before = before;
entry = after;
} else {
if (head == entry) {
head = entry.before;
}
entry = null;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public StateReturnValue execute(ChannelBuffer buffer, IcapMessageDecoder icapMes
}
if(isOptionsRequest) {
return StateReturnValue.createRelevantResult(icapMessageDecoder.message);
} else if(encapsulated != null && !encapsulated.containsEntry(IcapMessageElementEnum.REQHDR) & !encapsulated.containsEntry(IcapMessageElementEnum.RESHDR)) {
} else if(encapsulated != null && !encapsulated.containsEntry(IcapMessageElementEnum.REQHDR) && !encapsulated.containsEntry(IcapMessageElementEnum.RESHDR)) {
return StateReturnValue.createRelevantResult(icapMessageDecoder.message);
}
return StateReturnValue.createIrrelevantResult();
Expand Down Expand Up @@ -119,7 +119,7 @@ private void validateMandatoryMessageHeaders(IcapMessage message) {
private void handleEncapsulationHeaderVolatility(IcapMessage message) {
// Pseudo code
// IF Encapsulated header is missing
// IF OPTIONS request OR 100 Continue response OR 204 No Content response
// IF OPTIONS request OR 100 Continue response OR 204 No Content response OR is a server error
// THEN inject synthetic null-body Encapsulated header.
boolean requiresSynthecticEncapsulationHeader = false;
if(!message.containsHeader(IcapHeaders.Names.ENCAPSULATED)) {
Expand All @@ -128,7 +128,9 @@ private void handleEncapsulationHeaderVolatility(IcapMessage message) {
} else if(message instanceof IcapResponse) {
IcapResponse response = (IcapResponse)message;
IcapResponseStatus status = response.getStatus();
if(status.equals(IcapResponseStatus.CONTINUE) | status.equals(IcapResponseStatus.NO_CONTENT)) {
if(status.equals(IcapResponseStatus.CONTINUE) ||
status.equals(IcapResponseStatus.NO_CONTENT) ||
(status.getCode() >= 500)) {
requiresSynthecticEncapsulationHeader = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public void onEntry(ChannelBuffer buffer, IcapMessageDecoder icapMessageDecoder)
@Override
public StateReturnValue execute(ChannelBuffer buffer, IcapMessageDecoder icapMessageDecoder) throws DecodingException {
String[] initialLine = IcapDecoderUtil.splitInitialLine(IcapDecoderUtil.readLine(buffer,icapMessageDecoder.maxInitialLineLength));
icapMessageDecoder.message = icapMessageDecoder.createMessage(initialLine);
if (initialLine.length >= 3) {
try {
icapMessageDecoder.message = icapMessageDecoder.createMessage(initialLine);
}
catch (IllegalArgumentException e) {
icapMessageDecoder.message = null;
}
}
return StateReturnValue.createIrrelevantResult();
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/ch/mimo/netty/handler/codec/icap/IcapHeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,17 @@ public void getDateHeader() {
Date returnedDate = headers.getDateHeader(IcapHeaders.Names.DATE);
assertNotNull("The returned date was null",returnedDate);
}

@Test
public void removeAddHead() {
IcapHeaders headers = new IcapHeaders();
headers.addHeader("fuz", "buz");
headers.addHeader("foo", "bar");
assertTrue("Header 'FOO' should exist (1)", headers.containsHeader("foo"));
assertEquals("Header 'FOO' should be 'bar'", "bar", headers.getHeader("foo"));
headers.removeHeader("foo");
headers.addHeader("foo", "baz");
assertTrue("Header 'FOO' should exist (2)", headers.containsHeader("foo"));
assertEquals("Header 'FOO' should be 'baz'", "baz", headers.getHeader("foo"));
}
}