Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Inspect JSON request payload

Chado
Nimbostratus
Nimbostratus

First off, I am not a developer. I have limited experience with iRules. I got task to write an iRule to inspect JSON requests containing specific type parameters in its payload. If the payload contains any of the valid type parameters then forward to VS(X). All other JSON requests should be drop with an http status code 404.

 

{

    “type”:  “XXXX”,

“type”:  “XXXX”,

      …..

      ..…

}

 

I was not able to find anything on D/C yet. Any direction or help would be much appreciated!

1 REPLY 1

Yoann_Le_Corvi1
Cumulonimbus
Cumulonimbus

Hi

 

Here is a code snippet that might help. Keep in mind this is not a full fledge JSON parser though.

 

set payload "[string map {"\"" ""} [string trim $jsonRequestPayload "\{\}"]]"
for each parameter [split $payload ","] {
 
switch -glob -- $parameter {
 
"type:*" {
    set type [ lindex [split $parameter ":"] 1 ]
    if { $type equals "wrongtype" } {
			
		HTTP::respond 404 content "Not Found"
 
		}
 
	}
 
}

Hope this may help.

 

Yoann