so i use lib/asp.rb module to get legacy asp content from internal
win2k/iis5/asp (classic not .net) servers as a mixin and require it in
my application_controller.rb as i have many asp pages. i do it this
way because it gives me a smooth incremental upgrade path to rails
from asp by replacing page for page as we write a better rails
replacement. this way my routes are all rails and i just call
asp_get_content when i have an asp page to wrap.
controller:
def my_legacy_page
asp_get_content
end
lib/asp.rb
module asp
def asp_get_content
@asp_response = Net::HTTP.start(host, port) {|x|
x.read_timeout = 1200
x.send_request(method, path, data, headers)
}
# return false on redirects so we can use custom renders like so:
# render :foo => :bar if asp_get_content while still allowing just
# asp_get_content without anything else for standard stuff
case @asp_response
when Net::HTTPRedirection
redirect_to "#...@asp_response['location']}"
false
else
true
end
end
view:
<%= @asp_response.body %>
to reproduce the issue, just add
<%= chr(150) %> to the asp page. rails will choke with invalid byte
sequence utf-8 as soon as the response.rb tries to parse
@asp_response.body. see the above comments for the stack trace.
this is just my particular situation. i suspect you can add any high,
non-standard ascii code that windows likes like ascii 128-159. my test
case is ascii 150 that will reliably reproduce the issue. my point is
not with encoding per se, i just think that rails should be a bit more
fault tolerant around encodings as interop makes it almost a certainty
that we will pull incontent with bad encodings just as we pull in
malformed html. we cope with the latter well but now need to do so
with the former. imho.
thanks...gg
On Apr 13, 5:05 am, Conrad Taylor <[email protected]> wrote:
> 2009/4/13 buddycat <[email protected]>
>
>
>
>
>
> > hector,
>
> > further update:
>
> > i was able to set both my internal and external encoding thanks to
> > hongli lai at phusion passenger. he helped me with a wrapper for my
> > local ruby that uses the encoding option. not suggesting that this is
> > his preferred method though, but you don't seem to be able to pass
> > ruby options any other way that i'm aware of in passenger's apache
> > config.
>
> > /usr/local/ruby1.9/bin/ruby_wrapper:
> > #!/bin/bash
> > exec /usr/local/ruby1.9/bin/ruby -E utf-8:utf-8 "$@"
>
> > then in apache2.conf:
> > PassengerRuby /usr/local/ruby1.9/bin/ruby_wrapper
>
> > restart apache.
>
> > in a controller:
> > raise "#{Encoding.default_internal} #{Encoding.default_internal}"
>
> > results in:
> > utf-8 utf-8
>
> > so all is good. for my app anyway. irb and script/console is a pain.
>
> > unfortunately, after all this, my asp pages still get ascii encoded
> > when brought in by net::http (after adding all the asp settings i can
> > to convince it to use utf). also, more unfortunately, your assertion
> > that if i have the default encodings set right (particularly
> > default_internal which i do now), that it will silently and fautlessly
> > convert my ascii page without error. no joy. got same utf encoding
> > error that i started with.
>
> > so...guess i am back to doing explicit encoding like you suggested or
> > going back to iconv.
>
> > all in all i have to say that ruby1.9 and rails2.3 and encoding and
> > irb and compiling your own ruby and... are still very rough.
>
> > ...gg
>
> Do you have a test case that I can reproduce the issue that you're seeing?
>
> Thanks,
>
> -Conrad
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---