MCPcopy Create free account
hub / github.com/ImAyrix/fallparams / ParseHttpRequest

Function ParseHttpRequest

funcs/utils/utils.go:123–170  ·  view source on GitHub ↗
(options *opt.Options)

Source from the content-addressed store, hash-verified

121}
122
123func ParseHttpRequest(options *opt.Options) []string {
124 var allUrls []string
125 file, err := os.Open(options.InputHttpRequest)
126 CheckError(err)
127 defer file.Close()
128
129 scanner := bufio.NewScanner(file)
130 var lines []string
131 for scanner.Scan() {
132 lines = append(lines, scanner.Text())
133 }
134
135 if strings.Contains(lines[0], "HTTP/2") {
136 lines[0] = strings.Replace(lines[0], "HTTP/2", "HTTP/1.1", 1)
137 }
138
139 request, err := http.ReadRequest(bufio.NewReader(strings.NewReader(strings.Join(lines, "\n"))))
140 CheckError(err)
141
142 host := request.Host
143 scheme := "http"
144 if request.TLS != nil {
145 scheme = "https"
146 }
147 fullURL := fmt.Sprintf("%s://%s%s", scheme, host, request.URL.RequestURI())
148 allUrls = append(allUrls, fullURL)
149
150 var headers []string
151 for key, values := range request.Header {
152 for _, value := range values {
153 headers = append(headers, fmt.Sprintf("%s: %s", key, value))
154 }
155 }
156
157 var body string
158 if request.Body != nil {
159 bodyBytes, err := ioutil.ReadAll(request.Body)
160 CheckError(err)
161 body = string(bodyBytes)
162 request.Body = ioutil.NopCloser(strings.NewReader(body))
163 }
164
165 options.CustomHeaders = append(options.CustomHeaders, headers...)
166 options.RequestHttpMethod = request.Method
167 options.RequestBody = body
168
169 return allUrls
170}

Callers 2

mainFunction · 0.92
GetInputFunction · 0.85

Calls 1

CheckErrorFunction · 0.85

Tested by

no test coverage detected