Return Accept header based on an array of accepts provided.
 @param [Array] accepts array for Accept
 @return [String] the Accept header (e.g. application/json)
978366
def select_header_accept(accepts)
      if accepts.empty?
        return
      elsif accepts.any?{ |s| s.casecmp('application/json') == 0 }
        'application/json' # look for json data by default
      else
        accepts.join(',')
      end
    end
284415
def get(name)
      name = normalize_header name.to_s
      @pile.select { |k, _| k == name }.map { |_, v| v }
    end
921159
private static boolean accepts(String acceptHeader, String toAccept) {
        String[] acceptValues = acceptHeader.split("\\s*(,|;)\\s*");
        Arrays.sort(acceptValues);
        return Arrays.binarySearch(acceptValues, toAccept) > -1
                || Arrays.binarySearch(acceptValues, toAccept.replaceAll("/.*$", "/*")) > -1
                || Arrays.binarySearch(acceptValues, "*/*") > -1;
    }
902034
def validate_headers!(response)
      return unless headers
      headers.each do |name, value|
        if name.is_a? Symbol
          raise Exceptions::Validation.new(
            "Symbols are not supported in headers"
          )
        end

        unless response.headers.has_key?(name)
          raise Exceptions::Validation.new(
            "Header #{name.inspect} was required but is missing"
          )
        end

        case value
        when String
          if response.headers[name] != value
            raise Exceptions::Validation.new(
              "Header #{name.inspect}, with value #{value.inspect} does not match #{response.headers[name]}."
            )
          end
        when Regexp
          if response.headers[name] !~ value
            raise Exceptions::Validation.new(
              "Header #{name.inspect}, with value #{value.inspect} does not match #{response.headers[name].inspect}."
            )
          end
        end
      end
    end
1353282
def get(path, headers = {})
      response = super(path, { 'Accept' => ACCEPT }.merge(headers.to_h))
      case response.content_type
      when CONTENT_TYPE then [parse_response(response), response]
      else raise "Unknown content type #{response.content_type.inspect}"
      end
    end
485585
public static function getAccept(): array
    {
        if (!self::$accept) {
            // get header from request
            self::$accept = self::parseAcceptHeader(self::getHeader('Accept'));
        }
        return self::$accept;
    }
1155575
def parse_accept_header(accept):
    

    def parse_media_range(accept_item):
        """ Parse media range and subtype """

        return accept_item.split('/', 1)

    def comparator(a, b):
        """ Compare accept items a and b """

        # first compare q values
        result = -cmp(a[2], b[2])
        if result is not 0:
            # q values differ, no need to compare media types
            return result

        # parse media types and compare them (asterisks are lower in precedence)
        mtype_a, subtype_a = parse_media_range(a[0])
        mtype_b, subtype_b = parse_media_range(b[0])
        if mtype_a == '*' and subtype_a == '*':
            return 1
        if mtype_b == '*' and subtype_b == '*':
            return -1
        if subtype_a == '*':
            return 1
        if subtype_b == '*':
            return -1
        return 0

    if not accept:
        return []

    result = []
    for media_range in accept.split(","):
        parts = media_range.split(";")
        media_type = parts.pop(0).strip()
        media_params = []
        q = 1.0
        for part in parts:
            (key, value) = part.lstrip().split("=", 1)
            if key == "q":
                q = float(value)
            else:
                media_params.append((key, value))
        result.append((media_type, tuple(media_params), q))
    result.sort(comparator)
    return result
102115
public Request accept(String headerValue){
        final String accept = RequestHeaderFields.ACCEPT.getName();
        String acceptValue = headers.get(accept);
        if (acceptValue == null){
            acceptValue = headerValue;
        } else {
            acceptValue = acceptValue + ", " + headerValue;
        }
        return this.setHeader(accept, acceptValue);
    }
584531
def accepts(self):  # type: Union[Iterable[Type[T]], Type[Any]]
        """"""
        types = set()
        any_dispatch = False
        try:
            types.update(getattr(self.__class__, "put")._accepts)
            any_dispatch = True
        except AttributeError:
            pass
        try:
            types.update(getattr(self.__class__, "put_many")._accepts)
            any_dispatch = True
        except AttributeError:
            pass
        return types if any_dispatch else TYPE_WILDCARD
1333943
async def accept(
            self,
            headers: Optional[Union[dict, CIMultiDict, Headers]] = None,
            subprotocol: Optional[str] = None,
    ) -> None:
        
        if headers is None:
            headers_ = Headers()
        else:
            headers_ = Headers(headers)
        await self._accept(headers_, subprotocol)
238264
def accept(visitor)
      visitor.visit(self)
      if @children
        visitor.before_children if visitor.respond_to?(:before_children)
        @children.each { |c| c.accept(visitor) }
        visitor.after_children if visitor.respond_to?(:after_children)
      end
    end
843620
def normalize_header(name)
      return name if name =~ CANONICAL_NAME_RE

      normalized = name.split(/[\-_]/).each(&:capitalize!).join("-")

      return normalized if normalized =~ COMPLIANT_NAME_RE

      raise HeaderError, "Invalid HTTP header field name: #{name.inspect}"
    end
1360931
protected function getAcceptHeader(Request $request): Accept
	{
		$headerName = 'Accept';
		$headerLine = '*/*';
		if ($request->hasHeader($headerName))
		{
			$headerLine = $request->getHeaderLine($headerName);
		}
		try
		{
			return Accept::fromString($headerName . ': ' . $headerLine);
		}
		catch (\Exception $e)
		{
			throw new Exception\BadRequest('Invalid Accept header', $e);
		}
	}
759857
def parse_http_accept_header(header):
    
    components = [item.strip() for item in header.split(',')]

    l = []
    for component in components:
        if ';' in component:
            subcomponents = [item.strip() for item in component.split(';')]
            l.append(
                (
                    subcomponents[0], # eg. 'text/html'
                    subcomponents[1][2:] # eg. 'q=0.9'
                )
            )
        else:
            l.append((component, '1'))

    l.sort(
        key = lambda i: i[1],
        reverse = True
    )

    content_types = []
    for i in l:
        content_types.append(i[0])

    return content_types
832453
def process_header(raw)
      # this util gives us arrays of values. We are only set up to handle one header value.
      WEBrick::HTTPUtils.parse_header(raw.strip).map.inject({}) do |h,(k,v)|
        h[k]=v.first; h
      end
    end
1302393
public function getBestFormat($accept, $supported)
    {
        // Parse the accept header
        $parts = $this->parseHeader($accept);

        // Sort the array based on
        $parts = $this->sortParts($parts);

        // Loop through the array
        foreach ($parts as $part) {
            // Check if mime type is $supported
            if (in_array($part['value'], $supported)) {
                // Return the mime type
                return $part;
            }

            // Match for example image/*
            if (substr($part['value'], -2) === '/*') {
                // Get the type
                $range = substr($part['value'], 0, -2);

                // Look if type is found in $supported
                foreach ($supported as $support) {
                    if (strpos($support, $range, 0) === 0) {
                        $part['value'] = $support;
                        return $part;
                    }
                }
            }

            // Check if accepts anything
            if ($part['value'] === '*/*') {
                return $this->acceptsAnything($part['quality'], $supported);
            }
        }

        // Return null if no match is found
        return null;
    }
766252
def server_extensions_handshake(requested, supported):
    # type: (List[str], List[Extension]) -> Optional[bytes]
    
    accepts = {}
    for offer in requested:
        name = offer.split(";", 1)[0].strip()
        for extension in supported:
            if extension.name == name:
                accept = extension.accept(offer)
                if accept is True:
                    accepts[extension.name] = True
                elif accept is not False and accept is not None:
                    accepts[extension.name] = accept.encode("ascii")

    if accepts:
        extensions = []
        for name, params in accepts.items():
            if params is True:
                extensions.append(name.encode("ascii"))
            else:
                # py34 annoyance: doesn't support bytestring formatting
                params = params.decode("ascii")
                if params == "":
                    extensions.append(("%s" % (name)).encode("ascii"))
                else:
                    extensions.append(("%s; %s" % (name, params)).encode("ascii"))
        return b", ".join(extensions)

    return None