@@ -25,13 +25,14 @@ use crate::event;
25
25
use crate :: query:: Query ;
26
26
use crate :: response:: QueryResponse ;
27
27
use crate :: s3:: S3 ;
28
- use crate :: utils:: header_parsing:: collect_labelled_headers;
28
+ use crate :: utils:: header_parsing:: { collect_labelled_headers, ParseHeaderError } ;
29
29
use crate :: utils:: { self , flatten_json_body, merge} ;
30
30
31
31
use self :: error:: { PostError , QueryError } ;
32
32
33
33
const PREFIX_TAGS : & str = "x-p-tag-" ;
34
34
const PREFIX_META : & str = "x-p-meta-" ;
35
+ const STREAM_NAME_HEADER_KEY : & str = "x-p-stream-name" ;
35
36
const SEPARATOR : char = '^' ;
36
37
37
38
pub async fn query ( _req : HttpRequest , json : web:: Json < Value > ) -> Result < HttpResponse , QueryError > {
@@ -48,12 +49,38 @@ pub async fn query(_req: HttpRequest, json: web::Json<Value>) -> Result<HttpResp
48
49
. map_err ( |e| e. into ( ) )
49
50
}
50
51
52
+ pub async fn ingest (
53
+ req : HttpRequest ,
54
+ body : web:: Json < serde_json:: Value > ,
55
+ ) -> Result < HttpResponse , PostError > {
56
+ if let Some ( ( _, stream_name) ) = req
57
+ . headers ( )
58
+ . iter ( )
59
+ . find ( |& ( key, _) | key == STREAM_NAME_HEADER_KEY )
60
+ {
61
+ push_logs ( stream_name. to_str ( ) . unwrap ( ) . to_owned ( ) , req, body) . await ?;
62
+
63
+ Ok ( HttpResponse :: Ok ( ) . finish ( ) )
64
+ } else {
65
+ Err ( PostError :: Header ( ParseHeaderError :: MissingStreamName ) )
66
+ }
67
+ }
68
+
51
69
pub async fn post_event (
52
70
req : HttpRequest ,
53
71
body : web:: Json < serde_json:: Value > ,
54
72
) -> Result < HttpResponse , PostError > {
55
73
let stream_name: String = req. match_info ( ) . get ( "logstream" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
74
+ push_logs ( stream_name, req, body) . await ?;
56
75
76
+ Ok ( HttpResponse :: Ok ( ) . finish ( ) )
77
+ }
78
+
79
+ async fn push_logs (
80
+ stream_name : String ,
81
+ req : HttpRequest ,
82
+ body : web:: Json < serde_json:: Value > ,
83
+ ) -> Result < ( ) , PostError > {
57
84
let tags = HashMap :: from ( [ (
58
85
"p_tags" . to_string ( ) ,
59
86
collect_labelled_headers ( & req, PREFIX_TAGS , SEPARATOR ) ?,
@@ -89,7 +116,7 @@ pub async fn post_event(
89
116
event. process ( ) . await ?;
90
117
}
91
118
92
- Ok ( HttpResponse :: Ok ( ) . finish ( ) )
119
+ Ok ( ( ) )
93
120
}
94
121
95
122
pub mod error {
0 commit comments