我的一些用户使用的是不支持 Cache-Control HTTP header 的旧浏览器。因此,除了确保我的内容在可能的情况下被缓存之外,我还想设置 Expires header 。
我正在使用 Java SDK,我发现 this question也就是说上传时使用ObjectMetadata中的setHeader方法。
这似乎工作正常,但我注意到在 JavaDocs 中它声明 setHeader 方法仅供内部使用。从我自己的代码中调用此方法可能会出现任何问题吗?
最佳答案
This seems to work OK, but I notice that in the JavaDocs it states that the setHeader method is for internal use only. Are there any problems that may arise from calling this method from my own code?
这个有点令人惊讶的问题已经再次出现,请参阅 bkirkbri's comment - 这是 my reply :
Hmmh, I wasn't aware of that restriction indeed, but recall having used Expires: at some point a while back; I might be wrong though, insofar I often use other SDKs for interacting with S3 (e.g. C#/Python, which do definitely support this) and could have mixed that up - the code itself doesn't differ from the other setXYZHeader() methods currently (see ObjectMetadata.java), so the restriction would be based on a non visible side effect, if any.
这似乎仍然成立,即如果您分析代码,则没有任何其他迹象 - 因此,bkirkbri's conclusion似乎正确地总结了事态:
It's probably used by the other header methods internally and internal only because only certain headers will work. They should add a setExpires method on ObjectMetadata as it's the only header that doesn't have it's own method
除此之外,恐怕只有 AWS SDK for Java 团队本身才能提供明确的答案:像往常一样,您可能会在相应的 AWS forum 中询问。 ,但截至最近,他们正在接受移动 GitHub repository 中的问题同样,这可能会为此类与代码相关的问题提供更快、更明确的结果。
关于java - 使用 AWS Java SDK 设置 Expires 和其他杂项 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13792227/