Adding a User-Agent to our After Effects Socket request

One of the things I noticed while experimenting with the After Effects Socket object was that my Apache Server logs showed the User-Agent for my requests as “_” which I think is the Apache equivalent of null. While not really a problem while we are experimenting, it’s always a good idea to be a good citizen of the net as a developer. If we were to ingest a web service with the After Effects socket like so it would be the equivalent of knocking on a door with a mask on.

I didn’t see any reference to User-Agent in the After Effects Scripting Guide so I dug around a bit. User-Agent is simply a line in the GET or POST http request. Since we are crafting our http request line by line we can just add a reference to our project like so…

webConnect.write('GET /socketDemo/sampleProject.json HTTP/1.0  \nUser-Agent: OurFantasticAfterEffectsWebService(\n\n'); 

What might be more common is an internal web service. In that case we might use system.machineName as the User-Agent like so…

var machine = system.machineName;
var request = "GET /socketDemo/sampleProject.json HTTP/1.0  \nUser-Agent: " + machine + "\n\n";

We could then use our web server logs to trace which internal machine requested a particular service at a particular time.

Problem solved. I haven’t done a lot of work with raw HTTP requests and there is a ton of stuff in the HTTP spec so I know I’ll be doing some more reading as I dig deeper into using After Effects like this.

1 Comment

  1. Andrew said

    That’s for the great article. Can you please post a tutorial on using the socket object in reverse (as a server)? I’ve been experimenting with the examples in the Javascript Reference Guide without success. Don’t know if it’s my scripts that are the problem, or my server setup on osx.

RSS feed for comments on this post

Comments are closed.