cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to set HTTP status code to 410?

SOLVED
Highlighted
New Contributor

Is it possible to set HTTP status code to 410?

I am trying to set HTTP status code to 410 for the whole domain.

In the RuleBuilder I create one condition: HTTP Header - Host - contains - somedomain.com

Then I add a single action: Set Header - Status - 410

However, the traffic is still passed onto the webserver and I get 404.

Does Stingray allow rewriting HTTP status codes?

EDIT: OK, so Status is not part of the Header (it helps to read RFC once in a while). The question remains though: is it possible to set HTTP status code in Stingray?

4 REPLIES
Contributor

Re: Is it possible to set HTTP status code to 410?

you want to send a 410 to the client for every request right?

so a trafficscript line of

http.sendResponse( "410 Gone", "text/html", "Gone", "");

should do the job.

(if i understand the requirement correctly, or do you want to modify the request-status prior to deliver the request to the nodes, which for me does not make sense)

as far as i can see, with rule builder only redirect and changesite is possible.

Contributor

Re: Is it possible to set HTTP status code to 410?

Rule Builder does not have a HTTP Send response function, but can stop connections from going to the back end nodes with the "Drop Connection"

RuleBuilderDropConn.JPG.jpg

If just dropping the connection is not your desired outcome you can use Traffic Script and http.sendResponse function to send the specific 410 HTTP response. Ref: http.sendResponse( code, type, body, headers )

Example


if( string.contains( http.getheader( "Host" ), "somedomain.com" ) ){



http.sendResponse( "410 Gone", "text/html", "Gone", "");



}




Directly answering your question:


"The question remains though: is it possible to set HTTP status code in Stingray?"



Yes, with the Traffic Script http.setResponseCode function Sets the status code and message in the first line of the HTTP response. Ref: http.setResponseCode( code, [message] )

Example


http.setResponseCode( "410", "Gone" );



Note, This is used in response rule to requests that have come from the back end nodes, so the request was already passed onto the web server.

New Contributor

Re: Is it possible to set HTTP status code to 410?

Thank you both for the answers.

Just to clarify one thing: I do not want the request to ever reach the web server - all requests to a specific domain need to instantly return 410.

When I raised the question we didn't have trafficscript available, but now we do, so this definitely answers my question.

Contributor

Re: Re: Is it possible to set HTTP status code to 410?

When applied as a request rule,this Example will send a 410 response to all requests that contain somedomain.com in the host header. i.e. www.somedomain.com or somedomain.com.


if( string.contains( http.getheader( "Host" ), "somedomain.com" ) ){ 


http.sendResponse( "410 Gone", "text/html", "Gone", ""); 


}


You could also change the logic and send all requests NOT containing mydomain.com a HTTP 410 Response.


if( string.contains( http.getheader( "Host" ), "mydomain.com" ) == 0 ){


http.sendResponse( "410 Gone", "text/html", "Gone", ""); 


}



In both examples, the requests will be sent by Traffic Script and not the web server.