From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 5F0561F4BD for ; Thu, 3 Oct 2019 03:53:40 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 32B21120A42; Thu, 3 Oct 2019 12:53:27 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3904A120A3F for ; Thu, 3 Oct 2019 12:53:25 +0900 (JST) Received: by filter0073p3las1.sendgrid.net with SMTP id filter0073p3las1-24025-5D9570B7-E 2019-10-03 03:53:27.396192177 +0000 UTC m=+119388.200103260 Received: from herokuapp.com (unknown [54.161.249.108]) by ismtpd0069p1mdw1.sendgrid.net (SG) with ESMTP id vjOPxb3BSuaD2BBhheAaTw for ; Thu, 03 Oct 2019 03:53:27.142 +0000 (UTC) Date: Thu, 03 Oct 2019 03:53:27 +0000 (UTC) From: richard.seviora@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70781 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16231 X-Redmine-Issue-Author: RichSeviora X-Redmine-Sender: RichSeviora X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?79ddmzjTgH4uLGZ+qKbXqPXTNfieFsLh6=2F0tg04DUrDhDzW4FfZ8FME0sc1usd?= =?us-ascii?Q?nVpSaJauQdYiViH4u3jTdRkQzZXZN=2F9sxkTDH46?= =?us-ascii?Q?5WZsry=2FcNEpXpXtTiY188SbcBwMGAr2JEOFvbKC?= =?us-ascii?Q?af=2F8kvxdvaDcaVMcRYxYijNmK3Koh8Xjg8rwGwA?= =?us-ascii?Q?HLj3Rg=2FCiAxrhznYGBaw1JVRUU8cOGslk6Q=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95194 Subject: [ruby-core:95194] [Ruby master Feature#16231] Add #location to Net::HTTPResponse X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "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/