-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support to combine multilple cookie headers into one
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...m.ws.transport.http/src/com/ibm/ws/http/netty/pipeline/inbound/CombinedCookieHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package com.ibm.ws.http.netty.pipeline.inbound; | ||
|
||
import java.util.List; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.handler.codec.http.FullHttpRequest; | ||
import io.netty.handler.codec.http.HttpHeaderNames; | ||
|
||
public class CombinedCookieHandler extends ChannelInboundHandlerAdapter { | ||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
if (msg instanceof FullHttpRequest) { | ||
FullHttpRequest request = (FullHttpRequest) msg; | ||
|
||
// Retrieve all Cookie headers | ||
List<String> cookieHeaders = request.headers().getAll(HttpHeaderNames.COOKIE); | ||
if (cookieHeaders.size() > 1) { | ||
// Combine multiple Cookie headers into one | ||
String combinedCookies = String.join("; ", cookieHeaders); | ||
// Remove all existing Cookie headers | ||
request.headers().remove(HttpHeaderNames.COOKIE); | ||
// Set the combined Cookie header | ||
request.headers().set(HttpHeaderNames.COOKIE, combinedCookies); | ||
} | ||
} | ||
// Pass the message along to the next handler | ||
ctx.fireChannelRead(msg); | ||
} | ||
} |