1
1
/*
2
- * Copyright 2013, 2014 Deutsche Nationalbibliothek
2
+ * Copyright 2013, 2022 Deutsche Nationalbibliothek et al
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 the "License";
5
5
* you may not use this file except in compliance with the License.
@@ -54,14 +54,14 @@ public final class HttpOpener extends DefaultObjectPipe<String, ObjectReceiver<R
54
54
55
55
private static final String ACCEPT_HEADER = "accept" ;
56
56
private static final String ENCODING_HEADER = "accept-charset" ;
57
-
58
57
private static final String ACCEPT_DEFAULT = "*/*" ;
58
+ private static final String CONTENT_TYPE_HEADER = "content-Type" ;
59
+ private static final String CONTENT_TYPE_DEFAULT = "application/json" ;
59
60
private static final String ENCODING_DEFAULT = "UTF-8" ;
60
-
61
61
private static final String INPUT_DESIGNATOR = "@-" ;
62
+ private static final String DEFAULT_PREFIX = "ERROR: " ;
62
63
63
64
private static final Method DEFAULT_METHOD = Method .GET ;
64
- private static final String DEFAULT_PREFIX = "ERROR: " ;
65
65
66
66
private final Map <String , String > headers = new HashMap <>();
67
67
@@ -98,6 +98,7 @@ private boolean getInputAsBody() {
98
98
*/
99
99
public HttpOpener () {
100
100
setAccept (ACCEPT_DEFAULT );
101
+ setContentType (CONTENT_TYPE_DEFAULT );
101
102
setEncoding (ENCODING_DEFAULT );
102
103
setErrorPrefix (DEFAULT_PREFIX );
103
104
setMethod (DEFAULT_METHOD );
@@ -124,6 +125,16 @@ public void setBody(final String body) {
124
125
this .body = body ;
125
126
}
126
127
128
+ /**
129
+ * Sets the HTTP content type header. This is a mime-type such as text/plain,
130
+ * text/html. The default is application/json.
131
+ *
132
+ * @param contentType mime-type to use for the HTTP contentType header
133
+ */
134
+ public void setContentType (final String contentType ) {
135
+ setHeader (CONTENT_TYPE_HEADER , contentType );
136
+ }
137
+
127
138
/**
128
139
* Sets the preferred encoding of the HTTP response. This value is in the
129
140
* accept-charset header. Additonally, the encoding is used for reading the
0 commit comments