-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from CleverCloud/chore/rewrite-errors
chore(http): better WarpScript error extraction
- Loading branch information
Showing
4 changed files
with
102 additions
and
15 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
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,45 @@ | ||
import org.apache.pekko | ||
import org.apache.pekko.actor.ActorSystem | ||
import org.apache.pekko.http.scaladsl.Http | ||
import org.apache.pekko.http.scaladsl.model.{ HttpMethod, HttpRequest, HttpResponse, Uri } | ||
import org.apache.pekko.stream.scaladsl.{ Sink, Source } | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* Mock Akka HTTP Server, will handle requests which is provided with handle request | ||
*/ | ||
object MockServer { | ||
|
||
val interface = "localhost" | ||
val port = 8888 | ||
|
||
def handleRequest( | ||
method: HttpMethod, | ||
uri: Uri, | ||
response: HttpResponse | ||
// httpRequest: HttpRequest | ||
)(implicit | ||
system: ActorSystem | ||
): Future[Http.ServerBinding] = { | ||
|
||
val serverSource: Source[Http.IncomingConnection, Future[Http.ServerBinding]] = | ||
Http().newServerAt(interface, port).connectionSource() | ||
|
||
// val requestPath = httpRequest.uri.path.toString() | ||
|
||
val requestHandler: HttpRequest => HttpResponse = { | ||
case HttpRequest(method, uri, _, _, _) => // Uri.Path(`requestPath`) | ||
response | ||
case _: HttpRequest => | ||
HttpResponse(404, entity = "Unknown resource!") | ||
} | ||
|
||
serverSource | ||
.to(Sink.foreach { connection => | ||
println("Mock Server accepted new connection from " + connection.remoteAddress) | ||
connection handleWithSyncHandler requestHandler | ||
}) | ||
.run() | ||
} | ||
} |
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