{"action":"opened","issue":{"url":"https://api.github.com/repos/radkovo/jStyleParser/issues/14","labels_url":"https://api.github.com/repos/radkovo/jStyleParser/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/radkovo/jStyleParser/issues/14/comments","events_url":"https://api.github.com/repos/radkovo/jStyleParser/issues/14/events","html_url":"https://github.com/radkovo/jStyleParser/issues/14","id":53372230,"number":14,"title":"Ability to set a callback for network connections","user":{"login":"hrj","id":345879,"avatar_url":"https://avatars.githubusercontent.com/u/345879?v=3","gravatar_id":"","url":"https://api.github.com/users/hrj","html_url":"https://github.com/hrj","followers_url":"https://api.github.com/users/hrj/followers","following_url":"https://api.github.com/users/hrj/following{/other_user}","gists_url":"https://api.github.com/users/hrj/gists{/gist_id}","starred_url":"https://api.github.com/users/hrj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hrj/subscriptions","organizations_url":"https://api.github.com/users/hrj/orgs","repos_url":"https://api.github.com/users/hrj/repos","events_url":"https://api.github.com/users/hrj/events{/privacy}","received_events_url":"https://api.github.com/users/hrj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-05T07:52:11Z","updated_at":"2015-01-05T07:52:11Z","closed_at":null,"body":"### Goal\r\nCurrently, jStyleParser starts fetching from the network whenever it sees `@import` rules.\r\n\r\nHowever, in gngr, we need network connections to be handled in the browser core. Reasons:\r\n* the browser maintains a network cache which can be utilised for the CSS requests\r\n* the browser has a request manager to control which network requests are allowed\r\n* the browser needs to maintain separate connection pools for separate trust zones\r\n\r\n### Ideas\r\nI initially thought that it would be best if jStyleParser only did the parsing and returned `@import rules` in the AST. The browser would initiate the request and call the parser again.\r\n\r\nHowever, I think a simpler way would be to pass a callback function to jStyleParser which the parser can call whenever it needs to make a network request. The actual request will then be processed/filtered/logged in the browser and the response will be handed back to the parser.\r\n\r\nAn example API could be:\r\n```java\r\npublic Interface NetworkProcessor {\r\n  // fetches a URL and returns the response as a String. On error, returns null\r\n  public String fetch(URL url);\r\n}\r\n\r\npublic Class CSSParserFactory {\r\n  public parse(String css, blah blah, NetworkProcessor processor) {\r\n  }\r\n}\r\n```\r\n\r\nIf you like, we could also probably use something like `java.net.URLStreamHandler`, but I haven't fully thought about that interface."}}