Repository: go-resty/resty
Pull request #428 (2021-05-11 00:37:01)

Update Bazel build to work with 4.0.0
This includes several updates to the BUILD and WORKSPACE files, so that they now work with Bazel 4.0.0, Gazelle 0.23 and rules_go 0.27.

By default, [Gazelle now uses](https://github.com/bazelbuild/bazel-gazelle/pull/863) the last component of the Bazel package, rather than `go_default_library` as the `go_library name`.

This causes problems when the naming conventions do not match.
https://github.com/bazelbuild/bazel-gazelle/issues/890#issuecomment-685145667

Adding support for the new naming convention should not break anything that depends on using the old naming convention, because the Gazelle option `import_alias` makes aliases to the libraries and this allows the old naming convention to still work.

jeevatkm: @tanyabouman Travis CI build link was broken. I have migrated travis-ci.org to travis-ci.com

Can you please edit the PR or close & reopen it to trigger the CI build?

Patch:
diff --git a/.travis.yml b/.travis.yml
index 583a039..9b4aa53 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,8 +3,8 @@ language: go
 os: linux
 
 go: # use travis ci resource effectively, keep always latest 2 versions and tip :) 
+  - 1.16.x
   - 1.15.x
-  - 1.14.x
   - tip
 
 install:
diff --git a/BUILD.bazel b/BUILD.bazel
index 6c47cbb..03bb44c 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,36 +1,48 @@
-package(default_visibility = ["//visibility:private"])
-
-load("@bazel_gazelle//:def.bzl", "gazelle")
 load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+load("@bazel_gazelle//:def.bzl", "gazelle")
 
-gazelle(
-    name = "gazelle",
-    command = "fix",
-    prefix = "github.com/go-resty/resty/v2",
-)
+# gazelle:prefix github.com/go-resty/resty/v2
+# gazelle:go_naming_convention import_alias
+gazelle(name = "gazelle")
 
 go_library(
-    name = "go_default_library",
-    srcs = glob(
-        ["*.go"],
-        exclude = ["*_test.go"],
-    ),
+    name = "resty",
+    srcs = [
+        "client.go",
+        "middleware.go",
+        "redirect.go",
+        "request.go",
+        "response.go",
+        "resty.go",
+        "retry.go",
+        "trace.go",
+        "transport.go",
+        "transport112.go",
+        "util.go",
+    ],
     importpath = "github.com/go-resty/resty/v2",
     visibility = ["//visibility:public"],
     deps = ["@org_golang_x_net//publicsuffix:go_default_library"],
 )
 
 go_test(
-    name = "go_default_test",
-    srcs =
-        glob(
-            ["*_test.go"],
-            exclude = ["example_test.go"],
-        ),
-    data = glob([".testdata/*"]),
-    embed = [":go_default_library"],
-    importpath = "github.com/go-resty/resty/v2",
-    deps = [
-        "@org_golang_x_net//proxy:go_default_library",
+    name = "resty_test",
+    srcs = [
+        "client_test.go",
+        "context_test.go",
+        "example_test.go",
+        "request_test.go",
+        "resty_test.go",
+        "retry_test.go",
+        "util_test.go",
     ],
+    data = glob([".testdata/*"]),
+    embed = [":resty"],
+    deps = ["@org_golang_x_net//proxy:go_default_library"],
+)
+
+alias(
+    name = "go_default_library",
+    actual = ":resty",
+    visibility = ["//visibility:public"],
 )
diff --git a/README.md b/README.md
index 819fbf3..2088cc3 100644
--- a/README.md
+++ b/README.md
@@ -107,7 +107,7 @@ Resty author also published following projects for Go Community.
 
 ```bash
 # Go Modules
-require github.com/go-resty/resty/v2 v2.4.0
+require github.com/go-resty/resty/v2 v2.6.0
 ```
 
 ## Usage
@@ -829,13 +829,13 @@ client.SetTransport(&transport).SetScheme("http").SetHostURL(unixSocket)
 client.R().Get("/index.html")
 ```
 
-#### Bazel support
+#### Bazel Support
 
 Resty can be built, tested and depended upon via [Bazel](https://bazel.build).
 For example, to run all tests:
 
 ```shell
-bazel test :go_default_test
+bazel test :resty_test
 ```
 
 #### Mocking http requests using [httpmock](https://github.com/jarcoal/httpmock) library
@@ -876,7 +876,7 @@ BTW, I'd like to know what you think about `Resty`. Kindly open an issue or send
 
 ## Core Team
 
-Have a look on [Members](https://github.com/orgs/go-resty/teams/core/members) page.
+Have a look on [Members](https://github.com/orgs/go-resty/people) page.
 
 ## Contributors
 
diff --git a/WORKSPACE b/WORKSPACE
index 5459d63..9ef03e9 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,26 +1,30 @@
 workspace(name = "resty")
 
-git_repository(
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
     name = "io_bazel_rules_go",
-    remote = "https://github.com/bazelbuild/rules_go.git",
-    tag = "0.13.0",
+    sha256 = "69de5c704a05ff37862f7e0f5534d4f479418afc21806c887db544a316f3cb6b",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
+        "https://github.com/bazelbuild/rules_go/releases/download/v0.27.0/rules_go-v0.27.0.tar.gz",
+    ],
 )
 
-git_repository(
+http_archive(
     name = "bazel_gazelle",
-    remote = "https://github.com/bazelbuild/bazel-gazelle.git",
-    tag = "0.13.0",
+    sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
+    urls = [
+        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
+        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
+    ],
 )
 
-load(
-    "@io_bazel_rules_go//go:def.bzl",
-    "go_rules_dependencies",
-    "go_register_toolchains",
-)
+load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
 
 go_rules_dependencies()
 
-go_register_toolchains()
+go_register_toolchains(version = "1.16")
 
 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
 
diff --git a/request.go b/request.go
index 41709cf..b9d0184 100644
--- a/request.go
+++ b/request.go
@@ -117,6 +117,22 @@ func (r *Request) SetHeaders(headers map[string]string) *Request {
 	return r
 }
 
+// SetHeaderMultiValues sets multiple headers fields and its values is list of strings at one go in the current request.
+//
+// For Example: To set `Accept` as `text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8`
+//
+// 		client.R().
+//			SetHeaderMultiValues(map[string][]string{
+//				"Accept": []string{"text/html", "application/xhtml+xml", "application/xml;q=0.9", "image/webp", "*/*;q=0.8"},
+//			})
+// Also you can override header value, which was set at client instance level.
+func (r *Request) SetHeaderMultiValues(headers map[string][]string) *Request {
+	for key, values := range headers {
+		r.SetHeader(key, strings.Join(values, ", "))
+	}
+	return r
+}
+
 // SetHeaderVerbatim method is to set a single header field and its value verbatim in the current request.
 //
 // For Example: To set `all_lowercase` and `UPPERCASE` as `available`.


Test patch:
diff --git a/request_test.go b/request_test.go
index 368463a..e0b6065 100644
--- a/request_test.go
+++ b/request_test.go
@@ -1371,6 +1371,19 @@ func TestSetHeaderVerbatim(t *testing.T) {
 	assertEqual(t, "value_standard", r.Header.Get("Header-Lowercase"))
 }
 
+func TestSetHeaderMultipleValue(t *testing.T) {
+	ts := createPostServer(t)
+	defer ts.Close()
+
+	r := dclr().
+		SetHeaderMultiValues(map[string][]string{
+			"Content":       []string{"text/*", "text/html", "*"},
+			"Authorization": []string{"Bearer xyz"},
+		})
+	assertEqual(t, "text/*, text/html, *", r.Header.Get("content"))
+	assertEqual(t, "Bearer xyz", r.Header.Get("authorization"))
+}
+
 func TestOutputFileWithBaseDirAndRelativePath(t *testing.T) {
 	ts := createGetServer(t)
 	defer ts.Close()