Regexp class inside of Agents

Can the Squirrel Regexp class be added into Agents?

I’m trying to check request.headers for a particular Content-Type but it’s not super easy without some kind of string.match function which the Regexp class contains. The use case is to check and see if a POST has the header “content-type: application/x-www-form-urlencoded” however when posting from a browser you may get some other valid things come along for the ride (when using the Firefox RESTClient I get “content-type: application/x-www-form-urlencoded; charset=UTF-8” ). Right now I have no simple method to check if the content-type contains the substring “application/x-www-form-urlencoded”.

Also, I discovered that all the header keys in request.headers are automatically set to lowercase but I haven’t found that documented anywhere.

We intend to add Regexp, yes. For this particular case, though, you can use string.find() – or, as the part you’re looking for is required to come at the beginning of the value, just string.slice().

Delivering the headers in lower-case makes it easier to use them as a Squirrel table, headers[“content-type”], as Squirrel doesn’t offer a case-insensitive table type. This is documented for outbound HTTP (httprequest.sendasync()), but not for inbound HTTP, sorry; I’ll fix that.

Peter

Ah, thank you Peter! I was looking at the Squirrel Standard Libraries instead of the Squirrel Reference Manual and missed string.find().