How do I get the full URL that was sent by the client?

I am considering using HMAC to sign requests and I want to include the URL as well as other things (e.g. HMAC = verb + url + nonce + timestamp + body). I don’t see a simple way to get the request URL that the client sent, it looks like I have to reconstitute it using:

var req_verb = context.getVariable('request.verb');
var req_scheme = context.getVariable('client.scheme');
var req_host = context.getVariable('request.header.host');
var req_request_uri = context.getVariable('request.uri');
var req_url = req_scheme + "://" + req_host + req_request_uri;

Since the message URI includes the basepath, suffix and params, can I assume what the client sent is what Apigee actually gets? Or could it change in transit?

How about “proxy.url” ?

Scope: Proxy request Type: String Permission: Read

Gets the complete URL associated with the proxy request received by the ProxyEndpoint, including any query parameters present.

Please check http://docs.apigee.com/api-services/reference/variables-reference for complete variable reference .

You can check proxy.url at proxy side or request.url at target scope to get the complete url.

Yep, tried that, it returns something like:

https://rrt002hipaaba.us-ea.4.apigee.com/hello

not

https://org-test.apigee.net/hello

var req_verb = context.getVariable(‘request.verb’);

var req_scheme = context.getVariable(‘client.scheme’);

var req_host = context.getVariable(‘request.header.host’);

var req_request_uri = context.getVariable(‘request.uri’);

var req_url = req_scheme + “://” + req_host + req_request_uri;

1 Like

That’s pretty much what I’m doing, and that message looks dated.

BTW:

  • proxy.host has no value,
  • client.host returns IP address

I modified my code to use request instead of message, looks more consistent :slight_smile:

Correct. That’s what I meant. request.host worked for me and req.get(‘host’); in Node.js. I’m glad it worked! Don’t forget to mark as accepted :wink:

Maybe this one could be documented more explicitely under Variables Reference http://docs.apigee.com/api-services/reference/variables-reference.

@wwitman, @docs

@Kurt Kanaskie , Yes, You are right. Missed to verify URL contents. I believe it’s a bug. Above URL is no use, I believe this has to be fixed in the product.

@Kurt Kanaskie At this point that’s the only way to get it. Though I agree that there should be an OOTB variable to get the request url received by Apigee. What you get from the javascript is fine and that is what the client sent. There’s no change in transit unless there’s some nginx level routing that modified the path or any of the other parameters, which is not very common.

I added a tip to the variables doc explaining how to construct the request URI, as there is no other way to get this from a built-in flow variable.

1 Like

Thanks @wwitman!

Nice, glad this worked out.

I’m confused, in my JS code request.host is empty.

print('request.host: ' + context.getVariable('request.host'));

But that’s OK, I like the new documentation : )

You got it right from the beginning Kurt. So, you need to use request.header.host.

I found another nice way of doing it, get the proxy.url value in the Pre-Proxy flow hook, assign it to a new variable by using an AssignMessage policy and use the new variable wherever needed.

AM-SetRequestUrl SF-PreProxy-V1.RequestUrl proxy.url ErrorOnCopy true

It seems that proxy.url contains the request url before entering the proxy, after that it gets replaced by the target server url so capturing the value before that happens works well.