/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const Url=require("url");var NetUtils=function(){this._request=require("sync-request")};NetUtils.prototype.loadUrl=function(url){var res,ret={};try{res=this._request("GET",url);ret.statusCode=res.statusCode;ret.headers=res.headers;if(res.statusCode===200){this._evalMediaType(res,ret)}}catch(e){ret.eCode=e.code;if(e.code=="ECONNREFUSED"&&url.startsWith("http://localhost:8136/rules")){ret.statusCode=4242}else{ret.statusCode=e.code==="ENOTFOUND"?404:999}}return ret};NetUtils.prototype.stripQuery=function(url){var u,path,x;u=Url.parse(url);path=u.pathname;x=url.indexOf(path);return url.substr(0,x+path.length)};NetUtils.prototype._evalMediaType=function(resp,ret){var contentType,body;contentType=resp.headers["content-type"];contentType=contentType?contentType.trim().toLowerCase():"text/plain";body=resp.getBody();if(contentType==="application/zip"||contentType==="application/7z"||contentType.startsWith("application/x-7z")||body[0]===80&&body[1]===75){ret.body=body;ret.type="zip"}else{if(contentType==="application/json"){ret.type="json"}else if(contentType.startsWith("application/javascript")||contentType.startsWith("text/javascript")){ret.type="js"}else if(contentType==="text/html"){ret.type="html"}else if(contentType==="text/css"){ret.type="css"}else if(contentType==="text/plain"){ret.type="text"}ret.body=body.toString("utf8")}};module.exports=NetUtils;