MCPcopy
hub / github.com/laurentj/slimerjs / maybeAddHeaders

Function maybeAddHeaders

src/components/httpd.js:2198–2274  ·  view source on GitHub ↗

* Adds custom-specified headers for the given file to the given response, if * any such headers are specified. * * @param file * the file on the disk which is to be written * @param metadata * metadata about the incoming request * @param response * the Response to which any specified h

(file, metadata, response)

Source from the content-addressed store, hash-verified

2196 * if an error occurred while processing custom-specified headers
2197 */
2198function maybeAddHeaders(file, metadata, response)
2199{
2200 var name = file.leafName;
2201 if (name.charAt(name.length - 1) == HIDDEN_CHAR)
2202 name = name.substring(0, name.length - 1);
2203
2204 var headerFile = file.parent;
2205 headerFile.append(name + HEADERS_SUFFIX);
2206
2207 if (!headerFile.exists())
2208 return;
2209
2210 const PR_RDONLY = 0x01;
2211 var fis = new FileInputStream(headerFile, PR_RDONLY, PERMS_READONLY,
2212 Ci.nsIFileInputStream.CLOSE_ON_EOF);
2213
2214 try
2215 {
2216 var lis = new ConverterInputStream(fis, "UTF-8", 1024, 0x0);
2217 lis.QueryInterface(Ci.nsIUnicharLineInputStream);
2218
2219 var line = {value: ""};
2220 var more = lis.readLine(line);
2221
2222 if (!more && line.value == "")
2223 return;
2224
2225
2226 // request line
2227
2228 var status = line.value;
2229 if (status.indexOf("HTTP ") == 0)
2230 {
2231 status = status.substring(5);
2232 var space = status.indexOf(" ");
2233 var code, description;
2234 if (space < 0)
2235 {
2236 code = status;
2237 description = "";
2238 }
2239 else
2240 {
2241 code = status.substring(0, space);
2242 description = status.substring(space + 1, status.length);
2243 }
2244
2245 response.setStatusLine(metadata.httpVersion, parseInt(code, 10), description);
2246
2247 line.value = "";
2248 more = lis.readLine(line);
2249 }
2250
2251 // headers
2252 while (more || line.value != "")
2253 {
2254 var header = line.value;
2255 var colon = header.indexOf(":");

Callers 1

httpd.jsFile · 0.85

Calls 1

dumpnFunction · 0.85

Tested by

no test coverage detected