Analyze API returns in YAML format if analyzed string begins with ---

fixes #2624
This commit is contained in:
Shay Banon 2013-03-01 22:17:09 +01:00
parent 9b68e98ea2
commit 2eea99255d
2 changed files with 6 additions and 2 deletions

View File

@ -76,7 +76,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
@Override @Override
public void onResponse(AnalyzeResponse response) { public void onResponse(AnalyzeResponse response) {
try { try {
XContentBuilder builder = restContentBuilder(request); XContentBuilder builder = restContentBuilder(request, false);
builder.startObject(); builder.startObject();
response.toXContent(builder, request); response.toXContent(builder, request);
builder.endObject(); builder.endObject();

View File

@ -35,10 +35,14 @@ import java.io.IOException;
public class RestXContentBuilder { public class RestXContentBuilder {
public static XContentBuilder restContentBuilder(RestRequest request) throws IOException { public static XContentBuilder restContentBuilder(RestRequest request) throws IOException {
return restContentBuilder(request, true);
}
public static XContentBuilder restContentBuilder(RestRequest request, boolean autoDetect) throws IOException {
XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type"))); XContentType contentType = XContentType.fromRestContentType(request.param("format", request.header("Content-Type")));
if (contentType == null) { if (contentType == null) {
// try and guess it from the body, if exists // try and guess it from the body, if exists
if (request.hasContent()) { if (autoDetect && request.hasContent()) {
contentType = XContentFactory.xContentType(request.content()); contentType = XContentFactory.xContentType(request.content());
} }
} }