Default implementation of NotFound HTTP response
@param {Object} req HTTP request
@param {Object} res HTTP response
541688
function httpNotFound(req, res) {
    console.log(`No request handler found for ${req.url}`);
    res.writeHead(404, { 'Content-Type': 'text/plain' });
    res.write('404 Not found');
    res.end();
}
43411
function fixRedirectedResponse(response) {
  if (isNotRedirectedResponse(response)) {
    return Promise.resolve(response);
  }

  const body = 'body' in response ?
    Promise.resolve(response.body) : response.blob();

  return body.then(data => {
    return new Response(data, {
      headers: response.headers,
      status: response.status
    });
  });
}
249087
function notFound(req, res) {

    var ext = ppath.extname(req.path);
    if ((!ext || /\.htm|\.html/i.test(ext)) && !u.size(req.query)) return error(404, req, res);

    debug('404 %s', req.originalUrl);
    res.status(404).end();
  }
646441
function retrieveWhatAtTransmitter(req, res) {
  if(redirect(req.params.id, '', '', res)) {
    return;
  }

  switch(req.accepts(['json', 'html'])) {
    case 'html':
      res.sendFile(path.resolve(__dirname + '/../../web/response.html'));
      break;
    default:
      var options = {
        query: 'receivedBy',
        req: req,
        ids: [req.params.id]
      };
      var rootUrl = req.protocol + '://' + req.get('host');
      var queryPath = req.originalUrl;
      req.barterer.getDevicesState(options, rootUrl, queryPath,
                                   function(response, status) {
        res.status(status).json(response);
      });
      break;
  }
}
1115793
function (res, res_obj) {

    // return response if exist, otherwise response might be returned 
    // AFTER some callback is done handling (i.e., response will be returned within the handler)
    if (typeof res_obj === 'string') {
        LOG.sys('replying a string: ' + res_obj);
        res.writeHead(200, {'Content-Type': 'text/plain'});                     
        res.end(res_obj);            
    }
    else {
        LOG.sys('replying a JSON: ' + JSON.stringify(res_obj));
        res.writeHead(200, {'Content-Type': 'application/json'});                     
        res.end(JSON.stringify(res_obj));        
    }
}
581890
function(res) {
    res.setEncoding('utf8');
    var data = "";
    res.on('data', function(chunk) {
      data+=chunk;
    });

    res.on('end', function() {
      // Get HTTP Statuscode and act according to situation
      var code = res.statusCode;
      try { // try to parse JSON
        var answer = JSON.parse(data);
      } catch (e) {
        var err = {};
        err.http_code = 500;
        err.message = "No valid JSON received: "+data;
        callback(err, null);
        return;
      }
      if(code >= 200 && code <= 206) { // request was successful
        callback(null, answer);
      } else if (code >= 300 && code <= 307) { // server send redirect
        // we do not follow anything the server wants us to follow right now, since this should never be the case.
        // instead let's raise an error.
        var err = new Object();
        err.http_code = 500;
        err.message = "Redirects not supported by pastyclient-node"
        callback(err, null);
      } else if (code >= 400 && code <= 418) { // client error
        if(typeof(answer.error) == "object") {
          var err = answer.error;
        } else if(answer.code != undefined && answer.message != undefined) { // New RestError, temporary support both 
          var err = answer;
          err.http_code = code;
        } else {
          var err = new Object();
          err.http_code = code;
          err.message = "Resource not found";
        }
        callback(err, null);
      } else if (code >= 500 && code <= 505) { // server error
        if(typeof(answer.error) == "object") {
          var err = answer.error;
        } else {
          var err = new Object();
          err.http_code = code;
          err.message = "Internal Server Error";
        }
        callback(err, null);
      } else {
        // Not existant HTTP code. Raise error.
        var err = new Object();
        err.http_code = 500;
        err.message = "HTTP Status Code "+code+" is not supported by pastyclient-node"
        callback(err, null);
      }
    });
  }
839515
function(request, response, next){
		if (!utils.Misc.isNullOrUndefined(request.user) || request.originalUrl == '/error' || request.originalUrl.indexOf('/error?') == 0) {
			next();
		}
		else {
			var success = encodeURIComponent(request.protocol + '://' + request.get('host') + request.originalUrl);
			response.redirect('/login?success=' + success + '&no_query=true'); //we don't want it to add any query string
		}
	}
869199
def process_request(self, req, resp):  # pylint: disable=unused-argument
        

        try:
            creds = self._get_creds(req)
            self.auth_creds(*creds)
        except (AuthRejected, AuthRequired, InvalidAuthSyntax) as exc:
            exc.headers = self._error_headers
            if not self.optional:
                abort(exc)
222846
void _prepareResponseDataOnlyOnce(HttpServletRequest req) {
        if (req.getAttribute(KEY_FILE) == null) {
            
            String pathInfo    = req.getPathInfo();
            
            if (pathInfo == null)
                pathInfo = "";
            
            String fileSeparator = System.getProperty("file.separator");
            String filePath      = pathInfo.replaceAll(Pattern.quote("/"), fileSeparator);
            String mappedDirPath = getMappedDirPath();

            File file = new File(mappedDirPath, filePath);

            boolean isDirectory = file.isDirectory();
            req.setAttribute(KEY_IS_DIR,        isDirectory);
            
            if (isDirectory)
                file = new File(mappedDirPath, getIndexFilename());

            req.setAttribute(KEY_FILE,          file);
            req.setAttribute(KEY_MIME,          __getMimeType(file));
            req.setAttribute(KEY_LAST_MODIFIED, file.exists() ? file.lastModified() : 0);
        }
    }
976785
private HttpUriRequest addDefaultHeaders(HttpUriRequest req) {
        req.addHeader(HttpHeaders.ACCEPT, "*/*");
        req.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
        return req;
    }
161662
function(req, res) {
            if (!req._body || (req.body == null) || !req.body) {
                res.send(400, "Invalid POST missing required request body.");
                return;
            }
            if ((req.body.store == null) || !req.body.store) {
                res.send(400, "Invalid POST mising 'store' property in request body.");
                return;
            }
            if ((req.body.address == null) || !req.body.address) {
                res.send(400, "Invalid POST missing 'address' property in request body.");
                return;
            }
            if ((req.body.data == null) || !req.body.data) {
                res.send(400, "Invalid POST missing 'data' property in request body.");
                return;
            }
            var store = onmStoreDictionary[req.body.store];
            if ((store == null) || !store) {
                res.send(404, "The specified onm data store '" + req.body.store + "' does not exist on this server.");
                return;
            }
            var address = undefined;
            try {
                address = store.model.createAddressFromHashString(req.body.address);
            } catch (exception) {
                console.error(exception);
                res.send(403, "Invalid address '" + req.body.address + "' is outside of the data model's address space.");
                return;
            }
            var namespace = undefined
            try {
                namespace = store.openNamespace(address);
            } catch (exception) {
                console.error(exception);
                res.send(404, "Data component '" + req.body.address + "' does not exist in store '" + req.body.store + "'.");
                return;
            }
            try {
                namespace.fromJSON(req.body.data);
            } catch (exception) {
                console.error(exception);
                res.send(400, "Unable to de-serialize JSON data in request.");
                return;
            }
            res.send(204);
        }
624127
function (req, res) {
        var id = req.params.id;
        {modelName}.findOne({_id: id}, function (err, {name}) {
            if (err) {
                return res.status(500).json({
                    message: 'Error when getting {name}.',
                    error: err
                });
            }
            if (!{name}) {
                return res.status(404).json({
                    message: 'No such {name}'
                });
            }
            return res.json({name});
        });
    }
1268007
function (err, data) {
      debug(' => service response:', err, data);
      if (err) return next(err.cause || err);

      res.data = data;

      if (!data) {
        debug(`No content returned for '${req.url}'`);
        res.status(statusCodes.noContent);
      } else if (method === 'post') {
        res.status(statusCodes.created);
      }

      return next();
    }
699898
function(req, res) {
      var defaultString = 'You have successfully logged out.';

      // now respond or redirect
      var postResponse = this._resolvePostAction(waterlock.config.postActions.logout.failure,
        defaultString);

      if (typeof postResponse === 'string' && this._isURI(postResponse)) {
        res.redirect(postResponse);
      } else {
        res.ok(postResponse);
      }
    }
883160
function Request_handleError(response) {
        var request, code, that = this;

        if (this.isRendered) {
            // we have multiple recursion in parse for catching
            return false;
        }
        // log error request
        logger.error('Request:', {
            url: this.url,
            status: this.statusCode,
            id: this.id,
            isRendered: this.isRendered,
            content_type: this.getHeader('content-type'),
            message: response
        });

        if (response instanceof Error) {
            response = error.silentHttpError(500, {}, 'SlientHttpError: mvcjs error is not thrown', response);
        }
        // get error code from message
        code = getErrorCode(response);
        // set status codes
        this.setStatusCode(code);
        // stop current chain!!!
        this.stopPromiseChain();

        response += '\n';
        response += 'ROUTE:' + core.inspect(this._getRouteInfo());

        if (!this.isERROR && !!router.getErrorRoute()) {
            // return new request
            this.isRendered = true;

            request = new Request({
                request: this.request,
                response: this.response,
                isForwarded: true,
                body: this.body,
                isERROR: true
            }, router.createUrl(router.getErrorRoute()));
            // pass exception response over parsed url query as query parameter
            // assign to exception
            request.parsedUrl.query.exception = response;
            // set status codes for new request
            request.setStatusCode(code);
            // return parsed request
            return request.parse();
        } else {
            this.addHeader('Content-Type', 'text/plain');
            return response;
        }
    }
757472
function onResponse( response ) {
		if ( response.statusCode !== 200 ) {
			err = {
				'status': response.statusCode,
				'message': ''
			};
		}
		debug( 'Received a response from query endpoint.' );
		debug( 'Response status: %s.', response.statusCode );
		debug( 'Response headers: %s', JSON.stringify( response.headers ) );

		response.setEncoding( 'utf8' );
		response.on( 'data', onData );
		response.on( 'end', onEnd );
	}
267780
function handleReset(req, res, next) {
		var p = new Promise(function (resolve, reject) {
			const currentToken = req.params.token || 'missing';
			const email = req.params.email || 'missing@email.com';
			const password = req.params.password;
			if (!password) {
				return reject(new restifyErrors.BadRequestError("New password is missing"));
			}
			const qry = {
				local_auth_type: 'password',
				active: true,
				email: email,
				verify_token: currentToken
			};
			AclUser.findOne(qry, function (err, usr) {
				if (err) {
					debug(`Error finding user for password reset`, err);
					return reject(new restifyErrors.InternalError(err));
				}
				if (!usr) {
					debug(`Password reset email address and reset token did not match`, email);
					return reject(new restifyErrors.InvalidCredentialsError("Email address and reset token did not match"));
				}
				usr.verify_token = "password-reset:" + usr.generateVerifyHash();
				usr.modifiedBy = 'password-reset';

				debug(`Updating ${email} with a password reset`);
				usr.setPassword(password, function () {
					usr.save(function (err, user) {
						if (err) {
							debug(`Error updating user during password reset`, err);
							return reject(new restifyErrors.InternalError(err));
						}
						const data = {
							'success': true,
							'message': "Password updated"
						};
						resolve(data);
					});
				});
			});
		}).then(function (data) {
			res.json(data);
			next();
		}).catch(function (err) {
			debug(`Password reset request failed`, err);
			next(err);
		});
	}