Skip to content

Commit

Permalink
Adjust scalafmt config
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurz committed Apr 11, 2022
1 parent 08d86b4 commit 5923841
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 43 deletions.
6 changes: 4 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
align = true
runner.dialect = scala213
align.preset = true
assumeStandardLibraryStripMargin = true
danglingParentheses = true
danglingParentheses.preset = true
docstrings.style = Asterisk
docstrings.wrap = false
maxColumn = 120
project.git = true
rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifiers, PreferCurlyFors ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ trait CurlFormat {
b.append(s" --request ${request.method}")
b.append(" \\\n")

//authentication
// authentication
request.auth match {
case Some((userName, password, WSAuthScheme.BASIC)) =>
val encodedPassword =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,24 @@ class AhcHttpCache(underlying: standaloneAhc.cache.Cache, heuristicsEnabled: Boo
if (isUnsafeMethod(request) && isNonErrorResponse(response)) {
val requestHost = request.getUri.getHost

//A cache MUST invalidate the effective request URI (Section 5.5 of
//[RFC7230]) when it receives a non-error response to a request with a
//method whose safety is unknown.
// A cache MUST invalidate the effective request URI (Section 5.5 of
// [RFC7230]) when it receives a non-error response to a request with a
// method whose safety is unknown.
val responseKey = EffectiveURIKey(request.getMethod, response.getUri.toJavaNetURI)
invalidateKey(responseKey)

//A cache MUST invalidate the effective Request URI (Section 5.5 of
//[RFC7230]) as well as the URI(s) in the Location and Content-Location
//response header fields (if present) when a non-error status code is
//received in response to an unsafe request method.
// A cache MUST invalidate the effective Request URI (Section 5.5 of
// [RFC7230]) as well as the URI(s) in the Location and Content-Location
// response header fields (if present) when a non-error status code is
// received in response to an unsafe request method.

// https://tools.ietf.org/html/rfc7231#section-3.1.4.2
// https://tools.ietf.org/html/rfc7230#section-5.5
getURI(response, "Content-Location").foreach { contentLocation =>
//However, a cache MUST NOT invalidate a URI from a Location or
//Content-Location response header field if the host part of that URI
//differs from the host part in the effective request URI (Section 5.5
//of [RFC7230]). This helps prevent denial-of-service attacks.
// However, a cache MUST NOT invalidate a URI from a Location or
// Content-Location response header field if the host part of that URI
// differs from the host part in the effective request URI (Section 5.5
// of [RFC7230]). This helps prevent denial-of-service attacks.
if (requestHost.equalsIgnoreCase(contentLocation.getHost)) {
val key = EffectiveURIKey(request.getMethod, contentLocation)
invalidateKey(key)
Expand Down Expand Up @@ -234,8 +234,8 @@ class AhcHttpCache(underlying: standaloneAhc.cache.Cache, heuristicsEnabled: Boo
}

protected def isNonErrorResponse(response: CacheableResponse): Boolean = {
//Here, a "non-error response" is one with a 2xx (Successful) or 3xx
//(Redirection) status code.
// Here, a "non-error response" is one with a 2xx (Successful) or 3xx
// (Redirection) status code.
response.getStatusCode match {
case success if success >= 200 && success < 300 =>
true
Expand Down Expand Up @@ -324,12 +324,12 @@ class AhcHttpCache(underlying: standaloneAhc.cache.Cache, heuristicsEnabled: Boo

// Need to freshen this stale response
// https://tools.ietf.org/html/rfc7234#section-4.3.4
//If a stored response is selected for update, the cache MUST:
//o delete any Warning header fields in the stored response with
//warn-code 1xx (see Section 5.5);
// If a stored response is selected for update, the cache MUST:
// o delete any Warning header fields in the stored response with
// warn-code 1xx (see Section 5.5);
//
//o retain any Warning header fields in the stored response with
//warn-code 2xx; and,
// o retain any Warning header fields in the stored response with
// warn-code 2xx; and,
val headers = response.headers
val headersMap: HttpHeaders = new DefaultHttpHeaders().add(headers)
val filteredWarnings = headersMap
Expand All @@ -342,9 +342,9 @@ class AhcHttpCache(underlying: standaloneAhc.cache.Cache, heuristicsEnabled: Boo
.asJava
headersMap.set("Warning", filteredWarnings)

//o use other header fields provided in the 304 (Not Modified)
//response to replace all instances of the corresponding header
//fields in the stored response.
// o use other header fields provided in the 304 (Not Modified)
// response to replace all instances of the corresponding header
// fields in the stored response.
headersMap.set(newHeaders)

response.copy(headers = headersMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ class AsyncCachingHandler[T](
if (cache.isNotModified(response)) {
processNotModifiedResponse(response)
} else if (cache.isError(response)) {
//o However, if a cache receives a 5xx (Server Error) response while
//attempting to validate a response, it can either forward this
//response to the requesting client, or act as if the server failed
//to respond. In the latter case, the cache MAY send a previously
//stored response (see Section 4.2.4).
// o However, if a cache receives a 5xx (Server Error) response while
// attempting to validate a response, it can either forward this
// response to the requesting client, or act as if the server failed
// to respond. In the latter case, the cache MAY send a previously
// stored response (see Section 4.2.4).

maybeAction match {
case Some(Validate(reason, staleIfError)) if staleIfError =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,25 @@ class CachingAsyncHttpClient(underlying: AsyncHttpClient, ahcHttpCache: AhcHttpC
// https://tools.ietf.org/html/rfc7234#section-4.3.1
// https://tools.ietf.org/html/rfc7232#section-2.4

//A client:
// A client:
//
//o MUST send that entity-tag in any cache validation request (using
// o MUST send that entity-tag in any cache validation request (using
// If-Match or If-None-Match) if an entity-tag has been provided by
//the origin server.
// the origin server.
//
//o SHOULD send the Last-Modified value in non-subrange cache
//validation requests (using If-Modified-Since) if only a
//Last-Modified value has been provided by the origin server.
// o SHOULD send the Last-Modified value in non-subrange cache
// validation requests (using If-Modified-Since) if only a
// Last-Modified value has been provided by the origin server.
//
//o MAY send the Last-Modified value in subrange cache validation
//requests (using If-Unmodified-Since) if only a Last-Modified value
//has been provided by an HTTP/1.0 origin server. The user agent
//SHOULD provide a way to disable this, in case of difficulty.
// o MAY send the Last-Modified value in subrange cache validation
// requests (using If-Unmodified-Since) if only a Last-Modified value
// has been provided by an HTTP/1.0 origin server. The user agent
// SHOULD provide a way to disable this, in case of difficulty.
//
//o SHOULD send both validators in cache validation requests if both
//an entity-tag and a Last-Modified value have been provided by the
//origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to
//respond appropriately.
// o SHOULD send both validators in cache validation requests if both
// an entity-tag and a Last-Modified value have been provided by the
// origin server. This allows both HTTP/1.0 and HTTP/1.1 caches to
// respond appropriately.

composeRequest(request) { rb =>
val headers = response.getHeaders
Expand Down

0 comments on commit 5923841

Please sign in to comment.