All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.ext.web.impl.ParsableHeaderValuesContainer Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.ext.web.impl;

import io.vertx.codegen.annotations.Nullable;
import io.vertx.ext.web.LanguageHeader;
import io.vertx.ext.web.MIMEHeader;
import io.vertx.ext.web.ParsedHeaderValue;
import io.vertx.ext.web.ParsedHeaderValues;

import java.util.Collection;
import java.util.List;

public class ParsableHeaderValuesContainer implements ParsedHeaderValues {

  private final List accept;
  private final List acceptCharset;
  private final List acceptEncoding;
  private final List acceptLanguage;
  private final ParsableMIMEValue contentType;

  public ParsableHeaderValuesContainer(
      List accept, List acceptCharset, List acceptEncoding,
      List acceptLanguage, ParsableMIMEValue contentType) {
    this.accept = accept;
    this.acceptCharset = acceptCharset;
    this.acceptEncoding = acceptEncoding;
    this.acceptLanguage = acceptLanguage;
    this.contentType = contentType;
  }

  @Override
  public List accept() {
    return accept;
  }
  @Override
  public List acceptCharset() {
    return acceptCharset;
  }
  @Override
  public List acceptEncoding() {
    return acceptEncoding;
  }
  @Override
  public List acceptLanguage() {
    return acceptLanguage;
  }
  @Override
  public ParsableMIMEValue contentType() {
    return contentType;
  }

  @Override
  public @Nullable MIMEHeader findBestUserAcceptedIn(List userAccepted, Collection in) {
    for (MIMEHeader acceptableType: userAccepted) {
      MIMEHeader acceptedType = acceptableType.findMatchedBy(in);
      if (acceptedType != null) {
        if ("*".equals(acceptedType.subComponent()) || "*".equals(acceptedType.component()))
          return acceptableType;
        else
          return acceptedType;
      }
    }
    return null;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy