MCPcopy Create free account
hub / github.com/defold/defold / HttpResponse

Function HttpResponse

engine/dlib/src/dlib/webserver.cpp:118–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116 }
117
118 void HttpResponse(void* user_data, const dmHttpServer::Request* request)
119 {
120 Server* server = (Server*) user_data;
121
122 dmArray<HandlerData>& handlers = server->m_Handlers;
123 uint32_t n = handlers.Size();
124 HandlerData* handler = 0;
125 for (uint32_t i = 0; i < n; ++i)
126 {
127 HandlerData* h = &handlers[i];
128
129 if (strncmp(request->m_Resource, h->m_Prefix, strlen(h->m_Prefix)) == 0)
130 {
131 handler = h;
132 break;
133 }
134 }
135
136 if (handler)
137 {
138 InternalRequest internal_request;
139 internal_request.m_Server = server;
140 internal_request.m_Request = request;
141
142 Request web_request;
143 web_request.m_Method = request->m_Method;
144 web_request.m_Resource = request->m_Resource;
145 web_request.m_ContentLength = request->m_ContentLength;
146 web_request.m_Internal = &internal_request;
147
148 handler->m_Handler(handler->m_Userdata, &web_request);
149 }
150 else
151 {
152 dmHttpServer::SetStatusCode(request, 404);
153 char not_found[256];
154 dmSnPrintf(not_found, sizeof(not_found), "Resource '%s' not found", request->m_Resource);
155 dmHttpServer::Send(request, not_found, strlen(not_found));
156 }
157
158 ResetHeadersTable(server);
159 }
160
161 Result New(const NewParams* params, HServer* server_out)
162 {

Callers

nothing calls this directly

Calls 5

dmSnPrintfFunction · 0.85
ResetHeadersTableFunction · 0.85
SetStatusCodeFunction · 0.70
SendFunction · 0.70
SizeMethod · 0.45

Tested by

no test coverage detected