@@ -9,6 +9,7 @@ use codecs::{
9
9
} ;
10
10
11
11
use http:: { StatusCode , Uri } ;
12
+ use http_serde;
12
13
use lookup:: { lookup_v2:: OptionalValuePath , owned_value_path, path} ;
13
14
use tokio_util:: codec:: Decoder as _;
14
15
use vector_config:: configurable_component;
@@ -129,6 +130,13 @@ pub struct SimpleHttpConfig {
129
130
#[ serde( default = "default_http_method" ) ]
130
131
method : HttpMethod ,
131
132
133
+ /// Specifies the HTTP response status code that will be returned on successful requests.
134
+ #[ configurable( metadata( docs:: examples = 202 ) ) ]
135
+ #[ configurable( metadata( docs:: numeric_type = "uint" ) ) ]
136
+ #[ serde( with = "http_serde::status_code" ) ]
137
+ #[ serde( default = "default_http_response_code" ) ]
138
+ response_code : StatusCode ,
139
+
132
140
#[ configurable( derived) ]
133
141
tls : Option < TlsEnableableConfig > ,
134
142
@@ -242,6 +250,7 @@ impl Default for SimpleHttpConfig {
242
250
path : default_path ( ) ,
243
251
path_key : default_path_key ( ) ,
244
252
method : default_http_method ( ) ,
253
+ response_code : default_http_response_code ( ) ,
245
254
strict_path : true ,
246
255
framing : None ,
247
256
decoding : Some ( default_decoding ( ) ) ,
@@ -289,6 +298,10 @@ fn default_path_key() -> OptionalValuePath {
289
298
OptionalValuePath :: from ( owned_value_path ! ( "path" ) )
290
299
}
291
300
301
+ const fn default_http_response_code ( ) -> StatusCode {
302
+ StatusCode :: OK
303
+ }
304
+
292
305
/// Removes duplicates from the list, and logs a `warn!()` for each duplicate removed.
293
306
fn remove_duplicates ( mut list : Vec < String > , list_name : & str ) -> Vec < String > {
294
307
list. sort ( ) ;
@@ -328,6 +341,7 @@ impl SourceConfig for SimpleHttpConfig {
328
341
self . address ,
329
342
self . path . as_str ( ) ,
330
343
self . method ,
344
+ self . response_code ,
331
345
self . strict_path ,
332
346
& self . tls ,
333
347
& self . auth ,
@@ -478,7 +492,7 @@ mod tests {
478
492
Compression ,
479
493
} ;
480
494
use futures:: Stream ;
481
- use http:: { HeaderMap , Method } ;
495
+ use http:: { HeaderMap , Method , StatusCode } ;
482
496
use lookup:: lookup_v2:: OptionalValuePath ;
483
497
use similar_asserts:: assert_eq;
484
498
@@ -506,6 +520,7 @@ mod tests {
506
520
path_key : & ' a str ,
507
521
path : & ' a str ,
508
522
method : & ' a str ,
523
+ response_code : StatusCode ,
509
524
strict_path : bool ,
510
525
status : EventStatus ,
511
526
acknowledgements : bool ,
@@ -529,6 +544,7 @@ mod tests {
529
544
headers,
530
545
encoding : None ,
531
546
query_parameters,
547
+ response_code,
532
548
tls : None ,
533
549
auth : None ,
534
550
strict_path,
@@ -639,6 +655,7 @@ mod tests {
639
655
"http_path" ,
640
656
"/" ,
641
657
"POST" ,
658
+ StatusCode :: OK ,
642
659
true ,
643
660
EventStatus :: Delivered ,
644
661
true ,
@@ -683,6 +700,7 @@ mod tests {
683
700
"http_path" ,
684
701
"/" ,
685
702
"POST" ,
703
+ StatusCode :: OK ,
686
704
true ,
687
705
EventStatus :: Delivered ,
688
706
true ,
@@ -720,6 +738,7 @@ mod tests {
720
738
"http_path" ,
721
739
"/" ,
722
740
"POST" ,
741
+ StatusCode :: OK ,
723
742
true ,
724
743
EventStatus :: Delivered ,
725
744
true ,
@@ -751,6 +770,7 @@ mod tests {
751
770
"http_path" ,
752
771
"/" ,
753
772
"POST" ,
773
+ StatusCode :: OK ,
754
774
true ,
755
775
EventStatus :: Delivered ,
756
776
true ,
@@ -787,6 +807,7 @@ mod tests {
787
807
"http_path" ,
788
808
"/" ,
789
809
"POST" ,
810
+ StatusCode :: OK ,
790
811
true ,
791
812
EventStatus :: Delivered ,
792
813
true ,
@@ -830,6 +851,7 @@ mod tests {
830
851
"http_path" ,
831
852
"/" ,
832
853
"POST" ,
854
+ StatusCode :: OK ,
833
855
true ,
834
856
EventStatus :: Delivered ,
835
857
true ,
@@ -879,6 +901,7 @@ mod tests {
879
901
"http_path" ,
880
902
"/" ,
881
903
"POST" ,
904
+ StatusCode :: OK ,
882
905
true ,
883
906
EventStatus :: Delivered ,
884
907
true ,
@@ -964,6 +987,7 @@ mod tests {
964
987
"http_path" ,
965
988
"/" ,
966
989
"POST" ,
990
+ StatusCode :: OK ,
967
991
true ,
968
992
EventStatus :: Delivered ,
969
993
true ,
@@ -1005,6 +1029,7 @@ mod tests {
1005
1029
"http_path" ,
1006
1030
"/" ,
1007
1031
"POST" ,
1032
+ StatusCode :: OK ,
1008
1033
true ,
1009
1034
EventStatus :: Delivered ,
1010
1035
true ,
@@ -1055,6 +1080,7 @@ mod tests {
1055
1080
"http_path" ,
1056
1081
"/" ,
1057
1082
"POST" ,
1083
+ StatusCode :: OK ,
1058
1084
true ,
1059
1085
EventStatus :: Delivered ,
1060
1086
true ,
@@ -1084,6 +1110,7 @@ mod tests {
1084
1110
"vector_http_path" ,
1085
1111
"/event/path" ,
1086
1112
"POST" ,
1113
+ StatusCode :: OK ,
1087
1114
true ,
1088
1115
EventStatus :: Delivered ,
1089
1116
true ,
@@ -1123,6 +1150,7 @@ mod tests {
1123
1150
"vector_http_path" ,
1124
1151
"/event" ,
1125
1152
"POST" ,
1153
+ StatusCode :: OK ,
1126
1154
false ,
1127
1155
EventStatus :: Delivered ,
1128
1156
true ,
@@ -1182,6 +1210,7 @@ mod tests {
1182
1210
"vector_http_path" ,
1183
1211
"/" ,
1184
1212
"POST" ,
1213
+ StatusCode :: OK ,
1185
1214
true ,
1186
1215
EventStatus :: Delivered ,
1187
1216
true ,
@@ -1196,6 +1225,39 @@ mod tests {
1196
1225
) ;
1197
1226
}
1198
1227
1228
+ #[ tokio:: test]
1229
+ async fn http_status_code ( ) {
1230
+ assert_source_compliance ( & HTTP_PUSH_SOURCE_TAGS , async move {
1231
+ let ( rx, addr) = source (
1232
+ vec ! [ ] ,
1233
+ vec ! [ ] ,
1234
+ "http_path" ,
1235
+ "/" ,
1236
+ "POST" ,
1237
+ StatusCode :: ACCEPTED ,
1238
+ true ,
1239
+ EventStatus :: Delivered ,
1240
+ true ,
1241
+ None ,
1242
+ None ,
1243
+ )
1244
+ . await ;
1245
+
1246
+ spawn_collect_n (
1247
+ async move {
1248
+ assert_eq ! (
1249
+ StatusCode :: ACCEPTED ,
1250
+ send( addr, "{\" key1\" :\" value1\" }" ) . await
1251
+ ) ;
1252
+ } ,
1253
+ rx,
1254
+ 1 ,
1255
+ )
1256
+ . await ;
1257
+ } )
1258
+ . await ;
1259
+ }
1260
+
1199
1261
#[ tokio:: test]
1200
1262
async fn http_delivery_failure ( ) {
1201
1263
assert_source_compliance ( & HTTP_PUSH_SOURCE_TAGS , async {
@@ -1205,6 +1267,7 @@ mod tests {
1205
1267
"http_path" ,
1206
1268
"/" ,
1207
1269
"POST" ,
1270
+ StatusCode :: OK ,
1208
1271
true ,
1209
1272
EventStatus :: Rejected ,
1210
1273
true ,
@@ -1234,6 +1297,7 @@ mod tests {
1234
1297
"http_path" ,
1235
1298
"/" ,
1236
1299
"POST" ,
1300
+ StatusCode :: OK ,
1237
1301
true ,
1238
1302
EventStatus :: Rejected ,
1239
1303
false ,
@@ -1265,6 +1329,7 @@ mod tests {
1265
1329
"http_path" ,
1266
1330
"/" ,
1267
1331
"GET" ,
1332
+ StatusCode :: OK ,
1268
1333
true ,
1269
1334
EventStatus :: Delivered ,
1270
1335
true ,
0 commit comments