0

I'm working on a fork of a library that implements Faraday to build URLs.

site = "https://example.io/#/"
path = "oauth/authorize"
connection = Faraday.new(site)
resource = Faraday::Utils.URI(path)
URL = connection.build_url(resource)

Notice that my site URL ends with a hashbang. But when the above code is executed, Faraday strips out the hashbang entirely:

https://example.io/oauth/authorize

But my application requires it to build this URL (with the hashbang):

https://example.io/#/oauth/authorize

Now before I go ripping out Faraday and monkey-patching something terrible.. can I do this by setting an option on Faraday?

Charney Kaye
  • 3,667
  • 6
  • 41
  • 54

2 Answers2

3

I think the answer here would be to quit trying to preserve the hash portion of the URL in Faraday since that portion is ignored for HTTP requests.

The hash part of the URL (also known as URI "fragment identifier") is never sent to the server. It can only have a meaning in the client. Typically, when the HTTP client is a web browser, the fragment identifier holds the name of the element to scroll to. Or, hashbang tricks can be employed with some JavaScript interaction.

But to use such URLs in Faraday doesn't make sense because the hash portion will never get sent to the server anyway.

mislav
  • 14,919
  • 8
  • 47
  • 63
  • Yep, that's the correct answer. Faraday prevents it for a reason. Having slept on the question myself, I woke up determined to approach the problem from the other side- refactoring the target (in this case an oauth server, designed for security purposes to be sent full URL requests) – Charney Kaye May 24 '15 at 17:53
0

Having '#' in path variable instead of site variable i am getting the output as you require.

site = "https://example.io/"
path = "#/oauth/authorize"
connection = Faraday.new(site)
resource = Faraday::Utils.URI(path)
URL = connection.build_url(resource)

Please try the above code and let me know the result.

  • I had not tried that exact combination before, however it yielded the same result. Nonetheless, I am leaning towards the other answer- that Faraday prevents it for a reason. – Charney Kaye May 24 '15 at 17:50