Advertisement
Guest User

Akka HTTP Client For git ls-remote

a guest
Jul 30th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.74 KB | None | 0 0
  1. package com.example
  2.  
  3. import scala.concurrent.Await
  4. import scala.concurrent.ExecutionContext.Implicits.global
  5. import scala.concurrent.duration._
  6.  
  7. import org.scalatest._
  8.  
  9. import akka.actor.ActorSystem
  10. import akka.http.scaladsl._
  11. import akka.http.scaladsl.model._
  12. import akka.http.scaladsl.model.headers.{ Accept, Host, `User-Agent` }
  13. import akka.stream.ActorMaterializer
  14. import akka.stream.scaladsl._
  15. import akka.stream.testkit.scaladsl.{ TestSink, TestSource }
  16. import akka.testkit._
  17.  
  18. class Example extends TestKit(ActorSystem("ProxySpec")) with ImplicitSender
  19.   with FlatSpecLike with Matchers with BeforeAndAfterAll {
  20.   "httpOutgoingConnectionHttps" should "be able to get a git repo" in {
  21.     val http = Http(system)
  22.     implicit val materializer = ActorMaterializer()
  23.     val uri = Uri("https://github.com/akka/akka-http.git/info/refs?service=git-upload-pack")
  24.     val connFlow = http.outgoingConnectionHttps(uri.authority.host.address, uri.effectivePort)
  25.  
  26.     val (pub, sub) = TestSource.probe[HttpRequest]
  27.       .via(connFlow)
  28.       .toMat(TestSink.probe[HttpResponse])(Keep.both)
  29.       .run()
  30.     val r = HttpRequest(uri = uri).withHeaders(
  31.       Accept(MediaRange(MediaType.customWithOpenCharset("*", "*", allowArbitrarySubtypes = true))),
  32.       //`User-Agent`("curl/7.50.3"),
  33.       //Host(uri.authority.host)
  34.       )
  35.  
  36.  
  37.     sub.request(n = 1)
  38.     pub.sendNext(r)
  39.     val res = sub.expectNext(10.seconds)
  40.  
  41.     val resBody = Await.result(res.entity.toStrict(10.seconds).map(_.data.decodeString("UTF-8")), 10.seconds)
  42.     println(s"----> ${res.status}")
  43.     println(s"----> ${resBody}")
  44.     resBody should not be ("Not Found")
  45.     res.status should be(200)
  46.   }
  47.  
  48.   override def afterAll {
  49.     TestKit.shutdownActorSystem(system)
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement