reactor / reactor-netty

TCP/HTTP/UDP/QUIC client/server with Reactor over Netty

Home Page:https://projectreactor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to add cookie in redirectRequestBiConsumer

istibekesi opened this issue · comments

Expected Behavior

According to the javadoc of followRedirect:
Param redirectRequestBiConsumer – BiConsumer, invoked on redirects, after the redirect request has been initialized, in order to apply further changes such as add/remove headers and cookies.

Actual Behavior

Redirect headers are added, redirect cookies are missing.

Steps to Reproduce

	@Test
	void myTest() {
		disposableServer =
			createServer()
				.host("localhost")
				.route(r -> r.get("/1", (req, res) -> res.sendRedirect("/3"))
					.get("/3", (req, res) -> {
						if (req.cookies().containsKey("myCookie")) {
							return res.status(200).sendString(Mono.just("OK"));
						} else {
							return res.status(400).sendString(Mono.just("NOK"));
						}
					}))
				.wiretap(false)
				.bindNow();

		HttpClientResponse response =
			createClient(disposableServer::address)
				.wiretap("", LogLevel.INFO, AdvancedByteBufFormat.TEXTUAL)
				.followRedirect(
					(req, res) -> true,
					(headers, redirect) -> {
						redirect.addHeader("myHeader", "myHeader");
						redirect.addCookie(new DefaultCookie("myCookie", "myCookie"));
					}
				)
				.get()
				.uri("/1")
				.response()
				.block(Duration.ofSeconds(30));

		assertThat(response).isNotNull();
		assertThat(response.status()).isEqualTo(HttpResponseStatus.OK);
	}

Log:

09:14:17.154 [reactor-http-nio-3] INFO   - [b9a9d5df-1, L:/127.0.0.1:65266 - R:/127.0.0.1:65263] WRITE: 124B GET /3 HTTP/1.1
user-agent: ReactorNetty/dev
host: 127.0.0.1:65263
accept: */*
myHeader: myHeader
content-length: 0

Note: on 1.0.34 the above test passed, but fails on 1.1.x

@istibekesi Thanks for the reproducible example! I'm observing the issue with both 1.0.x and 1.1.x versions. It is a regression caused by PR #2994

The PR #3039 should fix it.