-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WX-1092 Support size
engine function for public HTTP files
#7128
Changes from all commits
d361dc8
3fac6d8
11bda5c
b0855a0
175d959
07604b6
d92e0f4
7fa1503
9fd171e
39d2c5a
e0ba395
add9b93
82c4a50
7489d79
a90eec2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import java.nio.file.Paths | |
|
||
import akka.actor.{ActorContext, ActorSystem} | ||
import akka.http.scaladsl.Http | ||
import akka.http.scaladsl.model.HttpRequest | ||
import akka.http.scaladsl.model.{HttpMethods, HttpRequest} | ||
import akka.stream.scaladsl.{FileIO, Keep} | ||
import akka.stream.{ActorAttributes, ActorMaterializer} | ||
import cromwell.core.Dispatcher | ||
|
@@ -53,4 +53,20 @@ case class HttpPath(nioPath: NioPath) extends Path { | |
override def pathAsString: String = nioPath.toString.replaceFirst("/", "//") | ||
|
||
override def pathWithoutScheme: String = pathAsString.replaceFirst("http[s]?://", "") | ||
|
||
def fetchSize(implicit executionContext: ExecutionContext, actorSystem: ActorSystem): Future[Long] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't directly override |
||
Http().singleRequest(HttpRequest(uri = pathAsString, method = HttpMethods.HEAD)).map { response => | ||
response.discardEntityBytes() | ||
val length = if (response.status.isSuccess()) | ||
response.entity.contentLengthOption | ||
else | ||
None | ||
length.getOrElse( | ||
throw new RuntimeException( | ||
s"Couldn't fetch size for $pathAsString, missing Content-Length header or path doesn't exist (HTTP ${response.status.toString()})." | ||
) | ||
) | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suppresses warnings about the
etag
header when reading blob files. I turned these warnings off entirely because they don't seem useful to anyone and are more log clutter. If anyone objects to the big hammer, this can be changed to suppress warnings about specific headers (ex. justetag
) or can be added just to our Azure config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach makes sense to me.