How do I determine which HostHeader the client used? - asp.net-mvc-3

I'm attempting to set some session variables depending on which hostHeader was used to access my site. Do I have to parse it out of the URI property or is there a better way? (MVC3/IIS7)

Check out the HttpWebRequest.Host property, which should be equivalent to accessing Request.Headers["Host"] in MVC.
It mentions it's used to "Get or set the Host header value to use in an HTTP request independent from the request URI." If you're not setting this somehow then "then the Host header value to use in an HTTP request is based on the request URI." So inspecting it via the Request.Url.Host or equivalent property is equally sufficient. I don't know of any other way.

Related

AWS APIGW - Access static HTTP Headers for Integration Request in Mapping Template for Lambda

I am trying to modify an API GW config similar to what is found here https://oozio.medium.com/serverless-discord-bot-55f95f26f743
What I need to do is pass to lambda a custom static HTTP Header. I have defined in APIGW -> /{resource} -> Integration Request -> HTTP Headers: a header like {"Name": "application", "Mapped from": "'discord'", "Caching": false} (with single ticks as noted in the documentation for a static value)
This header never appears in the list of headers from the mapping template. I've spent the better part of a day trying to solve this.
Simplified question:
How do you access a static HTTP Header defined in Integration Request, in the Mapping Template?
TIA
After working with AWS support, this is apparently not possible.
Many Thanks for your kind patience. After our call I started to look for a possible
solution to fetch the statically set HTTP header in the mapping template, but
unfortunately could not find any solution.
I then discussed this scenario with my colleagues and also reached out to the
back-end API Gateway Service Team. It seems that this is something that is not
possible currently.
We cannot access the static header value defined in the integration request, in
the request body mapping template. If your use case needs to send the static header
in body for non proxy integration then it is recommended that you may define it
statically in the body mapping template directly.
I understand as you explained to me how you need to access the header in the mapping
template but unfortunately this does not seem to have a solution. Although the
statically set header is seen to be passed in the API Gateway logs, there is no
mechanism in the lambda service to fetch these headers.
Currently, I can ask the Service Team to consider the same as a feature request but
I wont be having a ETA available and also would need a solid reasoning since the
same can be done in the mapping template.
The workaround at this time (March 2021) has to be expressing it directly in the mapping template itself, or using Proxy for Lambda.
The following was provided as justification for the feature request.
When creating APIGW via a templating process (Such as terraform), being able to
express 'API Wide' variables is a useful tool for sending contextual information
to a backend integration. For example, a Lambda that can process requests from
multiple sources, but it needs to know which source should be used. While the
value can be statically expressed in the mapping template, having it be a
variable as part of the API allows for better visibility and management as its
an interact-able component, where as the mapping template is effectively a
complex string. This also does not need to be a header, it could simply be
"integration variables" that allow you to define simple k:v pairs that are either
passed as part of context, or accessible in $context within the mapping template.
While statically expressing it in the mapping template is a workaround, it is
only that.

How to define email address with Jmeter user defined variables?

Problem: In email address # replaced by %40.
http header manager:
user defined variables:
http request:
and result tree:
I have researched about this, and they say that, if http method is POST, then it should encoded automatically. But It does not encoded automatically. Any advice, how can I resolve this?
Note: Jmeter version : 3.1 and I am trying to test a rest service.
Please try sending data in Body data instead of sending it in parameters.
Change "Implementation" of your HTTP Request sampler to Java
If you need to change it for more than one sampler - it makes sense to define the setting using HTTP Request Defaults.
I found the answer. #PoorvajaDeshmukh's answer suggest me. Like following (correct defination of body data);
I also tried #DmitriT's suggestion, but I did not work. Thanks for advices...

Accessing JMeter HTTP Request Defaults values

I'm using HTTP Request Defaults to set host and port for a set of requests.
I'd like to access the same host value for cookie domain. Is there a way to refer to that particular variable?
Something like this maybe?
${DEFAULT_HOST}
No. There are no such default variables to access the HTTP Request Default Values.
But - you can easily achieve this using User Defined Variables.
Just create a variable DEFAULT_HOST=www.google.com
Then update the server name of the HTTP Request Defaults to ${DEFAULT_HOST}
You can also access the hostname everywhere in your test by using ${DEFAULT_HOST}.
And for extra credit...
Add a User Defined Variables element to the beginning of the test, so you can pass arguments from the commandline. In my tests, i have
name=HOST
value=${__P(host,test.mysite.com)}
Then you can use ${HOST} for HTTP and cookie defaults (and anything else), and run your test from the commandline like
jmeter -n -t mysite_loadTest.jmx -Jhost=www.mysite.com

Manipulate post body of httpsampler before request

I'm testing an Eclipse-RAP application with JMeter.
In RAP the client (javascript-framework in the browser) communicates with the server over a json-based protocol.
A message looks like this:
{"head":{"requestCounter":3,"uiSessionId":"832834"},"operations":[["set","w1",{"bounds": [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
As you see there is a session-ID stored in uiSessionId. I extracted this id using a "Regular Expression Extractor" and stored it in a variable namedUI_SESSION_ID`.
Then i edited the raw "Post Body" of the recorded HTTP-Request:
{"head":{"requestCounter":3,"uiSessionId":"${UI_SESSION_ID}"},"operations":[["set","w1",{"bounds": [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
and it works.
But i have to alter each Post-Body of each HTTP-Request which can be a lot.
After some research i thought using a "BeanShell PreProcessor" would be the right thing, but:
var sampler = ctx.getCurrentSampler();
would give me a HTTPSampler and i did not find any method which allows me to retrieve the post-body, replace the session-id with the variable and set the altered post-body.
JavaDoc: http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSampler.html
Do you know any way i can replace the uiSessionId with the variable without changing every request manually?
You don't have to. The uiSessionId header has been introduced in a milestone version in preparation for multiple browser-tab support in RAP, but it has been replaced by another mechanism that does not use this header parameter anymore.
As of RAP 2.1 RC1, the client now attaches a “connection id” to every POST request in a URL parameter cid. This parameter does not affect load tests, and you don't have to remove it from your recording. Since every jmeter thread gets its own HttpSession, it's not a problem that all threads have the same cid.
One reason for this change was the ability to load test RAP applications without the kind of problems that you've been struggling with.

Header Manager and Recording Controller

In my test scripts, I use a header manager that is shared at a thread group level, and then each sampler has it's own header as well for things that change (referrer, certain pragmas and cache-control) from request to request. I do this for ease of control e.g. so I can easily change the user agent for all requests.
I use the proxy and a recording controller to make the majority of my scripts, and I have set a header manager as a child of the recording controller - I have also tested this by setting a header manager inside the proxy element, but neither of these work as I want.
What it is doing is adding in a full set of headers from the browser, and not just those missing or different than what I have specified in the header manager.
Am I missing something, or is there even a way to do what I am trying to do?
I am using jmeter 2.6.
As others have pointed out, this doesn't happen yet in Jmeter. I am using 2.7 and see the same behavior.
I believe the original intent of the HTTP Request Defaults and HTTP Header Manager was to ease the task of developers creating scripts by hand. With the increased usage of the HTTP Proxy Controller, the application of the the above two elements needs to be extended to the Proxy Controller as well for recording.

Resources