Testing your site that is on a server that uses host headers

April 16, 2010

If you believe that the only way to test multiple front end servers that are using host headers is by changing your host file, I have some good news. That is SO not true.

A bit of a recap: (non geeks can skip this)

What is a host header?

A host header is used to identify to what website the requester wants the request to go.

Why do I need it

Web servers work, by listening to requests for web pages, on a predefined port. Normally to have a more efficient use of a server it would be able to handle several websites at once. However there is a bit of a catch. If you have 1 ip address on a given server, you can only setup 1 site, to respond on that server on port 80. So if you want to run a second site on that server you need to have another ip address to listen on. So that is why the clever people introduced the host header. So now you can have 2 sites listening on port 80, and IIS looks at the incoming request for a page, and then looks at the host header, if it has a web site that is listening on that host header, it forwards the request to that specific site.

So that makes it quite difficult to test your website that is sitting on multiple servers, and have multiple sites on each server, except if you go down one layer of abstraction.

If you use TinyGet (found here: http:// support.microsoft.com/kb/840671) you can change how the normal request looks like a bit.

So a normal request to http://google.com will look like this in TinyGet

There are a couple of things to notice.

The Command:

TinyGet –srv:www.google.co.za –uri:/ -t

If you want to know more about the syntax and stuff read the help document

The bit that says request: **********

It has a GET – the verb to use in the request

Host: …. That is the host header

Accpet: */* that says what the client programs accepts.

The rest that follows is what you get back from the server.

So if we want to request a page from a server where we know the IP Address for we can use a command like the following ( I just pinged www.google.co.za, and guested that another web server will be listening on 99)

tinyget.exe -srv:209.85.229.100 -uri:/ -reqheaders:”host:www.google.co.za \n” –t

tinyget.exe -srv:209.85.229.99 -uri:/ -reqheaders:”host:www.google.co.za \n” –t

The magic is done by the –reqheaders bit

So we requesting from a specific IP address but we saying to the server, treat this request as if I actual request it from www.google.co.za instead of the IP address

Happy testing


Using SQL to generate tinyget script

March 16, 2010

Started of with running tinyget each time:
select  'tinyget -srv:"dev.24.com" -uri:"/cdn/Files/cms/img/' + 
cast(RepositoryItemId as varchar(50)) + 
'/?w=800&h=600&id=' + cast(RepositoryId as varchar(50))  +'"'
from repositoryitem

 

Then created a script file with sql, and executed tinyget once using the script file

:

select  '-uri:/cdn/Files/cms/img/' + 
cast(RepositoryItemId as varchar(50)) + 
'/?w=800&h=600&id=' + 
cast(RepositoryId as varchar(50))  
from repositoryitem
Command used to execute this script file:

c:\>tinyget –srv:webserver –script:scriptfilename.txt –l 10 –x:2

That runs it 10 times over 2 threads using the output of the sql statement saved to a text file


Follow

Get every new post delivered to your Inbox.