-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Downloader with HttpURLConnection backend
- Loading branch information
1 parent
3bb551f
commit 08f5d0d
Showing
9 changed files
with
83 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
docker/static-files/100MB.bin* | ||
target/ |
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,6 @@ | ||
version: '3' | ||
services: | ||
static-files: | ||
build: docker/static-files | ||
ports: | ||
- 8088:80 |
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,6 @@ | ||
FROM nginx:stable | ||
|
||
COPY ./100MB.bin /var/www/100MB.bin | ||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
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,9 @@ | ||
server { | ||
listen 80; | ||
server_name _; | ||
|
||
root /var/www/; | ||
|
||
location / { | ||
} | ||
} |
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,6 @@ | ||
#!/bin/bash | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
dd if=/dev/random of=$DIR/100MB.bin bs=1024 count=1024 | ||
shasum $DIR/100MB.bin | awk '{print $1}' > $DIR/100MB.bin.shasum |
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
19 changes: 19 additions & 0 deletions
19
fetch-file/src/main/scala/vdx/fetchfile/HttpURLConnectionBackend.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,19 @@ | ||
package vdx.fetchfile | ||
|
||
import cats.effect.{Resource, Sync} | ||
import java.net.HttpURLConnection | ||
|
||
object HttpURLConnectionBackend { | ||
def apply[F[_]: Sync]: Backend[F] = | ||
url => Resource.fromAutoCloseable { | ||
Sync[F].delay { | ||
val connection = url.openConnection().asInstanceOf[HttpURLConnection] | ||
connection.setRequestProperty( | ||
"User-Agent", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11" | ||
) | ||
connection.connect() | ||
connection.getInputStream() | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,11 @@ | ||
package vdx | ||
|
||
import cats.effect.{Resource, Sync} | ||
import cats.effect.Resource | ||
|
||
import java.net.URL | ||
import java.io.InputStream | ||
import java.net.{HttpURLConnection, URL} | ||
|
||
package object fetchfile { | ||
|
||
type Backend[F[_]] = URL => Resource[F, InputStream] | ||
|
||
object Backend { | ||
implicit def httpUrlConnectionBackend[F[_]: Sync]: Backend[F] = | ||
url => Resource.fromAutoCloseable { | ||
Sync[F].delay { | ||
val connection = url.openConnection().asInstanceOf[HttpURLConnection] | ||
connection.setRequestProperty( | ||
"User-Agent", | ||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11" | ||
) | ||
connection.connect() | ||
connection.getInputStream() | ||
} | ||
} | ||
|
||
} | ||
} |
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