question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add easy way to set date header.

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
swankjessecommented, Nov 3, 2018

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!

1reaction
yschimkecommented, Mar 13, 2018

+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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found