@@ -100,7 +100,7 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
100
100
DBObject content ;
101
101
102
102
if (isNotFormData (contentTypes )) { // json or hal+json
103
- final String contentString = ChannelReader .read (exchange .getRequestChannel ());
103
+ final String contentString = workaroundAngularJSIssue1463 ( ChannelReader .read (exchange .getRequestChannel () ));
104
104
105
105
try {
106
106
content = (DBObject ) JSON .parse (contentString );
@@ -142,11 +142,11 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
142
142
ResponseHelper .endExchangeWithMessage (exchange , HttpStatus .SC_NOT_ACCEPTABLE , errMsg );
143
143
return ;
144
144
}
145
-
145
+
146
146
File file = data .getFirst (fileFieldName ).getFile ();
147
147
148
148
context .setFile (file );
149
-
149
+
150
150
injectContentTypeFromFile (content , file );
151
151
}
152
152
@@ -171,6 +171,20 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
171
171
getNext ().handleRequest (exchange , context );
172
172
}
173
173
174
+ /**
175
+ * need this to workaroung angularjs issue
176
+ * https://github.com/angular/angular.js/issues/1463
177
+ *
178
+ * @param content
179
+ * @return
180
+ */
181
+ private static String workaroundAngularJSIssue1463 (String contentString ) {
182
+ if (contentString == null )
183
+ return null ;
184
+
185
+ return contentString .replaceAll ("\" €oid\" *:" , "\" \\ $oid\" :" );
186
+ }
187
+
174
188
/**
175
189
*
176
190
* @param contentTypes
@@ -215,22 +229,24 @@ private void filterOutReservedKeys(DBObject content, RequestContext context) {
215
229
context .addWarning ("the reserved field " + keyToRemove + " was filtered out from the request" );
216
230
});
217
231
}
218
-
232
+
219
233
private void injectContentTypeFromFile (DBObject content , File file ) throws IOException {
220
- if (content .get ("contentType" ) != null )
234
+ if (content .get ("contentType" ) != null ) {
221
235
return ;
222
-
236
+ }
237
+
223
238
String contentType ;
224
-
225
- if (file == null )
239
+
240
+ if (file == null ) {
226
241
return ;
227
- else
242
+ } else {
228
243
contentType = detectMediaType (file );
229
-
244
+ }
245
+
230
246
if (content == null && contentType != null ) {
231
247
content = new BasicDBObject ();
232
- }
233
-
248
+ }
249
+
234
250
content .put ("contentType" , contentType );
235
251
}
236
252
0 commit comments