Request constructor

Request(
  1. HttpRequest hReq,
  2. String id,
  3. Server server
)

Constructor

Creates a Woomera Request from a HttpRequest.

This is only used internally, when the Woomera server receives a HTTP request.

Implementation

Request(HttpRequest hReq, String id, Server server)
    : _id = id,
      _server = server,
      _coreRequest = _CoreRequestReal(hReq),
      _coreResponse = _CoreResponseReal(hReq.response) {
  _logRequest.fine(
      '[$id] ${_coreRequest.method} ${_coreRequest.internalPath(server._basePath)}');

  _logRequestHeader.finer(() {
    // Log request
    final buf = StringBuffer('[$id] HTTP headers:');
    _coreRequest.headers.forEach((name, values) {
      buf.write('\n  $name: ');
      if (values.isEmpty) {
        buf.write('<noValue>');
      } else if (values.length == 1) {
        buf.write('${values[0]}');
      } else {
        var index = 1;
        for (var v in values) {
          buf.write('\n  [${index++}] $v');
        }
      }
    });
    return buf.toString();
  });

  // Check length of URI does not exceed limits

  var length = hReq.uri.path.length;

  if (hReq.uri.hasQuery) {
    length += hReq.uri.query.length;
  }

  if (hReq.uri.hasFragment) {
    length += hReq.uri.fragment.length;
  }

  if (server.urlMaxSize < length) {
    throw PathTooLongException();
  }

  // Set queryParams from the request
  // Do not use uri.queryParams, because it does not handle repeating keys.

  queryParams = RequestParams._fromQueryString(hReq.uri.query);

  // Determine method used for maintaining (future) sessions

  if (_coreRequest.cookies.isNotEmpty) {
    _sessionUsingCookies = true; // got cookies, so browser must support them
  } else {
    // Cannot detect from HTTP request whether cookies are supported or not.
    // Use default setting from server.
    _sessionUsingCookies = _server.sessionCookieAlways;
  }

  _constructorCommon();
}