Skip to content

Commit

Permalink
fix #1751
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Oct 31, 2023
1 parent 6e5afc6 commit 2980de9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 44 deletions.
40 changes: 14 additions & 26 deletions otoroshi/app/netty/h1h2client.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package otoroshi.netty

import akka.http.scaladsl.model.HttpHeader.ParsingResult
import akka.http.scaladsl.model.headers.{`Content-Length`, `Content-Type`, `User-Agent`, RawHeader}
import akka.http.scaladsl.model.headers.{RawHeader, `Content-Length`, `Content-Type`, `User-Agent`}
import akka.http.scaladsl.model.{ContentType, HttpHeader, Uri}
import akka.stream.scaladsl.{Sink, Source}
import akka.util.ByteString
import com.google.common.base.Charsets
import io.netty.buffer.Unpooled
import io.netty.buffer.{ByteBuf, Unpooled}
import io.netty.channel.ChannelOption
import io.netty.handler.codec.http.HttpMethod
import io.netty.handler.logging.LogLevel
Expand All @@ -20,21 +20,7 @@ import otoroshi.utils.reactive.ReactiveStreamUtils
import otoroshi.utils.syntax.implicits._
import play.api.Logger
import play.api.libs.json.{JsValue, Json}
import play.api.libs.ws.{
BodyWritable,
DefaultWSCookie,
EmptyBody,
InMemoryBody,
SourceBody,
WSAuthScheme,
WSBody,
WSCookie,
WSProxyServer,
WSRequest,
WSRequestFilter,
WSResponse,
WSSignatureCalculator
}
import play.api.libs.ws.{BodyWritable, DefaultWSCookie, EmptyBody, InMemoryBody, SourceBody, WSAuthScheme, WSBody, WSCookie, WSProxyServer, WSRequest, WSRequestFilter, WSResponse, WSSignatureCalculator}
import play.api.mvc.MultipartFormData
import reactor.core.publisher.{Flux, Mono}
import reactor.netty.ByteBufFlux
Expand Down Expand Up @@ -208,15 +194,17 @@ case class NettyWsClientRequest(
.addHttpHeaders("Content-Type" -> "application/octet-stream")
.execute()
override def withCookies(cookies: WSCookie*): WSRequest = {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
if (cookies.nonEmpty) {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
} else this
}
override def withHeaders(headers: (String, String)*): WSRequest = withHttpHeaders(headers: _*)
override def withHttpHeaders(headers: (String, String)*): WSRequest = {
Expand Down
20 changes: 11 additions & 9 deletions otoroshi/app/netty/h3client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -508,15 +508,17 @@ case class NettyHttp3ClientWsRequest(
.addHttpHeaders("Content-Type" -> "application/octet-stream")
.execute()
override def withCookies(cookies: WSCookie*): WSRequest = {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
if (cookies.nonEmpty) {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
} else this
}
override def withHeaders(headers: (String, String)*): WSRequest = withHttpHeaders(headers: _*)
override def withHttpHeaders(headers: (String, String)*): WSRequest = {
Expand Down
20 changes: 11 additions & 9 deletions otoroshi/app/utils/httpclient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1482,15 +1482,17 @@ case class AkkaWsClientRequest(
///////////

override def withCookies(cookies: WSCookie*): WSRequest = {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
if (cookies.nonEmpty) {
val oldCookies = headers.get("Cookie").getOrElse(Seq.empty[String])
val newCookies = oldCookies :+ cookies.toList
.map { c =>
s"${c.name}=${c.value}"
}
.mkString(";")
copy(
headers = headers + ("Cookie" -> newCookies)
)
} else this
}

override lazy val followRedirects: Option[Boolean] = Some(false)
Expand Down

0 comments on commit 2980de9

Please sign in to comment.