Skip to content

ContentNegotiationManager not finding media type when request includes quality parameter #35754

@eric-milles

Description

@eric-milles

Given a basic configuration for content negotiation:

    <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"
      p:favorPathExtension="false" p:mediaTypes-ref="negotiableMediaTypes"
    />
    <util:properties id="negotiableMediaTypes">
        <prop key="fo">application/fo+xml</prop>
        <prop key="json">application/json</prop>
        <prop key="xml">text/xml</prop>
    </util:properties>

When a request comes in with several media types, like "text/xml;q=0.8, application/xml;q=0.7, ..." the content negotiation manager's default org.springframework.web.accept.MappingMediaTypeFileExtensionResolver fails to connect "text/xml;q=0.8" to "text/xml" within resolveFileExtensions(MediaType).

The map lookup uses the MediaType with the quality parameter. MediaType's equals is implemented in MimeType:

	public boolean equals(@Nullable Object other) {
		return (this == other || (other instanceof MimeType otherType &&
				this.type.equalsIgnoreCase(otherType.type) &&
				this.subtype.equalsIgnoreCase(otherType.subtype) &&
				parametersAreEqual(otherType))); // XXX
	}

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions