Forum Discussion

Greenberg's avatar
Greenberg
Icon for Nimbostratus rankNimbostratus
Aug 15, 2019

iRule Help Inserting Header in HTTP_REQUEST_DATA

Hello,

 

I'm attempting to insert a header which contains error values from a 'Sideband' response.

 

I can't post the whole code due to what it does.

 

For example:-

 

when HTTP_REQUEST {


	set host_header [HTTP::host]
	set host_status [string tolower [class match -value [HTTP::host] starts_with DataGroup1]]
	set uri [HTTP::uri]
	set uri_status [string tolower [class match -value [HTTP::uri] starts_with DataGroup2]]

	set sessionid ""
	if {[HTTP::cookie exists "JSESSIONID"]} {
		set sessionid [HTTP::cookie value "JSESSIONID"]
	}


	if {[HTTP::method] eq "POST" && $host_status eq "on" && $uri_status eq "on"}{

		if {[HTTP::header exists "Content-Length"] }{
			set content_length [HTTP::header "Content-Length"]
		} else {
			set content_length 1048576
		}


		HTTP::collect $content_length
	} 
}

when HTTP_REQUEST_DATA {

	set payload [HTTP::payload]

  #DO SOME STUFF#
  
  	set pool1 [class match -value locale starts_with Datagroup3]
  
  	if { [active_members $pool1] < 1 } {
  		log local0. "The pool member is down"
		HTTP::header insert x-error-code Ts-Unavailable
        ***Above not inserting Header***

	} else {

#CONSTRUCT SOAP PAYLOAD#
#POST DATA TO SIDEBAND SERVICE#
	
		set conn [connect -timeout 1000 -status conn_status %Virtual1]
		set conn_info [connect info -idle -status $conn]
		set send_info [send -timeout 1000 $conn $request_to_send]
		set recv_request [recv -timeout 1000 $conn]
		close $conn


		if {$recv_request contains "<errorCode>"}{

			set start_error "<errorCode>"
			set end_error "</errorCode>"
			set pos_error [ string first $start_error $recv_request]
			set error_path_and_value [substr $recv_request $pos_error "</errorCode>"]
			set error_value [getfield $error_path_and_value ">" 2]

			HTTP::header insert x-error-code $error_value
            ***Above not inserting Header***

#STRIP OUT DATA#

		} else {

			#The Service replied with a valid response.


#REPLACE DATA WITH RECEIVED DATA#


		}


	}
	HTTP::release
}

 

Should this insert the Header into the HTTP Request destined for the Default Virtual/Pool? Am I missing something?

 

Thanks,

 

 

No RepliesBe the first to reply