Skip to content

Commit

Permalink
Revert "[Hmk/url encryption] Made changes to interceptor to extract a…
Browse files Browse the repository at this point in the history
…nd encrypt path and query params"
  • Loading branch information
DeeStarks authored Jun 22, 2024
1 parent 754d35c commit 63fb7b2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 14 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,4 @@ dist
.yarn/install-state.gz
.pnp.*

/bin/interceptor.wasm

.vscode
/bin/interceptor.wasm
7 changes: 1 addition & 6 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,8 @@ func fetch(this js.Value, args []js.Value) interface{} {
switch strings.ToLower(userHeaderMap["Content-Type"]) {
case "application/json": // Note this is the default that GET requests travel through
// Converting the body to Golag or setting it as null/nil
urlPath := strings.Replace(spURL, host, "", 1)
bodyMap := map[string]interface{}{
"__url_path": urlPath,
}
bodyMap := map[string]interface{}{}
body := options.Get("body")
// fmt.Println("[Interceptor] URL Path: ", urlPath) // For debugging purposes
if body.String() == "<undefined>" {
// body = js.ValueOf(map[string]interface{}{}) <= this will err out as "Uncaught (in promise) Error: invalid character '<' looking for beginning of value"
body = js.ValueOf("{}")
Expand All @@ -473,7 +469,6 @@ func fetch(this js.Value, args []js.Value) interface{} {
return
}
}
// fmt.Println("[Interceptor] BodyMap: ", bodyMap) // For debugging purposes
// encode the body to json
bodyByte, err := json.Marshal(bodyMap)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions internals/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ func (c *Client) do(
}
// create request
client := &http.Client{}
// !NOTE: GET Requests are also converted to POST requests
// fmt.Println("[Interceptor] c.proxyURL+parsedURL.Path: ", c.proxyURL+parsedURL.Path+"?"+parsedURL.RawQuery) // For debugging purposes
r, err := http.NewRequest("POST", c.proxyURL, bytes.NewBuffer(data))
r, err := http.NewRequest("POST", c.proxyURL+parsedURL.Path, bytes.NewBuffer(data))
if err != nil {
res := &utils.Response{
Status: 500,
Expand All @@ -170,7 +168,6 @@ func (c *Client) do(
resByte, _ := res.ToJSON()
return resByte
}

// Add headers to the interceptor request.
// Note that at this point, the user's headers are bundled into the encrypted body of the interceptor's request
r.Header.Add("X-Forwarded-Host", parsedURL.Host)
Expand Down
2 changes: 1 addition & 1 deletion internals/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestClientDo(t *testing.T) {

var (
RequestMethod = "GET"
RequestURL = "https://test.layer8.com/"
RequestURL = "https://test.layer8.com/test"
RequestHeaders = map[string]string{
"Content-Type": "application/json",
"X-Test-Header": "test",
Expand Down

0 comments on commit 63fb7b2

Please sign in to comment.