Description
This issue was originally filed by @seaneagan
Currently the Http[Client]{Request,Response} interfaces all have:
Map get headers();
int get contentLength();
bool get keepAlive();
There is a bunch of other header-specific functionality which would be useful to add as well:
* more dedicated fields for specific headers, especially those which represent Dates, Durations, ints, Cookies, MimeTypes, Links, etc.
- static constants for standard header names
- helper functions to convert to and from http dates etc.
Thus it seems to deserve its own dedicated interface, which might look something like...
interface HttpHeaders extends MultiMap<String, String> {
// helper methods for converting to and from http dates
static String fromDate(Date date);
static Date toDate(String headerValue);
bool keepAlive; // Keep-Alive
int contentLength; // Content-Length
// additional useful header fields
MimeType contentType; // Content-Type
bool noCache; // Cache-Control : no-cache / Pragma: no-cache
Date date; // Date
List<Cookie>cookies; // Cookie / Set-Cookie
}
Many headers though, are request-specific or response-specific, so there probably should be dedicated interfaces for each...
interface HttpResponseHeaders extends HttpHeaders {
// valid request header names
static final String AGE/* = 'Age'/;
//...
static final String CONTENT_LENGTH/ = 'Content-Length'*/;
//...
Duration age; // Age
Duration maxAge; // Max-Age
Duration retryAfter; // Retry-After
Date lastModified; // Last-Modified
Date expires; // Expires
String fileName; // Content-Disposition: attachment; filename= ...
List<Link> links; // Link
}
interface HttpRequestHeaders {
// valid request header names
static final String ACCEPT/* = 'Accept'/;
//...
static final String CONTENT_LENGTH/ = 'Content-Length'*/;
//...
Date ifModifiedSince; // If-Modified-Since
int maxForwards; // Max-Forwards
List<MimeType> accept; // Accept
}
These could then be surfaced as follows...
interface HttpRequest {
//...
final HttpRequestHeaders headers;
}
interface HttpClientRequest {
//...
HttpRequestHeaders headers;
}
interface HttpResponse {
//...
final HttpResponseHeaders headers;
}
interface HttpClientResponse {
//...
HttpResponseHeaders headers;
}