This repository has been archived by the owner on Feb 19, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved DRequest and DResult into protocol
- Loading branch information
1 parent
05b9287
commit 584c0d1
Showing
17 changed files
with
75 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/main/scala/asobu/distributed/gateway/enricher/RequestEnricher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
distributed/src/main/scala/asobu/distributed/gateway/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
distributed/src/main/scala/asobu/distributed/protocol/DRequest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package asobu.distributed.protocol | ||
|
||
import akka.stream.Materializer | ||
import akka.util.ByteString | ||
import asobu.distributed.Headers | ||
|
||
import play.api.http.HttpEntity | ||
import play.api.mvc.{ResponseHeader, Result, Request, AnyContent} | ||
|
||
import scala.concurrent.Future | ||
|
||
@SerialVersionUID(1L) | ||
case class HttpStatus(code: Int) extends AnyVal | ||
|
||
@SerialVersionUID(1L) | ||
case class DRequest( | ||
requestParams: RequestParams, | ||
body: AnyContent, | ||
headers: Headers = Nil | ||
) | ||
|
||
@SerialVersionUID(1L) | ||
case class RequestParams( | ||
pathParams: Map[String, String], | ||
queryString: Map[String, Seq[String]] | ||
) | ||
|
||
@SerialVersionUID(1L) | ||
case class DResult( | ||
status: HttpStatus, | ||
headers: Headers = Nil, | ||
body: Array[Byte] = Array.empty | ||
) | ||
|
||
object DRequest { | ||
def apply(params: RequestParams, request: Request[AnyContent]): DRequest = | ||
DRequest(params, request.body, request.headers.headers) | ||
} | ||
|
||
object RequestParams { | ||
lazy val empty = RequestParams(Map.empty, Map.empty) | ||
} | ||
|
||
object DResult { | ||
def toResult(dr: DResult): Result = | ||
Result(new ResponseHeader(dr.status.code, dr.headers.toMap), HttpEntity.Strict(ByteString(dr.body), None)) | ||
|
||
def from(result: Result)(implicit mat: Materializer): Future[DResult] = { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
result.body.consumeData.map { data ⇒ | ||
DResult( | ||
HttpStatus(result.header.status), | ||
result.header.headers.toSeq, | ||
data.toArray[Byte] | ||
) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/main/scala/asobu/distributed/service/DRequestExtractor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/main/scala/asobu/distributed/service/extractors/DRequestExtractors.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/main/scala/asobu/distributed/service/extractors/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/test/scala/asobu/distributed/service/DRequestExtractorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
distributed/src/test/scala/asobu/distributed/service/RequestParamsExtractorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters