init static method
Initializes a RSP page.
- It is used by generated RSP dart code. You don't need to invoke it.
- It returns false if the content shall not be generated.
- The caller shall stop immediately if this method returns false.
-
contentType
- ignored if null or empty.
Implementation
static bool init(HttpConnect connect, String? contentType,
{DateTime? lastModified, String? etag}) {
if (!connect.isIncluded) {
final response = connect.response;
final headers = response.headers;
if (contentType != null && contentType.isNotEmpty)
headers.contentType = parseContentType(contentType);
bool isPreconditionFailed = false;
if (etag != null || lastModified != null) {
if (!checkIfHeaders(connect, lastModified, etag))
return false;
isPreconditionFailed = response.statusCode == HttpStatus.preconditionFailed;
//Set by checkIfHeaders (see also Issue 59)
if (isPreconditionFailed || response.statusCode < HttpStatus.badRequest) {
if (lastModified != null)
headers.set(HttpHeaders.lastModifiedHeader, lastModified);
if (etag != null)
headers.set(HttpHeaders.etagHeader, etag);
}
}
if (connect.request.method == "HEAD" || isPreconditionFailed)
return false; //no more processing
}
return true;
}