Repository: cloudwego/hertz
Pull request #1050 (2024-01-16 04:17:57)

fix: add full path copy
#### What type of PR is this?

fix

<!--
Add one of the following kinds:

build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
docs: Documentation only changes
feat: A new feature
optimize: A new optimization
fix: A bug fix
perf: A code change that improves performance
refactor: A code change that neither fixes a bug nor adds a feature
style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc)
test: Adding missing tests or correcting existing tests
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
-->

#### Check the PR title.
<!--
The description of the title will be attached in Release Notes, 
so please describe it from user-oriented, what this PR does / why we need it.
Please check your PR title with the below requirements:
-->
- [x] This PR title match the format: \<type\>(optional scope): \<description\>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.
- [x] Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. [User docs repo](https://github.com/cloudwego/cloudwego.github.io)


#### (Optional) Translate the PR title into Chinese.


#### (Optional) More detailed description for this PR(en: English/zh: Chinese).
<!--
Provide more detailed info for review(e.g., it's recommended to provide perf data if this is a perf type PR).
-->
en: add full path copy
zh(optional): 添加 full_path 的 拷贝


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/cloudwego/hertz/pull/1050?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`af5c263`)](https://app.codecov.io/gh/cloudwego/hertz/commit/af5c263d2bd9f33b41a9882fd71e26a8f2c84a0b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) 82.54% compared to head [(`c74ffab`)](https://app.codecov.io/gh/cloudwego/hertz/pull/1050?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego) 82.54%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop    #1050   +/-   ##
========================================
  Coverage    82.54%   82.54%           
========================================
  Files           98       98           
  Lines        10024    10025    +1     
========================================
+ Hits          8274     8275    +1     
  Misses        1254     1254           
  Partials       496      496           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/cloudwego/hertz/pull/1050?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudwego).


Patch:
diff --git a/pkg/app/context.go b/pkg/app/context.go
index 510c972..91b5e0d 100644
--- a/pkg/app/context.go
+++ b/pkg/app/context.go
@@ -795,6 +795,7 @@ func (ctx *RequestContext) Copy() *RequestContext {
 	paramCopy := make([]param.Param, len(cp.Params))
 	copy(paramCopy, cp.Params)
 	cp.Params = paramCopy
+	cp.fullPath = ctx.fullPath
 	cp.clientIPFunc = ctx.clientIPFunc
 	cp.formValueFunc = ctx.formValueFunc
 	cp.binder = ctx.binder


Test patch:
diff --git a/pkg/app/context_test.go b/pkg/app/context_test.go
index 85d686c..7cbe71c 100644
--- a/pkg/app/context_test.go
+++ b/pkg/app/context_test.go
@@ -220,6 +220,7 @@ func TestGet(t *testing.T) {
 func TestCopy(t *testing.T) {
 	t.Parallel()
 	ctx := NewContext(0)
+	ctx.fullPath = "full_path"
 	ctx.Request.Header.Add("header_a", "header_value_a")
 	ctx.Response.Header.Add("header_b", "header_value_b")
 	ctx.Params = param.Params{
@@ -244,6 +245,11 @@ func TestCopy(t *testing.T) {
 				return
 			}
 
+			if c.fullPath != "full_path" {
+				t.Errorf("unexpected value: %#v, expected: %#v", c.fullPath, "full_path")
+				return
+			}
+
 			reqHeaderStr := context.Request.Header.Get("header_a")
 			if reqHeaderStr != "header_value_a" {
 				t.Errorf("unexpected value: %#v, expected: %#v", reqHeaderStr, "header_value_a")