Add easy way to set date header.
See original GitHub issueI want to put the date header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date) on all my requests.
static final ThreadLocal<DateFormat> DATE_HEADER_FORMAT =
new ThreadLocal<DateFormat>() {
@Override protected DateFormat initialValue() {
DateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format;
}
};
...
requestBuilder.addHeader("Date", DATE_HEADER_FORMAT.get().format(new Date())
I’d like to remove this code in favor of perhaps okhttp3.Headers.setDate(Date)
.
The downside is that it opens up discussion about other general headers that could be added to the Headers API. Is this general-purpose enough?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Insert the date or time into a header or footer - Microsoft Support
From the Header & Footer Ribbon menu, click Insert Date or Insert Time. You can also insert the Page Number, Number of Pages,...
Read more >how to set "Date" header for http request - Stack Overflow
From a XMLHttpRequest, there are a set of headers that cannot be set. Take a look at the spec for setRequestHeader(). Date is...
Read more >How to specify date or datetime format in header or footer?
2. Hold down the ALT + F11 keys in Excel to open the Microsoft Visual Basic for Applications window. 3. Click Insert >...
Read more >How to add date and time in header or footer in Microsoft word?
In this video we will learn that how to add date and time in header or footer in Microsoft word?✓Microsoft | MS Word...
Read more >How To Insert Date and Time Using Header or Footer ...
How To Insert Date and Time Using Header or Footer in MS Word | Add Date In Header in Microsoft Word This tutorial...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we’ve opened the door to java.time overloads, kicked off in OkHttpClient.
@jjshanks if you’d like to add more overloads, please do!
+1 I think OkHttp could usefully provide constants and formatters for more headers. Would it be worth a sweep through https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers?
Date is also pretty common in responses.