Search code examples
scalaetagif-none-match

scalaj etag get can't parse


Using scalaj.http 2.4 I cannot get the correct code for a If-None-Match etag for this simple call:

import scalaj.http.Http
object EtagTest extends App {
  val firstResponse = Http("https://api.github.com/users/octocat/orgs")
  // get correct etag ...
  val response = Http("https://api.github.com/users/octocat/orgs").header("If-None-Match", "\"98f0c1b396a4e5d54f4d5fe561d54b44\"").asString
  println(response.code)
}

I'm expecting a 304 Not Modified but I get a 200.


Solution

  • I tried the following and it worked for me. It looks like the ETag you get with this program is not the ETag you've hard coded in your program. The strange thing is that when I send a cURL request to it, the ETag returned is the one you have hard coded.

    import scalaj.http.Http
    
    object ETagTest extends App {
      val firstResponse = Http("https://api.github.com/users/octocat/orgs").asString
      val response = Http("https://api.github.com/users/octocat/orgs").header("If-None-Match", firstResponse.header(key = "ETag").get).asString
      println(response.code)
      println(response.header(key = "ETag").get)
    }
    

    Output of the above:

    304
    "80b190627d4c87e9a37c34e20ea246a1"