<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Can we only use the request uri +
      method + request mediaType as the cache key ?<br>
      Will this resolve these two issues ?<br>
      <br>
      Thanks,<br>
      Jim<br>
      <br>
      On 10/18/2018 03:27 PM, Petr Jurak wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAL1mVq8B5nJBCRtiCkWHXkA5ZfjhfMrDf6dYUdjYLvfok_zt_w@mail.gmail.com">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">Hi,
                      <div><br>
                      </div>
                      <div>I was looking into RESTEASY-2038 [1]. I'm not
                        sure how to handle this correctly so I need to
                        know your opinion.</div>
                      <div><br>
                      </div>
                      <div>In the <i>org.jboss.resteasy.client.jaxrs.cache.CacheInterceptor</i>
                        there is a method for storing response in the
                        cache containing this part. </div>
                      <div><br>
                      </div>
                      <div>
                        <div><i>String contentType = (String)
                            response.getHeaderString(HttpHeaders.CONTENT_TYPE);</i></div>
                        <div><i>byte[] cached =
                            ReadFromStream.readFromStream(1024,
                            response.getEntityStream());<br>
                          </i></div>
                        <div><i>MediaType mediaType =
                            MediaType.valueOf(contentType);<br>
                          </i></div>
                        <div><i>final BrowserCache.Entry entry =
                            cache.put(request.getUri().toString(),
                            mediaType,</i></div>
                        <div><i>        response.getHeaders(), cached,
                            expires, etag, lastModified);</i></div>
                      </div>
                      <div><br>
                      </div>
                      <div>Later, once the same GET method is executed,
                        the interceptor checks if there is an entry in
                        the cache for the given Accept type.</div>
                      <div><br>
                      </div>
                      <div><i>BrowserCache.Entry entry =
                          getEntry(request);</i><br>
                      </div>
                      <div><br>
                      </div>
                      <div>In the getEntry method it checks for the type</div>
                      <div><i><br>
                        </i></div>
                      <div>
                        <div><i>entry = cache.get(uri, accept);</i></div>
                        <div><i>if (entry != null) return entry;</i></div>
                        <div><i>if (MediaTypeHelper.isTextLike(accept))</i></div>
                        <div><i>{</i></div>
                        <div><i>      entry = cache.get(uri,
                            accept.withCharset("UTF-8"));</i></div>
                        <div><i>      if (entry != null) return entry;</i></div>
                        <div><i>}</i></div>
                      </div>
                      <div><br>
                      </div>
                      <div>Let's assume that resource returns XML data
                        with Content-Type: application/xml;charset=UTF-8</div>
                      <div>and the client sends Accept: application/xml</div>
                      <div>So the very first request adds into the cache
                        entry for application/xml;charset=UTF-8 because
                        it is taken from Content-Type header.</div>
                      <div><br>
                      </div>
                      <div>Subsequent request gets the cached value
                        (expecting that entry is not expired), although
                        it cannot find it under application/xml, it is
                        found under application/xml;charset=UTF-8
                        because of this:</div>
                      <div><i><br>
                        </i></div>
                      <div><i>cache.get(uri,
                          accept.withCharset("UTF-8"));</i><br>
                      </div>
                      <div><br>
                      </div>
                      <div>The problem is if decide to change the code
                        to use Accept instead of current Content-Type,
                        we can't be sure if there is Accept header in
                        the request and we're not sure about response
                        encoding.<br>
                      </div>
                      <div><br>
                      </div>
                      <div>Also the statement in Jira regarding content
                        type mismatch: like Accept is application/json,
                        but resource returns application/xml and to
                        store it under application/json instead of
                        application/xml is IMHO wrong (coding issue). I
                        believe that it should be stored per actual
                        content type.</div>
                      <div><br>
                      </div>
                      <div>Your thoughts?</div>
                      <div><br>
                      </div>
                      <div>Thanks!</div>
                      <div><br>
                      </div>
                      <div>Cheers,</div>
                      <div>Petr</div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div><br>
                      </div>
                      <div>[1] <a
                          href="https://issues.jboss.org/browse/RESTEASY-2038"
                          moz-do-not-send="true">https://issues.jboss.org/browse/RESTEASY-2038</a><br
                          clear="all">
                        <div><br>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
resteasy-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:resteasy-dev@lists.jboss.org">resteasy-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/resteasy-dev">https://lists.jboss.org/mailman/listinfo/resteasy-dev</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>