• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1898182370

30 Jun 2025 02:51PM UTC coverage: 65.621% (-0.1%) from 65.731%
1898182370

Pull #772

gitlab-ci

alfrunes
refactor(useradm): Create utility function to load JWT PKI

... to lower cyclomatic complexity for main.RunServer.

Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #772: MEN-7745: Add rate limiting support to authenticated useradm requests

212 of 404 new or added lines in 12 files covered. (52.48%)

1 existing line in 1 file now uncovered.

32534 of 49579 relevant lines covered (65.62%)

1.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.26
/backend/pkg/rest.utils/request.go
1
// Copyright 2025 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package rest
16

17
import (
18
        "net/http"
19
        "net/url"
20
)
21

22
// RewriteForwardedRequest makes a shallow clone of request and replaces
23
// the URL and Method with X-Forwarded-* headers.
24
func RewriteForwardedRequest(request *http.Request) *http.Request {
1✔
25
        newRequest := new(http.Request)
1✔
26
        *newRequest = *request
1✔
27
        uri := request.Header.Get("X-Forwarded-Uri")
1✔
28
        if uri != "" {
2✔
29
                var err error
1✔
30
                newRequest.URL, err = url.ParseRequestURI(uri)
1✔
31
                if err != nil {
1✔
NEW
32
                        panic(err)
×
33
                }
34
                newRequest.RequestURI = uri
1✔
NEW
35
        } else {
×
NEW
36
                newRequest.URL = new(url.URL)
×
NEW
37
                *newRequest.URL = *request.URL
×
NEW
38
        }
×
39
        host := request.Header.Get("X-Forwarded-Host")
1✔
40
        if host != "" {
2✔
41
                newRequest.URL.Host = host
1✔
42
        }
1✔
43
        method := request.Header.Get("X-Forwarded-Method")
1✔
44
        if method != "" {
2✔
45
                newRequest.Method = method
1✔
46
        }
1✔
47
        return newRequest
1✔
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc