ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95194] [Ruby master Feature#16231] Add #location to Net::HTTPResponse
       [not found] <redmine.issue-16231.20191003035326@ruby-lang.org>
@ 2019-10-03  3:53 ` richard.seviora
  2019-10-03 11:51 ` [ruby-core:95198] " shevegen
  2019-10-06 23:14 ` [ruby-core:95252] " sin
  2 siblings, 0 replies; 3+ messages in thread
From: richard.seviora @ 2019-10-03  3:53 UTC (permalink / raw)
  To: ruby-core

Issue #16231 has been reported by RichSeviora (Richard Seviora).

----------------------------------------
Feature #16231: Add #location to Net::HTTPResponse
https://bugs.ruby-lang.org/issues/16231

* Author: RichSeviora (Richard Seviora)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
# Abstract

Add a location convenience method to the `Net::HTTPRedirection` class.

# Background

When developers receive 3xx responses, we tend to do one of two things: follow the redirect or pass the redirect location onto the consumer. In both cases, we need to get the `Location` header value. This is a common enough use case that I had expected there'd be a convenience method, and there isn't one. I ended up googling how to do this and discovered I had to call the following: 

```
response['Location']
```

# Proposal

My proposal is to return the `Location` header value as-is (`String` if present, `nil` if header is not present) in a `#location` method added to `Net::HTTPResponse`. This will permit consumers to access the `Location` header in all of the response classes.

[Per RFC 7231 section 7.1.2](https://tools.ietf.org/html/rfc7231#section-7.1.2) the `Location` header is not limited to `3xx` responses; it can also be returned in `201 Created` responses. Augmenting the `Net:HTTPResponse` class makes more sense than augmenting (only) the `Net::HTTPRedirection` class.

# Implementation
```
class Net::HTTPResponse
  # ...
  # Returns the location value if present, nil otherwise.
  def location
    self['Location']
  end
  # ...
end
```
# Evaluation
This has nil performance impact when unused, it adds negligible costs over directly executing the same (guesstimate, I have not validated this)
# Discussion
Instead of returning a `String`, we could instead instantiate and return a `URI` object when the method is called (with the option to memoize). The implementation would need to handle both absolute and relative URIs, and decide whether to return the absolute resolved URI, or just the relative URI. 

I'm leaning towards returning the string as-is, and letting the consumer decide whether they need to instantiate a URI or just pass the string along.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95198] [Ruby master Feature#16231] Add #location to Net::HTTPResponse
       [not found] <redmine.issue-16231.20191003035326@ruby-lang.org>
  2019-10-03  3:53 ` [ruby-core:95194] [Ruby master Feature#16231] Add #location to Net::HTTPResponse richard.seviora
@ 2019-10-03 11:51 ` shevegen
  2019-10-06 23:14 ` [ruby-core:95252] " sin
  2 siblings, 0 replies; 3+ messages in thread
From: shevegen @ 2019-10-03 11:51 UTC (permalink / raw)
  To: ruby-core

Issue #16231 has been updated by shevegen (Robert A. Heiler).


Seems ok to me.

----------------------------------------
Feature #16231: Add #location to Net::HTTPResponse
https://bugs.ruby-lang.org/issues/16231#change-81874

* Author: RichSeviora (Richard Seviora)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
# Abstract

Add a location convenience method to the `Net::HTTPRedirection` class.

# Background

When developers receive 3xx responses, we tend to do one of two things: follow the redirect or pass the redirect location onto the consumer. In both cases, we need to get the `Location` header value. This is a common enough use case that I had expected there'd be a convenience method, and there isn't one. I ended up googling how to do this and discovered I had to call the following: 

```
response['Location']
```

# Proposal

My proposal is to return the `Location` header value as-is (`String` if present, `nil` if header is not present) in a `#location` method added to `Net::HTTPResponse`. This will permit consumers to access the `Location` header in all of the response classes.

[Per RFC 7231 section 7.1.2](https://tools.ietf.org/html/rfc7231#section-7.1.2) the `Location` header is not limited to `3xx` responses; it can also be returned in `201 Created` responses. Augmenting the `Net:HTTPResponse` class makes more sense than augmenting (only) the `Net::HTTPRedirection` class.

# Implementation
```
class Net::HTTPResponse
  # ...
  # Returns the location value if present, nil otherwise.
  def location
    self['Location']
  end
  # ...
end
```
# Evaluation
This has nil performance impact when unused, it adds negligible costs over directly executing the same (guesstimate, I have not validated this)
# Discussion
Instead of returning a `String`, we could instead instantiate and return a `URI` object when the method is called (with the option to memoize). The implementation would need to handle both absolute and relative URIs, and decide whether to return the absolute resolved URI, or just the relative URI. 

I'm leaning towards returning the string as-is, and letting the consumer decide whether they need to instantiate a URI or just pass the string along.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95252] [Ruby master Feature#16231] Add #location to Net::HTTPResponse
       [not found] <redmine.issue-16231.20191003035326@ruby-lang.org>
  2019-10-03  3:53 ` [ruby-core:95194] [Ruby master Feature#16231] Add #location to Net::HTTPResponse richard.seviora
  2019-10-03 11:51 ` [ruby-core:95198] " shevegen
@ 2019-10-06 23:14 ` sin
  2 siblings, 0 replies; 3+ messages in thread
From: sin @ 2019-10-06 23:14 UTC (permalink / raw)
  To: ruby-core

Issue #16231 has been updated by prajjwal (Prajjwal Singh).


Seems like a good first issue, I'd like to take this up if there's any interest in having it.

----------------------------------------
Feature #16231: Add #location to Net::HTTPResponse
https://bugs.ruby-lang.org/issues/16231#change-81929

* Author: RichSeviora (Richard Seviora)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
# Abstract

Add a location convenience method to the `Net::HTTPRedirection` class.

# Background

When developers receive 3xx responses, we tend to do one of two things: follow the redirect or pass the redirect location onto the consumer. In both cases, we need to get the `Location` header value. This is a common enough use case that I had expected there'd be a convenience method, and there isn't one. I ended up googling how to do this and discovered I had to call the following: 

```
response['Location']
```

# Proposal

My proposal is to return the `Location` header value as-is (`String` if present, `nil` if header is not present) in a `#location` method added to `Net::HTTPResponse`. This will permit consumers to access the `Location` header in all of the response classes.

[Per RFC 7231 section 7.1.2](https://tools.ietf.org/html/rfc7231#section-7.1.2) the `Location` header is not limited to `3xx` responses; it can also be returned in `201 Created` responses. Augmenting the `Net:HTTPResponse` class makes more sense than augmenting (only) the `Net::HTTPRedirection` class.

# Implementation
```
class Net::HTTPResponse
  # ...
  # Returns the location value if present, nil otherwise.
  def location
    self['Location']
  end
  # ...
end
```
# Evaluation
This has nil performance impact when unused, it adds negligible costs over directly executing the same (guesstimate, I have not validated this)
# Discussion
Instead of returning a `String`, we could instead instantiate and return a `URI` object when the method is called (with the option to memoize). The implementation would need to handle both absolute and relative URIs, and decide whether to return the absolute resolved URI, or just the relative URI. 

I'm leaning towards returning the string as-is, and letting the consumer decide whether they need to instantiate a URI or just pass the string along.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-06 23:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16231.20191003035326@ruby-lang.org>
2019-10-03  3:53 ` [ruby-core:95194] [Ruby master Feature#16231] Add #location to Net::HTTPResponse richard.seviora
2019-10-03 11:51 ` [ruby-core:95198] " shevegen
2019-10-06 23:14 ` [ruby-core:95252] " sin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).