Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional logging to track mesh clients interacting with Namerd #2277

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add H2HeaderInjector
Signed-off-by: Dennis Adjei-Baah <[email protected]>
  • Loading branch information
Dennis Adjei-Baah committed May 23, 2019
commit 44cf2f1de0eefc48c9938ae2d973a81c8ea21e46
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.twitter.finagle.buoyant.h2

import com.twitter.finagle
import com.twitter.finagle._
import com.twitter.util.Future

object H2HeaderInjector {
def module(headerMap: Map[String, String]): Stackable[ServiceFactory[Request, Response]] = {
new finagle.Stack.Module0[ServiceFactory[Request, Response]] {
override def make(next: ServiceFactory[Request, Response]): ServiceFactory[Request, Response] =
new HeaderInjector(headerMap).andThen(next)

override def role: Stack.Role = Stack.Role("H2HeaderInjector")
override def description: String = "Add arbitrary headers to H2 requests"
}
}
}

class HeaderInjector(injectHeaders: Map[String, String]) extends SimpleFilter[Request, Response] {
override def apply(request: Request, service: Service[Request, Response]): Future[Response] = {
val req = request.dup()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary? aren't headers mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember from my last run-in with H2 request mangling that I had to dup() this for some reason, alas, I do not remember. I think we don't need this.

injectHeaders.foreach { kvPair =>
req.headers.add(kvPair._1, kvPair._2); ()
}
service(req)
}
}