@@ -136,11 +136,10 @@ pub trait RequestHelper {
136
136
/// Issue a PUT request
137
137
async fn put < T > ( & self , path : & str , body : impl Into < Bytes > ) -> Response < T > {
138
138
let body = body. into ( ) ;
139
- let is_json = body. starts_with ( b"{" ) && body. ends_with ( b"}" ) ;
140
139
141
140
let mut request = self . request_builder ( Method :: PUT , path) ;
142
141
* request. body_mut ( ) = body;
143
- if is_json {
142
+ if is_json_body ( request . body ( ) ) {
144
143
request. header ( header:: CONTENT_TYPE , "application/json" ) ;
145
144
}
146
145
@@ -150,11 +149,10 @@ pub trait RequestHelper {
150
149
/// Issue a PATCH request
151
150
async fn patch < T > ( & self , path : & str , body : impl Into < Bytes > ) -> Response < T > {
152
151
let body = body. into ( ) ;
153
- let is_json = body. starts_with ( b"{" ) && body. ends_with ( b"}" ) ;
154
152
155
153
let mut request = self . request_builder ( Method :: PATCH , path) ;
156
154
* request. body_mut ( ) = body;
157
- if is_json {
155
+ if is_json_body ( request . body ( ) ) {
158
156
request. header ( header:: CONTENT_TYPE , "application/json" ) ;
159
157
}
160
158
@@ -170,11 +168,10 @@ pub trait RequestHelper {
170
168
/// Issue a DELETE request with a body... yes we do it, for crate owner removal
171
169
async fn delete_with_body < T > ( & self , path : & str , body : impl Into < Bytes > ) -> Response < T > {
172
170
let body = body. into ( ) ;
173
- let is_json = body. starts_with ( b"{" ) && body. ends_with ( b"}" ) ;
174
171
175
172
let mut request = self . request_builder ( Method :: DELETE , path) ;
176
173
* request. body_mut ( ) = body;
177
- if is_json {
174
+ if is_json_body ( request . body ( ) ) {
178
175
request. header ( header:: CONTENT_TYPE , "application/json" ) ;
179
176
}
180
177
@@ -260,6 +257,11 @@ fn req(method: Method, path: &str) -> MockRequest {
260
257
. unwrap ( )
261
258
}
262
259
260
+ fn is_json_body ( body : & Bytes ) -> bool {
261
+ ( body. starts_with ( b"{" ) && body. ends_with ( b"}" ) )
262
+ || ( body. starts_with ( b"[" ) && body. ends_with ( b"]" ) )
263
+ }
264
+
263
265
/// A type that can generate unauthenticated requests
264
266
pub struct MockAnonymousUser {
265
267
app : TestApp ,
0 commit comments