MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / handleRequest

Method handleRequest

plugins/plugin_utils/plugin_HTTP.cpp:71–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71bool BZFSHTTP::handleRequest(const HTTPRequest& request, HTTPReply& reply) {
72 if (serviceMimeResources && resourceRootPath.size() && mimeTypes.size()) {
73 // parse out the resource and see if we know what it is
74 std::string ext;
75 tolower(getFileExtension(request.resource), ext);
76
77 if (ext.size()) {
78 if (mimeTypes.find(ext) != mimeTypes.end()) {
79 // it's one we do, try and find it
80 std::string filepath = concatPaths(resourceRootPath.c_str(), request.resource.c_str());
81
82 FILE* fp = fopen(filepath.c_str(), "rb");
83 if (fp) {
84 char buffer[1024];
85 bool done = false;
86
87 while (!done) {
88 size_t read = fread(buffer, 1, 1024, fp);
89 if (read) {
90 reply.addBody(buffer, read);
91 }
92
93 if (read != 1024) {
94 done = true;
95 }
96 }
97 fclose(fp);
98
99 reply.docType = HTTPReply::eOther;
100 reply.otherMimeType = mimeTypes[ext];
101 reply.returnCode = HTTPReply::e200OK;
102 return true;
103 }
104 }
105 }
106 }
107
108 return generatePage(request, reply);
109}
110
111bool HTTPRequest::getParam(const char* param, std::string& val) const {
112 val = "";

Callers

nothing calls this directly

Calls 8

tolowerFunction · 0.85
c_strMethod · 0.80
addBodyMethod · 0.80
getFileExtensionFunction · 0.70
concatPathsFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected