handleServiceRequest method

Future handleServiceRequest(
  1. HttpRequest request
)

Implementation

Future handleServiceRequest(HttpRequest request) async {
  var name = request.uri.pathSegments.last;
  if (name.endsWith(".xml")) {
    name = name.substring(0, name.length - 4);
  }
  var service = device.findService(name);

  if (service == null) {
    service = device.findService(Uri.decodeComponent(name));
  }

  if (service == null) {
    request.response
      ..statusCode = HttpStatus.notFound
      ..close();
  } else {
    var xml = service.toXml();
    request.response
      ..headers.contentType = _xmlType
      ..writeln(xml)
      ..close();
  }
}