Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Conversation

ElfSundae
Copy link
Contributor

@ElfSundae ElfSundae commented Apr 18, 2020

Issue Link 🔗

https://github.com/AFNetworking/AFNetworking/issues/4549

Goals ⚽

Currently, AFHTTPSessionManager uses -addValue:forHTTPHeaderField: to add HTTP headers to an individual request, that will append the value to the existing field specified in the request serializer.

In general, we prefer to replace the default value, instead of appending things to the default value with a comma, right?

Implementation Details 🚧

This PR changes -addValue:forHTTPHeaderField: to -setValue:forHTTPHeaderField:. In my opinion, using -setValue: is more reasonable and clearer.

Testing Details 🔍

Tests were added to verify setting HTTP headers per request will replace the default value.

Copy link
Member

@jshier jshier left a comment

Choose a reason for hiding this comment

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

This is generally correct I think, but I'd like you to trace the history of the addValue implementation. There may be a specific reason it was written like this. Additionally, this change should be tested so that we can both verify the behavior and ensure future changes don't break it.

@ElfSundae
Copy link
Contributor Author

Setting headers per request is introduced from #4113 . At first I also doubted whether there were special reasons to use addValue, I searched the history and no other discussion about this.
Yes, tests are neccessary, but may be later.

@jshier
Copy link
Member

jshier commented Apr 19, 2020

Sorry, tests need to be added as part of this PR, and really any code change going forward. It's the only way to ensure the integrity of the library.

Also, would you mind summarizing the issue this fixes?

@ElfSundae
Copy link
Contributor Author

Tests are added. "later" I meant is now. 😄 I was going out.

@ElfSundae
Copy link
Contributor Author

would you mind summarizing the issue this fixes?

Do you mean updating the changelog file? Sorry I'm afraid I can't cause I'm not good at English :(

@ElfSundae
Copy link
Contributor Author

It might be:

Changes

  • Setting HTTP headers per request in AFHTTPSessionManager methods now replaces the default value specified in the request serializer.

@jshier
Copy link
Member

jshier commented Apr 19, 2020

would you mind summarizing the issue this fixes?

Do you mean updating the changelog file? Sorry I'm afraid I can't cause I'm not good at English :(

No, I just meant that you should fill out the PR template so that everyone can see why you're making a change and how you did so. Otherwise there might be a lot of unnecessary questions during review.

Copy link
Member

@jshier jshier 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 the test!

@jshier jshier merged commit f188585 into AFNetworking:master Apr 20, 2020
@jshier jshier added this to the 4.0.1 milestone Apr 20, 2020
jshier pushed a commit that referenced this pull request Apr 20, 2020
* Replace instead of appending to the default header

* Add tests for setting HTTP headers per request
jshier added a commit that referenced this pull request Apr 20, 2020
* Fix serverTrust crash (#4542)

* Update readme, add stale bot, add issue template, add pull request template

* Update copy from Alamofire

* Fix crash on nil serverTrust

* Expose server trust error

* add test for error throws

* Fix nullability

* Fix evaluateServerTrust determination (#4552)

Co-authored-by: Jon Shier <jon@jonshier.com>

* Revert changes making error generation public.

This reverts commit 111352b.

# Conflicts:
#	AFNetworking/AFURLSessionManager.m

* Make static error function a method instead.

* Make trust generatio part of AFTestCase.

* Add test cases for server trust error generation.

* Mark parameters explicitly nullable.

* Fix nullability (#4551)

* Replace instead of appending to the default header (#4550)

* Replace instead of appending to the default header

* Add tests for setting HTTP headers per request

* Fix SPM usage with better publicHeadersPath. (#4554)

Co-authored-by: Jakub Kašpar <kaspikk@gmail.com>
Co-authored-by: Elf Sundae <elf.sundae@gmail.com>
@ElfSundae
Copy link
Contributor Author

PR description was updated.

@ElfSundae ElfSundae deleted the overwrite-default-headers branch April 21, 2020 08:40
parkboo added a commit to parkboo/AFNetworking that referenced this pull request Sep 22, 2020
* commit '77ef5fed64d98107acd177a90182163a20ba4567': (31 commits)
  Use low priority queue instead of background for SCNetworkReachabilityGetFlags() (AFNetworking#4587)
  Exempt "needs investigation" from stalebot.
  Only mark unlabeled issues as stale.
  Loop over only changed keypaths in request serializer (AFNetworking#4581)
  Disable 'Zombie Objects' diagnostics for tvOS scheme (AFNetworking#4572)
  Fix docblock for setAuthenticationChallengeHandler (AFNetworking#4574)
  Fix type in CHANGELOG. (AFNetworking#4562)
  Prepare 4.0.1 Release (AFNetworking#4555)
  Fix ServerTrustError crash. (AFNetworking#4553)
  Fix SPM usage with better publicHeadersPath. (AFNetworking#4554)
  Replace instead of appending to the default header (AFNetworking#4550)
  Fix nullability (AFNetworking#4551)
  Update CHANGELOG.md (AFNetworking#4537)
  Fix UIKit+AFNetworking.h (AFNetworking#4536)
  Remove unused UIImage+AFNetworking.h (AFNetworking#4535)
  Separate bundle identifier for watchOS target (AFNetworking#4533)
  Fix MobileCoreServices renamed warning, close #4520 (AFNetworking#4532)
  Add FOUNDATION_EXPORT for AFJSONObjectByRemovingKeysWithNullValues (AFNetworking#4529)
  (Infra) Make infra changes to cleanup project and simplify its maintenance (AFNetworking#4531)
  Improve podspec (AFNetworking#4528)
  ...

# Conflicts:
#	Framework/AFNetworking.h
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants