HtmlUnitRequestBuilder detects form encoding type
Issue: SPR-14916
This commit is contained in:
parent
cb50f6bc8c
commit
38b6746d3d
|
@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.CookieManager;
|
||||
import com.gargoylesoftware.htmlunit.FormEncodingType;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.WebRequest;
|
||||
import com.gargoylesoftware.htmlunit.util.NameValuePair;
|
||||
|
@ -234,6 +235,12 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
|
|||
|
||||
private void contentType(MockHttpServletRequest request) {
|
||||
String contentType = header("Content-Type");
|
||||
if (contentType == null) {
|
||||
FormEncodingType encodingType = this.webRequest.getEncodingType();
|
||||
if (encodingType != null) {
|
||||
contentType = encodingType.getName();
|
||||
}
|
||||
}
|
||||
request.setContentType(contentType != null ? contentType : MediaType.ALL_VALUE);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -27,6 +27,7 @@ import javax.servlet.ServletContext;
|
|||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.FormEncodingType;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
|
||||
|
@ -150,6 +151,18 @@ public class HtmlUnitRequestBuilderTests {
|
|||
assertThat(actualRequest.getHeader("Content-Type"), equalTo(contentType));
|
||||
}
|
||||
|
||||
@Test // SPR-14916
|
||||
public void buildRequestContentTypeWithFormSubmission() {
|
||||
webRequest.setEncodingType(FormEncodingType.URL_ENCODED);
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getContentType(), equalTo("application/x-www-form-urlencoded"));
|
||||
assertThat(actualRequest.getHeader("Content-Type"),
|
||||
equalTo("application/x-www-form-urlencoded;charset=ISO-8859-1"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void buildRequestContextPathUsesFirstSegmentByDefault() {
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
|
Loading…
Reference in New Issue