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

Nima WebClient headers methods #7034

Closed
8 tasks done
Tracked by #6683
romain-grecourt opened this issue Jun 21, 2023 · 0 comments · Fixed by #7056
Closed
8 tasks done
Tracked by #6683

Nima WebClient headers methods #7034

romain-grecourt opened this issue Jun 21, 2023 · 0 comments · Fixed by #7056
Assignees
Milestone

Comments

@romain-grecourt
Copy link
Contributor

romain-grecourt commented Jun 21, 2023

In v3 we had this:

WebClientRequestHeaders headers =
        WebClient.builder()
                 .addHeader("h1", "v1") // String, String
                 .addCookie("foo", "bar")
                // default contentType and accepted cannot be set in the builder
                 .build()
                 .get()
                 .addHeader("h2", "v1", "v2") // String, String...
                 .addHeader("h3", List.of("v1", "v2"))  // String, List<String>
                 .headers(h -> {
                     h.add("h4", "v1", "v2"); // String, String...
                     h.add("h5", List.of("v1", "v2")); // String, List<String>
                     return h;
                 })
                 .addHeaders(HashParameters.create(Map.of("h6", List.of("v1", "v2")))) // bulk add
                 .headers(HashHeaders.create(Map.of("h6", List.of("v1", "v2")))) // bulk set
                 .contentType(MediaType.APPLICATION_XML)
                 .accept(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON)
                 .headers(); // ClientRequestHeaders getter

As of V4 pre M1 we have this:

Http1Client.builder()
           .header(Header.create(Header.create("h1"), "v1", "v2"))  // HeaderValue
           //.header(HeaderName, String...) is missing
           .header(Header.create("h3"), List.of("v1", "v2")) // HeaderName, List<String>
           .headers(h -> {
               // ClientRequestHeaders
               return h;
           })
           .build()
           .get()
           .header(Header.create(Header.create("h6"), "v1")) // HeaderValue
           .header(Header.create("h7"), "v1") // HeaderName, String          <-- Not 'String...'
           // .header(HeaderName, List<String>) is missing
           .headers(h -> {
               // ClientRequestHeaders, same as above
               return h;
           })
            //.accept(HttpMediaType) is missing
            // contentType(HttpMediaType) is missing 
            // .headers() is missing

Header value types

  • Add WebClient.Builder.header(HeaderName, String... value)
  • Update ClientRequest.header(Http.HeaderName name, String value) to use varag for the value
  • Add ClientRequest.header(Http.HeaderName name, List<String> value)

This will make the methods available on WebClient.Builder and ClientRequest symmetrical, (variants for String..., and List<String> for all header)

MediaType

  • Add ClientRequest.contentType(Mediatype)
  • Update ClientRequestHeaders.accept(HttpMediatype... accepted) to use HttpMediatype instead since the implementation of the method does not require it and HttpMediatype extends MediaType
  • Add ClientRequest.accept(Mediatype... acceptedTypes)

Ignoring HttpMediaType variants, see details in #7058

Bulk add

V3 WebClientRequestBuilder had methods to operate on bulk headers

  • one that adds bulk headers, see the javadoc
  • one that sets (or resets) all headers, see the javadoc

There is no way to easily add bulk headers (E.g. from a server request):

  • Add ClientRequest.headers(Headers)

The hard set (or reset) can be achieved with .headers(Function<ClientRequestHeaders, WritableHeaders<?>>)

ClientRequestHeaders getter

The only way to inspect the headers is to use .headers(Function<ClientRequestHeaders, WritableHeaders<?>>)

  • Add ClientRequest.headers() : ClientRequestHeaders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants