MCPcopy Create free account
hub / github.com/erpc/erpc / createRequestHandler

Method createRequestHandler

erpc/http_server.go:226–808  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

224}
225
226func (s *HttpServer) createRequestHandler() http.Handler {
227 handleRequest := func(httpCtx context.Context, r *http.Request, w http.ResponseWriter, writeFatalError func(ctx context.Context, statusCode int, body error)) {
228 startedAt := time.Now()
229 encoder := common.SonicCfg.NewEncoder(w)
230 encoder.SetEscapeHTML(false)
231
232 // Get host without port number
233 host := r.Host
234 if colonIndex := strings.Index(host, ":"); colonIndex != -1 {
235 host = host[:colonIndex]
236 }
237
238 var projectId, architecture, chainId string
239 var isAdmin, isHealthCheck bool
240 var err error
241
242 // Check aliasing rules
243 if s.serverCfg.Aliasing != nil {
244 for _, rule := range s.serverCfg.Aliasing.Rules {
245 matched, err := common.WildcardMatch(rule.MatchDomain, host)
246 if err != nil {
247 s.logger.Error().Err(err).Interface("rule", rule).Msg("failed to match aliasing rule")
248 continue
249 }
250 if matched {
251 projectId = rule.ServeProject
252 architecture = rule.ServeArchitecture
253 chainId = rule.ServeChain
254 break
255 }
256 }
257 }
258
259 w.Header().Set("Content-Type", "application/json")
260 w.Header().Set("X-ERPC-Version", common.ErpcVersion)
261 w.Header().Set("X-ERPC-Commit", common.ErpcCommitSha)
262
263 // Add custom response headers (resolved at startup with env var expansion)
264 for key, value := range s.resolvedResponseHeaders {
265 w.Header().Set(key, value)
266 }
267
268 projectId, architecture, chainId, isAdmin, isHealthCheck, err = s.parseUrlPath(r, projectId, architecture, chainId)
269 if err != nil {
270 handleErrorResponse(
271 httpCtx,
272 s.logger,
273 &startedAt,
274 nil,
275 err,
276 w,
277 encoder,
278 writeFatalError,
279 &common.TRUE,
280 s.executionHeadersMode(),
281 )
282 return
283 }

Callers 1

NewHttpServerFunction · 0.95

Calls 15

parseUrlPathMethod · 0.95
executionHeadersModeMethod · 0.95
handleHealthCheckMethod · 0.95
handleCORSMethod · 0.95
resolveRealClientIPMethod · 0.95
SetClientIPMethod · 0.95
ValidateMethod · 0.95
MethodMethod · 0.95
JsonRpcRequestMethod · 0.95
SetUserMethod · 0.95
BodyMethod · 0.95
SetNetworkMethod · 0.95

Tested by

no test coverage detected