question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Accept header not appended properly in 0.23.0-RC1

See original GitHub issue

I tried the following ways to construct the Accept header

    Headers(
      Accept(
        MediaRangeAndQValue
          .withDefaultQValue(MediaRange.parse("application/vnd.docker.distribution.manifest.v2+json").toOption.get)
      ),
      Header.Raw(ci"Accept", "application/vnd.docker.distribution.manifest.v2+json"),
      Accept.parse("application/vnd.docker.distribution.manifest.v2+json").toOption.get
    )

But none of them actually appended the header properly.

In previous version, headers in a call looked like this

{"@timestamp":"2021-07-28T15:59:16.160Z","@version":"1","message":"HTTP/1.1 GET https://registry-1.docker.io/v2/rtitle/anvil-rstudio-base/blobs/sha256:aaf072362a3bfa231f444af7a05aa24dd83f6d94ba56b3d6d0b365748deac30a Headers(Accept: application/vnd.docker.distribution.manifest.v2+json, Authorization: <REDACTED>, Accept: application/json)","logger_name":"org.http4s.client.middleware.RequestLogger","thread_name":"scala-execution-context-global-1942","severity":"INFO","level_value":20000}

But it now looks like this with 0.23.0-RC1

{"@timestamp":"2021-07-28T16:07:41.141Z","@version":"1","message":"HTTP/1.1 GET https://registry-1.docker.io/v2/rtitle/anvil-rstudio-base/manifests/0.0.1 Headers(Content-Type: application/vnd.docker.distribution.manifest.v2+json, Authorization: <REDACTED>, Accept: application/json)","logger_name":"org.http4s.client.middleware.RequestLogger","thread_name":"io-compute-8","severity":"INFO","level_value":20000}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
rossabakercommented, Sep 3, 2021

Yep!

Good way to tell on any repo: look at the commit on the fix. Up at the top, GitHub lists the tags that contain the commit.

1reaction
rossabakercommented, Jul 28, 2021

All of the client methods that take an EntityDecoder do something like this. As a quick fix, if you put this function on a client syntax trait:

  implicit class ClientTempSyntax[F[_]](val client: Client[F])(implicit F: MonadCancelThrow[F]) {
    def expectOptionOrHack[A](req: Request[F])(onError: Response[F] => F[Throwable])(implicit
        d: EntityDecoder[F, A]): F[Option[A]] = {
      val r = if (d.consumes.nonEmpty) {
        val m = d.consumes.toList
        req.transformHeaders(_.add(Accept(MediaRangeAndQValue(m.head), m.tail.map(MediaRangeAndQValue(_)): _*)))
      } else req

      client.run(r).use {
        case Successful(resp) =>
          d.decode(resp, strict = false).leftWiden[Throwable].rethrowT.map(_.some)
        case failedResponse =>
          failedResponse.status match {
            case Status.NotFound => Option.empty[A].pure[F]
            case Status.Gone => Option.empty[A].pure[F]
            case _ => onError(failedResponse).flatMap(F.raiseError)
          }
      }
    }
  }

And then just call expectOptionOrHack instead of expectOption.

I’ve been working toward the 0.23 release today. We’ll have a proper fix in that, and I’ll also release an 0.22.1 patch. Once that’s done, you can revert to the standard method, and all should be well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Accept header not handled correctly | Bitbucket Server
If the Accept header contains any of application/json, application/x-json, text/json, or text/x-json the request will return JSON. This is regardless of the ...
Read more >
python - Is it a bug to omit an Accept */* header in an HTTP/1.0 ...
I presume that curl and requests add the default for a reason, but I'm not sure what that reason is. RFC 2616 for...
Read more >
Prism is not respecting the Accept header · Issue #332 - GitHub
Describe the bug I'm getting empty responses from Prism mock server. To Reproduce Using this example specification: ...
Read more >
Text_Wiki - PEAR - PHP Extension and Application Repository
Bug #12490 wiki's do not display since php5-5.2.5 upgrade but are ... php pyrus.phar install pear/Text_Wiki-1.2.0RC1 ... Heading: collapsing in headers
Read more >
Important notes — Borg - Deduplicating Archiver 1.2.2 ...
A bug was discovered in our hashtable code, see issue #4829. The code is used for the client-side chunks cache and the server-side...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found