Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContentContainer.decode(_:as:) #3023

Merged
merged 5 commits into from May 30, 2023

Conversation

MahdiBM
Copy link
Contributor

@MahdiBM MahdiBM commented May 25, 2023

Adds ContentContainer.decode(_:as:) to compliment ContentContainer.encode(_:as:) to make it easy to override the Content-Type if calling an API or decoding a request that returns erroneous headers for the body type.

@MahdiBM
Copy link
Contributor Author

MahdiBM commented May 25, 2023

(I guess my branch name isn't accurate. Should have been something like mahdibm-add-as-contenttype)

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2023

Codecov Report

Merging #3023 (da11309) into main (e181d2d) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3023      +/-   ##
==========================================
+ Coverage   76.73%   76.77%   +0.04%     
==========================================
  Files         211      211              
  Lines        7770     7773       +3     
==========================================
+ Hits         5962     5968       +6     
+ Misses       1808     1805       -3     
Impacted Files Coverage Δ
Sources/Vapor/Content/ContentContainer.swift 77.77% <100.00%> (+1.03%) ⬆️

... and 3 files with indirect coverage changes

Tests/VaporTests/RequestTests.swift Outdated Show resolved Hide resolved
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

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

Implementation looks good, would like some changes in the tests 👍

Tests/VaporTests/ContentTests.swift Outdated Show resolved Hide resolved
Tests/VaporTests/ContentTests.swift Show resolved Hide resolved
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

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

Thanks!

@0xTim 0xTim changed the title add ContentContainer.decode(_:as:) Add ContentContainer.decode(_:as:) May 30, 2023
@0xTim
Copy link
Member

0xTim commented May 30, 2023

Original comment:

This came up in a conversation were both Tim and I were expecting such a function, but realized there it isn't there.
The fact that we expected it is probably because there is a ContentContainer.encode(:as:), but no decode(:as:).
This should be useful to users that are trying to decode content of a request with a bad/unexpected content-type header.

@0xTim 0xTim added the semver-minor Contains new API label May 30, 2023
@0xTim 0xTim enabled auto-merge (squash) May 30, 2023 08:06
@0xTim 0xTim merged commit 9a340de into vapor:main May 30, 2023
12 checks passed
@VaporBot
Copy link
Contributor

These changes are now available in 4.77.0

keniwhat pushed a commit to keniwhat/vapor that referenced this pull request Aug 29, 2023
* main: (75 commits)
  Make Storage Sendable (vapor#3056)
  Add Sendable Conformances to undelying types (vapor#3054)
  Resolve issue vapor#2650 (vapor#2674)
  Fix for vapor#2574 Missing quote from value (vapor#2839)
  Allow specifying a timeout for client requests (vapor#3043)
  Update dependencies with known CVEs to the latest versions (vapor#3038)
  Create CODEOWNERS
  Improve error reporting for `EncodingError` and `DecodingError` (vapor#2981)
  Fix incorrect use of non-localhost connection in test
  Update README with new Sponsor (vapor#3025)
  Add `ContentContainer.decode(_:as:)` (vapor#3023)
  Fixed drain handler call order in case of asynchronous buffer handling (vapor#3009)
  Update README with new Sponsor (vapor#3024)
  Update README with new Sponsor (vapor#3020)
  Don't use UnsafeRawBufferPointer.withMemoryRebound(to:_:) before Swift 5.7.2 (vapor#3021)
  Avoid deadlocking websocket tests (vapor#3019)
  Update README with new Sponsor (vapor#3014)
  Fix `Range: bytes=0-0` header not working properly (vapor#3010)
  Remove use of HTTPBin (vapor#3017)
  Improved error logging (vapor#3016)
  ...

# Conflicts:
#	Sources/Vapor/HTTP/Headers/HTTPHeaders+ContentRange.swift
#	Sources/Vapor/Utilities/FileIO.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Contains new API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants