Skip to content

Commit

Permalink
Merge pull request #73 from peterrosell/don't-do-a-head-request-in-co…
Browse files Browse the repository at this point in the history
…nnect

Don't do a head request in connect
  • Loading branch information
abdolence committed Apr 25, 2024
2 parents bbdd687 + 93c1183 commit 7c78521
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
9 changes: 4 additions & 5 deletions sbt-gcs-plugin/.scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ version = 3.8.1
preset = default
lineEndings = unix
maxColumn = 120
docstrings = JavaDoc

runner {
dialect = scala212
}

align {
preset = more
Expand All @@ -11,9 +14,6 @@ align {
arrowEnumeratorGenerator = true
}

newlines {
alwaysBeforeTopLevelStatements = true
}
continuationIndent {
defnSite = 4
}
Expand All @@ -32,5 +32,4 @@ trailingCommas = never

verticalMultiline {
atDefnSite = false
newlineBeforeImplicitKW = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import com.google.api.client.http.{
}
import sbt.Logger

import java.io.{ ByteArrayOutputStream, InputStream, OutputStream }
import java.net.{ HttpURLConnection, URL }
import scala.util.Try
import java.io.{ByteArrayOutputStream, InputStream, OutputStream}
import java.net.{HttpURLConnection, URL}
import scala.jdk.CollectionConverters.*
import scala.util.control.NonFatal

Expand All @@ -42,20 +41,10 @@ class GcsArtifactRegistryUrlConnection( googleHttpRequestFactory: HttpRequestFac
// when the connection has already been opened the call is ignored.
if (!connected) {
connectedWithHeaders = new HttpHeaders()
try {
super.getRequestProperties.asScala.foreach { case ( header, headerValues ) =>
connectedWithHeaders.set( header, headerValues )
}
logger.debug( s"Checking artifact at url: ${url}." )
val httpRequest =
googleHttpRequestFactory.buildHeadRequest( genericUrl )
connected = httpRequest.execute().isSuccessStatusCode
} catch {
case ex: HttpResponseException => {
responseCode = ex.getStatusCode
responseMessage = ex.getStatusMessage
}
super.getRequestProperties.asScala.foreach { case ( header, headerValues ) =>
connectedWithHeaders.set( header, headerValues )
}
connected = true
}
}

Expand All @@ -66,25 +55,21 @@ class GcsArtifactRegistryUrlConnection( googleHttpRequestFactory: HttpRequestFac
if (!connected) {
connect()
}
if (responseCode < 400) {
try {
logger.info( s"Receiving an artifact from url: ${url}." )
val httpRequest = googleHttpRequestFactory.buildGetRequest( genericUrl )
try {
logger.debug( s"Receiving an artifact from url: ${url}." )
val httpRequest = googleHttpRequestFactory.buildGetRequest( genericUrl )

val httpResponse = appendHeadersBeforeConnect( httpRequest ).execute()
val httpResponse = appendHeadersBeforeConnect( httpRequest ).execute()

val inputStream = httpResponse.getContent
inputStreamIsReady = Some( inputStream )
inputStream
} catch {
case ex: HttpResponseException => {
responseCode = ex.getStatusCode
responseMessage = ex.getStatusMessage
null
}
val inputStream = httpResponse.getContent
inputStreamIsReady = Some( inputStream )
inputStream
} catch {
case ex: HttpResponseException => {
responseCode = ex.getStatusCode
responseMessage = ex.getStatusMessage
null
}
} else {
null
}
}
}
Expand Down

0 comments on commit 7c78521

Please sign in to comment.