MCPcopy Create free account
hub / github.com/alibaba/loongcollector / ServeHTTP

Method ServeHTTP

plugins/input/httpserver/input_http_server.go:140–206  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

138}
139
140func (s *ServiceHTTP) ServeHTTP(w http.ResponseWriter, r *http.Request) {
141 if r.ContentLength > s.MaxBodySize {
142 TooLarge(w)
143 return
144 }
145 data, statusCode, err := s.decoder.ParseRequest(w, r, s.MaxBodySize)
146 logger.Debugf(s.context.GetRuntimeContext(), "request [method] %v; [header] %v; [url] %v; [body len] %d", r.Method, r.Header, r.URL, len(data))
147 switch statusCode {
148 case http.StatusBadRequest:
149 BadRequest(w)
150 case http.StatusRequestEntityTooLarge:
151 TooLarge(w)
152 case http.StatusInternalServerError:
153 InternalServerError(w)
154 case http.StatusMethodNotAllowed:
155 MethodNotAllowed(w)
156 }
157 if err != nil {
158 logger.Warning(s.context.GetRuntimeContext(), selfmonitor.ReadBodyFailAlarm, "read body failed", err, "request", r.URL.String())
159 return
160 }
161
162 if s.dumper != nil {
163 s.dumper.InputChannel() <- &helper.DumpData{
164 Req: helper.DumpDataReq{
165 Body: data,
166 URL: r.URL.String(),
167 Header: r.Header,
168 },
169 }
170 }
171 switch s.version {
172 case v1:
173 logs, err := s.decoder.Decode(data, r, s.Tags)
174 if err != nil {
175 logger.Warning(s.context.GetRuntimeContext(), selfmonitor.DecodeBodyFailAlarm, "decode body failed", err, "request", r.URL.String())
176 BadRequest(w)
177 return
178 }
179 for _, log := range logs {
180 s.collector.AddRawLog(log)
181 }
182 case v2:
183 groups, err := s.decoder.DecodeV2(data, r)
184 if err != nil {
185 logger.Warning(s.context.GetRuntimeContext(), selfmonitor.DecodeBodyFailAlarm, "decode body failed", err, "request", r.URL.String())
186 BadRequest(w)
187 return
188 }
189 if reqParams := s.extractRequestParams(r); len(reqParams) != 0 {
190 for _, g := range groups {
191 g.Group.Metadata.Merge(models.NewMetadataWithMap(reqParams))
192 }
193 }
194 s.collectorV2.CollectList(groups...)
195 }
196
197 switch s.Format {

Callers

nothing calls this directly

Calls 15

extractRequestParamsMethod · 0.95
DebugfFunction · 0.92
WarningFunction · 0.92
NewMetadataWithMapFunction · 0.92
TooLargeFunction · 0.85
BadRequestFunction · 0.85
InternalServerErrorFunction · 0.85
MethodNotAllowedFunction · 0.85
InputChannelMethod · 0.80
ParseRequestMethod · 0.65
GetRuntimeContextMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected