Skip to content

Commit

Permalink
Updated gitignore
Browse files Browse the repository at this point in the history
Signed-off-by: Akash <[email protected]>
  • Loading branch information
SkySingh04 committed Aug 10, 2024
1 parent fb26a2e commit 515ede5
Show file tree
Hide file tree
Showing 14 changed files with 1,910 additions and 289 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
.idea/**/gradle.xml
.idea/**/libraries

\build
\bin\main
node_modules
.gradle

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
Expand Down
2 changes: 1 addition & 1 deletion bin/main/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<version>1.0</version>

<description><![CDATA[
Your employer track every minute spent in browser? Use CatViewer in your IDE, and browse funny cats along you code!
Keploy : Generate e2e tests directly from your IDE!
]]></description>

<idea-version since-build="201.6668.113"/>
Expand Down
142 changes: 142 additions & 0 deletions bin/main/com/Keploy/CustomResourceHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.Keploy

import java.io.{IOException, InputStream}
import java.net.JarURLConnection
import org.cef.callback.CefCallback
import org.cef.handler.{CefLoadHandler, CefResourceHandler}
import org.cef.misc.{IntRef, StringRef}
import org.cef.network.{CefRequest, CefResponse}
import java.net.URLConnection

class CustomResourceHandler extends CefResourceHandler {
private var state: ResourceHandlerState = ClosedConnection
override def processRequest(
cefRequest: CefRequest,
cefCallback: CefCallback
): Boolean = {
val urlOption = Option(cefRequest.getURL)
urlOption match {
case Some(processedUrl) =>
val pathToResource = processedUrl.replace("http://myapp", "webview/")
val newUrl = getClass.getClassLoader.getResource(pathToResource)
state = OpenedConnection(
newUrl.openConnection()
)
cefCallback.Continue()
true
case None => false
}
}

override def getResponseHeaders(
cefResponse: CefResponse,
responseLength: IntRef,
redirectUrl: StringRef
): Unit = {
state.getResponseHeaders(cefResponse, responseLength, redirectUrl)
}

override def readResponse(
dataOut: Array[Byte],
designedBytesToRead: Int,
bytesRead: IntRef,
callback: CefCallback
): Boolean = {
state.readResponse(dataOut, designedBytesToRead, bytesRead, callback)
}

override def cancel(): Unit = {
state.close()
state = ClosedConnection
}
}

sealed trait ResourceHandlerState {
def getResponseHeaders(
cefResponse: CefResponse,
responseLength: IntRef,
redirectUrl: StringRef
): Unit

def readResponse(
dataOut: Array[Byte],
designedBytesToRead: Int,
bytesRead: IntRef,
callback: CefCallback
): Boolean

def close(): Unit = {}
}

case class OpenedConnection(connection: URLConnection)
extends ResourceHandlerState {
private lazy val inputStream: InputStream = connection.getInputStream
override def getResponseHeaders(
cefResponse: CefResponse,
responseLength: IntRef,
redirectUrl: StringRef
): Unit = {
try {
val url = connection.getURL.toString
url match {
case x if x.contains(".css") => cefResponse.setMimeType("text/css")
case x if x.contains(".js") =>
cefResponse.setMimeType("text/javascript")
case x if x.contains(".html") => cefResponse.setMimeType("text/html")
case _ =>
cefResponse.setMimeType(
connection.getContentType
) // since 2021.1 all mime type must be set here, by hand
}
responseLength.set(inputStream.available())
cefResponse.setStatus(200)
} catch {
case e: IOException =>
cefResponse.setError(CefLoadHandler.ErrorCode.ERR_FILE_NOT_FOUND)
cefResponse.setStatusText(e.getLocalizedMessage)
cefResponse.setStatus(404)
}
}

override def readResponse(
dataOut: Array[Byte],
designedBytesToRead: Int,
bytesRead: IntRef,
callback: CefCallback
): Boolean = {
val availableSize = inputStream.available()
if (availableSize > 0) {
val maxBytesToRead = Math.min(availableSize, designedBytesToRead)
val realNumberOfReadBytes =
inputStream.read(dataOut, 0, maxBytesToRead)
bytesRead.set(realNumberOfReadBytes)
true
} else {
inputStream.close()
false
}
}

override def close(): Unit = {
inputStream.close()
}
}

case object ClosedConnection extends ResourceHandlerState {
override def getResponseHeaders(
cefResponse: CefResponse,
responseLength: IntRef,
redirectUrl: StringRef
): Unit = {
cefResponse.setStatus(404)
}

override def readResponse(
dataOut: Array[Byte],
designedBytesToRead: Int,
bytesRead: IntRef,
callback: CefCallback
): Boolean = {
false
}
}
Loading

0 comments on commit 515ede5

Please sign in to comment.