- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Spring 的 RestTemplate 获取 HTTP header 。
HTTP headers are case insensitive ,但是 documentation for HttpHeaders似乎不承认这一点。
快速测试表明一切按预期工作......
HttpHeaders headers = restTemplate.headForHeaders(url);
Long a = Long.parseLong(headers.getFirst("Content-Length"));
Long b = Long.parseLong(headers.getFirst("content-length"));
assert( a.equals(b) ); // passes
我能确定这个测试在所有 Spring 配置下都能通过吗?
最佳答案
根据 this commit明确指出 HttpHeaders
不区分大小写:
Note that
HttpHeaders
generally treats header names in a case-insensitive manner.
旧答案
HttpHeaders
只有一个公共(public)构造函数及其主体:
public HttpHeaders() {
this(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH), false);
}
并根据LinkedCaseInsensitiveMap
docs :
LinkedHashMap variant that stores String keys in a case-insensitive manner, for example for key-based access in a results table.
Preserves the original order as well as the original casing of keys, while allowing for contains, get and remove calls with any case of key.
是的,它始终以不区分大小写的方式工作。
但为什么你不使用 HttpHeaders#getContentLength() ? :
// no need to convert String to long
long contentLength = httpHeaders.getContentLength();
关于java - HttpHeaders getFirst() 不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52224422/
我正在使用 Spring 的 RestTemplate 获取 HTTP header 。 HTTP headers are case insensitive ,但是 documentation for
本文整理了Java中org.zeromq.ZMsg.getFirst()方法的一些代码示例,展示了ZMsg.getFirst()的具体用法。这些代码示例主要来源于Github/Stackoverflo
这更像是一个设计层面的问题。我有一个持久类,它通过 SQL 查询从数据库中查询记录,并通过一个名为 getNext() 的成员函数返回给调用者,该函数的签名如下: int getNext(); //
Iterables为 getLast 提供两种方法 public static T getLast(Iterable iterable); public static T getLast(It
query.getFirst() 真正返回什么? Retrieves at most one ParseObject that satisfies this query. Uses the netwo
我是一名业余程序员,我正在尝试在 java 中创建一个方法,该方法允许我返回数组列表中名字首字母相同的所有内容。使用这样的代码,我不断收到错误“无法在原始类型 char 上调用 getFirst()”
LinkedList element() 方法和 getFirst() 方法有类似的描述(奇怪的是 - 不是同一个词)。 Deque明确指出这两种方法在返回值和异常方面是相同的。 我的问题是 - 为什
这是我的代码: public class FlightMap implements FlightMapInterface { LinkedList cityList = new LinkedList(
这个问题在这里已经有了答案: Why there is no getFirst(iterable) method? (2 个回答) 关闭6年前. 来自 Google Guava JavaDoc for
我是一名优秀的程序员,十分优秀!