<div dir="ltr">Yep, this will and actually this was the original idea to use Accept instead of Content-Type. But I had some doubts if this is good solution.<div><br></div><div>Let me sum it up what I want to do:</div><div>Use Accept if present, if not use Content-Type. Charset will not be taken into account.</div><div><br></div><div>Note: as an example, Content-Type is application/xml and Accept is application/json, so it will be stored with application/json, but the real content is XML. This is my main concern.</div><div><br></div><div>Cheers,</div><div>Petr</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 22, 2018 at 4:53 AM Jim Ma &lt;<a href="mailto:ema@redhat.com">ema@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <div class="m_2682786173733405280moz-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">
      <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&#39;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(&quot;UTF-8&quot;));</i></div>
                        <div><i>      if (entry != null) return entry;</i></div>
                        <div><i>}</i></div>
                      </div>
                      <div><br>
                      </div>
                      <div>Let&#39;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(&quot;UTF-8&quot;));</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&#39;t be sure if there is Accept header in
                        the request and we&#39;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" target="_blank">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="m_2682786173733405280mimeAttachmentHeader"></fieldset>
      <br>
      <pre>_______________________________________________
resteasy-dev mailing list
<a class="m_2682786173733405280moz-txt-link-abbreviated" href="mailto:resteasy-dev@lists.jboss.org" target="_blank">resteasy-dev@lists.jboss.org</a>
<a class="m_2682786173733405280moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/resteasy-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/resteasy-dev</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </div>

</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><p style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-weight:bold;margin:0px;padding:0px;font-size:14px;text-transform:uppercase"><span>PETR</span> <span>JURAK</span></p><p style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:10px;margin:0px 0px 4px;text-transform:uppercase"><span>SENIOR SOFTWARE ENGINEER</span><span style="color:rgb(170,170,170);margin:0px"></span></p><p style="font-family:overpass,sans-serif;margin:0px;font-size:10px;color:rgb(153,153,153)"><a href="https://www.redhat.com/" style="color:rgb(0,136,206);margin:0px" target="_blank">Red Hat <span><br><br></span></a></p><p style="font-family:overpass,sans-serif;margin:0px 0px 6px;font-size:10px;color:rgb(153,153,153)"></p><table border="0" style="color:rgb(0,0,0);font-family:overpass,sans-serif;font-size:medium"><tbody><tr><td width="100px"><a href="https://red.ht/sig" target="_blank"><img src="https://www.redhat.com/files/brand/email/sig-redhat.png" width="90" height="auto"></a></td><td style="font-size:10px"><div><a href="https://redhat.com/trusted" style="color:rgb(204,0,0);font-weight:bold" target="_blank">TRIED. TESTED. TRUSTED.</a></div></td></tr></tbody></table></div></div></div></div></div>