Apr 15, 2011

Bad URI with oauth token

Bad URI error occurs when we do OAuth verification. (I found it because of Facebook connect)

This is because the OAuth token contains a special character, precisely, |. I think there can be other characters that cause Bad URI error.

Moreover, I have found that the Bad URI only occurs with WEBRick, a webserver provided by Ruby.

Therefore, in order to fix it, I had to modify Ruby source code.

Here is what I have done:

In the file httpresponse.rb, which resides in C:/Ruby187/lib/ruby/1.8/webrick (This depends on where you installed Ruby)

Around the line 164:

# Location is a single absoluteURI.
if location = @header['location']
if @request_uri
@header['location'] = @request_uri.merge(location)
end
end


Add URI.encode() around location before @request_uri.merge()


# Location is a single absoluteURI.
if location = @header['location']
if @request_uri
@header['location'] = @request_uri.merge(URI.encode(location))
end
end


And that's it.

I'm gonna fix this in the Ruby open source project also. This will be my first open source participation, yeahhhh.