createHeaderVar function

Expression createHeaderVar(
  1. BaseParameterAnnotation annotation,
  2. ServerParam param
)

Implementation

Expression createHeaderVar(
  BaseParameterAnnotation annotation,
  ServerParam param,
) {
  if (annotation is! ServerHeaderAnnotation) {
    throw ArgumentError('Invalid annotation type: ${annotation.runtimeType}');
  }

  var headersRef = refer('context').property('request').property('headers');

  if (annotation.all) {
    headersRef = headersRef.property('getAll');
  } else {
    headersRef = headersRef.property('get');
  }

  return headersRef.call([literalString(annotation.name ?? param.name)]);
}