protected def findLocationHeader()

in app/services/GitlabAPI.scala [54:98]


  protected def findLocationHeader(from:Seq[HttpHeader]):Option[String] =
    from.find(_.lowercaseName() == "location").map(_.value())

  protected def makeRequestRaw(method:HttpMethod, url:String, moreHeaders:Map[String,String], bodyContent:Option[ByteString]):Future[ByteString] = {
    logger.debug(s"${method} $url")
    val entity = bodyContent match {
        case None=>
          HttpEntity.Empty
        case Some(content)=>
          HttpEntity(content).withContentType(ContentTypes.`application/json`)
      }

      val baseHeaders = Map(
        "PRIVATE-TOKEN"->token,
        "Accept"->"application/json"
      )

      val headers = (baseHeaders++moreHeaders)
        .map(kv=>HttpHeader.parse(kv._1, kv._2))
        .collect({case HttpHeader.ParsingResult.Ok(hdr,_)=>hdr})
        .toSeq

      val req = HttpRequest(method, url, headers, entity)
      http
        .singleRequest(req)
        .flatMap(response=>{
          val contentFut = consumeResponseContent(response)
          if(response.status==StatusCodes.TemporaryRedirect ||
            response.status==StatusCodes.PermanentRedirect ||
            response.status==StatusCodes.Found) {
            findLocationHeader(response.headers) match {
              case Some(nextUrl)=>
                logger.debug(s"Following ${response.status} redirect to $nextUrl...")
                makeRequestRaw(method, nextUrl, moreHeaders, bodyContent)
              case None=>
                logger.error(s"Received ${response.status} with no Location header?? Got ${response.headers}")
                Future.failed(new RuntimeException("Received redirect with no location"))
            }
          } else if(response.status==StatusCodes.OK || response.status==StatusCodes.Created || response.status==StatusCodes.Accepted) {
            contentFut
          } else {
            contentFut.flatMap(bytes=>Future.failed(new HttpError(response.status, bytes.utf8String)))
          }
        })
    }