handleHookRequest method

void handleHookRequest(
  1. HttpRequest request
)

Implementation

void handleHookRequest(HttpRequest request) {
  if (request.method != 'POST') {
    request.response
      ..write('Only POST is Supported')
      ..close();
    return;
  }

  if (request.headers.value('X-GitHub-Event') == null) {
    request.response
      ..write('X-GitHub-Event must be specified.')
      ..close();
    return;
  }

  const Utf8Decoder().bind(request).join().then((content) {
    _eventController.add(HookEvent.fromJson(
        request.headers.value('X-GitHub-Event'),
        jsonDecode(content) as Map<String, dynamic>?));
    request.response
      ..write(GitHubJson.encode({'handled': _eventController.hasListener}))
      ..close();
  });
}