Skip to content

Fix Location Header in POST Response header#1626

Merged
severussundar merged 13 commits intomainfrom
dev/shyamsundarj/fix-location-header-POST-response-header
Aug 19, 2023
Merged

Fix Location Header in POST Response header#1626
severussundar merged 13 commits intomainfrom
dev/shyamsundarj/fix-location-header-POST-response-header

Conversation

@severussundar
Copy link
Copy Markdown
Contributor

@severussundar severussundar commented Aug 10, 2023

Why make this change?

  • Closes [Bug] Unable to perform GET request using Location Header returned for POST requests  #1613
    • According to HTTP POST Specs, when a POST request results in the creation of a new item, then a Location header field should be returned in the response header.

    If one or more resources has been created on the origin server as a result of successfully processing a POST request, the origin server SHOULD send a 201 (Created) response containing a Location header field that provides an identifier for the primary resource created (Section 10.2.2) and a representation that describes the status of the request while referring to the new resource(s).

    • The Location header returned in the response headers were incorrect

Tables/View: https://localhost:5001/api/Book//id/5009
Stored Procedures: https://localhost:5001/api/CountBooks//CountBooks

  • When base-route is configured in the config file, the Location returned did not account for it. So, a subsequent GET request performed using the Location is unsuccessful.

What is this change?

  • RestController: Logic to construct the Location header is updated to accommodate the base-route field
  • RestService: Helper method to extract the configured base-route is added
  • ConfigurationTests: Integration tests to validate the Location field when a) base-route is configured b) base-route is absent for tables and stored procedures are added.

How was this tested?

  • Integration Tests
  • Manual Tests

Sample Request(s)

  • Table and base-route is not configured
    image

  • Stored Procedure and base-route is not configured
    image

  • Table and base-route is configured. Configured base-route: /data-api
    image

  • Stored Procedure and base-route is configured. Configured base-route: /data-api
    image

Comment thread src/Service/Controllers/RestController.cs Outdated
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this bug and fixing it! Left few questions..

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Core/Services/RestService.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Copy link
Copy Markdown
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions for test layout.

Comment thread src/Core/Resolvers/SqlMutationEngine.cs
Comment thread src/Core/Services/RestService.cs Outdated
Comment thread src/Service/Controllers/RestController.cs Outdated
Comment thread src/Service/Controllers/RestController.cs
Comment thread src/Core/Services/RestService.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Core/Services/RestService.cs
Copy link
Copy Markdown
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern with trimming >1 consecutive slashes from the URL and treating that as valid url. while //api/Book/id/1 is a "valid URL" , it is not a valid way to access the book entity. That is an invalid path which should result in either a 404 not found or 400 bad request.

Comment thread src/Service/Controllers/RestController.cs Outdated
Comment thread src/Service/Controllers/RestController.cs
Comment thread src/Core/Services/RestService.cs Outdated
Comment thread src/Service.Tests/Unittests/RestServiceUnitTests.cs
Comment thread src/Service.Tests/Unittests/RestServiceUnitTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
@seantleonard
Copy link
Copy Markdown
Contributor

Please ignore the first review as it is a duplicate cause by VScode GitHub PR extension.

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs Outdated
Copy link
Copy Markdown
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a last few suggestions before merging.

@severussundar severussundar merged commit 5e3874e into main Aug 19, 2023
@severussundar severussundar deleted the dev/shyamsundarj/fix-location-header-POST-response-header branch August 19, 2023 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Unable to perform GET request using Location Header returned for POST requests

4 participants