use faraday for json ld proxy again to allow for uris with queries
This commit is contained in:
parent
57f7eb4cd8
commit
22cdacd87a
1 changed files with 8 additions and 9 deletions
|
@ -1,8 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "net/http"
|
||||
require "uri"
|
||||
|
||||
require "faraday"
|
||||
|
||||
class Api::V1::JsonLdController < Api::BaseController
|
||||
include ActionController::Live
|
||||
|
@ -18,19 +16,20 @@ class Api::V1::JsonLdController < Api::BaseController
|
|||
io = request.env['rack.hijack_io']
|
||||
Thread.new {
|
||||
begin
|
||||
uri = URI.parse(url)
|
||||
conn = Faraday::Connection.new
|
||||
conn.options.timeout = 5
|
||||
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.open_timeout = 3
|
||||
http.read_timeout = 5
|
||||
http.write_timeout = 5
|
||||
api_response = http.request(Net::HTTP::Get.new(uri.request_uri))
|
||||
api_response = conn.get(url, nil, {'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'})
|
||||
|
||||
io.write("HTTP/1.1 #{api_response.status}\r\n")
|
||||
io.write("Content-Type: #{api_response.headers['Content-Type']}\r\n")
|
||||
io.write("Connection: close\r\n")
|
||||
io.write("\r\n")
|
||||
io.write(api_response.body)
|
||||
rescue
|
||||
io.write("HTTP/1.1 500\r\n")
|
||||
io.write("Connection: close\r\n")
|
||||
io.write("\r\n")
|
||||
ensure
|
||||
io.close
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue