Martian config applied, but ignored. What's going on here?

56 views
Skip to first unread message

Jonathan Frederic

unread,
May 31, 2018, 7:28:55 PM5/31/18
to martianproxy-users
Hi martians!

Thanks for the awesome tool. I'm working on writing an HTML page which uses the Fetch API to set martian proxy config. I've confirmed that, after issuing a GET /configure to martian, my configuration is pushed. However, I don't see my header added to the responses (I'm checking by looking at Chrome Dev Tools Network tab). I've also tried other demo configs, such as one which performs verification. It seems like martian is not using the config I've pushed. :/

Here's the JS:

const martianPort = 8080;

function postData(url, data) {
  console.log('fetch', url, data);
  // Default options are marked with *
  return fetch(url, {
    body: JSON.stringify(data), // must match 'Content-Type' header
    cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
    credentials: 'same-origin', // include, same-origin, *omit
    headers: {
      'content-type': 'application/json'
    },
    method: 'POST', // *GET, POST, PUT, DELETE, etc.
    mode: 'cors', // no-cors, cors, *same-origin
    redirect: 'follow', // manual, *follow, error
    referrer: 'no-referrer', // *client, no-referrer
  })
  .then(response => response)
}

postData(`http://martian.proxy:${martianPort}/configure`, {
  "header.Modifier": {
    "scope": ["response"],
    "name" : "Test-Header",
    "value" : "true"
  }
}).then(response => 
    console.log(response, response.text().then(
        text => console.log("response text:", text))));

Jonathan Frederic

unread,
May 31, 2018, 7:34:08 PM5/31/18
to martianproxy-users
Here's an even simpler example, which I still can't get to work:

const martianPort = 8080;

function postData(url, data) {
  return fetch(url, {
    body: JSON.stringify(data),
    headers: {
      'content-type': 'application/json'
    },
    method: 'POST',
  })
  .then(response => response)
}

postData(`http://martian.proxy:${martianPort}/configure`, {
  "header.Modifier": {
    "scope": ["response"],
    "name" : "Test-Header",
    "value" : "true"
  }
}).then(console.log.bind(console));

Bramha Ghosh

unread,
May 31, 2018, 7:41:19 PM5/31/18
to martianproxy-users
In this example is 8080 the API port or the traffic port? You'll want to use the API port for config changes, and make sure that your HTTP client (fetch in this case) is configured to proxy through the traffic port. I'm not familiar with fetch at all - but it looks like you're not telling fetch that there's a proxy involved.

Jonathan Frederic

unread,
May 31, 2018, 7:53:42 PM5/31/18
to martianproxy-users
Hi Bramha, 

Thanks for the quick reply. I'm actually not sure what the problem was with that config, but it appears to be the config. Using 8080 seems to auto redirect to 8081. The following config produces results I'd expect:


function postData(url, data) {
  return fetch(url, {
    body: JSON.stringify(data),
    headers: {
      'content-type': 'application/json'
    },
    method: 'POST',
  })
  .then(response => response)
}

postData(`http://martian.proxy:${martianPort}/configure`, {
  "url.Filter": {
    "host": "www.google.com",
    "scope": ["request", "response"],
    "modifier": {
      "header.Modifier": {
        "scope": ["request", "response"],
        "name": "Martian-Test",
        "value": "true"
      }
    }
  }
}).then(console.log.bind(console));

Where martianPort is the proxy port, not the API port.

Bramha Ghosh

unread,
May 31, 2018, 8:06:35 PM5/31/18
to Jonathan Frederic, martianproxy-users
Hmm interesting - I wonder if there's something going on with the scopes with the top level modifier (url.Filter in the working case).

I'll do some tinkering and see if I can figure out what was going on.

I think what's happening with the forwarding is that because you're using the special "martian.proxy" host, it's forwarding the request from the traffic port to the api port for you.

--
You received this message because you are subscribed to the Google Groups "martianproxy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to martianproxy-us...@googlegroups.com.
To post to this group, send email to martianpr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/martianproxy-users/0db7963c-2983-45c0-b171-a64cf4c752e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages