在多播之前将标头添加到 diffy 代理 [英] Adding headers to diffy proxy before multicasting

查看:26
本文介绍了在多播之前将标头添加到 diffy 代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Diffy 进行 API 测试,但发现它不允许在发送请求时自定义标头.我们的 API 需要访问令牌,这些令牌在作为 HTTP 标头传递的不同服务器中是不同的.

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.

我开始探索 Diffy 代码并尝试自己解决这个问题(对我来说).

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

理解流程/代码对我来说有点困难,因为我没有 Scala 经验.但是我稍微理解了代码并尝试在[HttpDifferenceProxy.scala] (https://github.com/twitter/diffy/blob/master/src/main/scala/com/twitter/diffy/proxy/HttpDifferenceProxy.scala)

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)

Diffy 工具在检查是否允许后异步执行 Http 请求.我在此检查之前在此处添加了我的代码行以添加标题.

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. 未添加标题
  2. 对于一个好的 Scala IDE 的任何建议——我使用的是构建在 Eclipse 之上的 ScalaIDE,但调试功能远不及 Eclipse 在 Java 中的调试功能.

我在这里做错了什么?

谢谢,苏卡尔波.

推荐答案

我找到了我的两个问题的答案,它们是相同的 :)

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

IntelliJ 是有史以来最酷的 IDE.

IntelliJ is the most coolest IDE ever.

1 的答案:- 正在添加标题.我在调试时以某种方式使用的糟糕的 ScalaIDE 没有显示出来,浪费了我一整天

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

2 的答案:- 放下 IntelliJ

Answer for 2:- Hands down IntelliJ

这篇关于在多播之前将标头添加到 diffy 代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆