Adding headers to diffy proxy before multicasting

2019-09-10 02:56发布

问题:

I wanted to use Diffy for my API testing but found that it does not allow customization of headers while sending requests. Our Apis need access tokens which are different in different servers that are passed as HTTP Headers.

I started exploring the Diffy code and tried to resolve this issue (for me) myself.

Understanding the flow/code is a bit difficult for me as I have no experience in scala. However I understood the code a little and tried to add a line of code at [HttpDifferenceProxy.scala] (https://github.com/twitter/diffy/blob/master/src/main/scala/com/twitter/diffy/proxy/HttpDifferenceProxy.scala)

The Diffy tool executes a Http Request asynchronously after checking whether it is allowed to do so. I added my line of code here before this check to add a header.

object SimpleHttpDifferenceProxy {
lazy val httpSideEffectsFilter =
Filter.mk[HttpRequest, HttpResponse, HttpRequest, HttpResponse] { (req, svc) =>
  req.headers().add("Authorization1", "123") //My code here
  val hasSideEffects =
    Set(Method.Post, Method.Put, Method.Delete).contains(Request(req).method)
  if (hasSideEffects) 
    DifferenceProxy.NoResponseExceptionFuture else svc(req)
} }

Okay I am facing two problems.

  1. The header is not getting added
  2. Any suggestion for a good Scala IDE -- I am using ScalaIDE built on top of Eclipse but the debugging is nowhere close to debugging capabilities of Eclipse in java.

What am I doing wrong here?

Thanks, Sukalpo.

回答1:

I found the answers to both my questions and they are the same :)

IntelliJ is the most coolest IDE ever.

Answer for 1:- The headers were getting added. The shitty ScalaIDE that I was using somehow did not show it while I was debugging and wasted my whole day

Answer for 2:- Hands down IntelliJ



标签: scala twitter