Use the character encoding of the request or UTF-8 if no character encoding is available for decoding the request body of a web hook (fixes #308)
This commit is contained in:
parent
358b4f229f
commit
32cd71c119
|
@ -22,6 +22,7 @@ import org.kohsuke.stapler.StaplerRequest;
|
|||
import org.kohsuke.stapler.StaplerResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -29,6 +30,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.dabsquared.gitlabjenkins.util.LoggerUtil.toArray;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* @author Robin Müller
|
||||
|
@ -103,7 +105,8 @@ public class ActionResolver {
|
|||
private String getRequestBody(StaplerRequest request) {
|
||||
String requestBody;
|
||||
try {
|
||||
requestBody = IOUtils.toString(request.getInputStream());
|
||||
Charset charset = request.getCharacterEncoding() == null ? UTF_8 : Charset.forName(request.getCharacterEncoding());
|
||||
requestBody = IOUtils.toString(request.getInputStream(), charset);
|
||||
} catch (IOException e) {
|
||||
throw HttpResponses.error(500, "Failed to read request body");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue