-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the http-debug code in its own low-level transport
This makes the code slighly saner and fixes the bug where the first NTLM and digest authentication requests weren't displayed. But by no means does this fix all of the bugs in the http-debug code... For those, see: - #986 - #1042 - #774 A discussion how some or all of them can be fixed can be found here: #1102 (comment)
- Loading branch information
Showing
3 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* | ||
* k6 - a next-generation load testing tool | ||
* Copyright (C) 2019 Load Impact | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package httpext | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httputil" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type httpDebugTransport struct { | ||
//TODO: get the state and log to its Logger | ||
originalTransport http.RoundTripper | ||
httpDebugOption string | ||
} | ||
|
||
// RoundTrip prints passing HTTP requests and received responses | ||
// | ||
// TODO: massively improve this, because the printed information can be wrong: | ||
// - https://github.com/loadimpact/k6/issues/986 | ||
// - https://github.com/loadimpact/k6/issues/1042 | ||
// - https://github.com/loadimpact/k6/issues/774 | ||
func (t httpDebugTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
// Make an initial reques | ||
t.debugRequest(req) | ||
resp, err := t.originalTransport.RoundTrip(req) | ||
t.debugResponse(resp) | ||
return resp, err | ||
} | ||
|
||
func (t httpDebugTransport) debugRequest(req *http.Request) { | ||
dump, err := httputil.DumpRequestOut(req, t.httpDebugOption == "full") | ||
if err != nil { | ||
log.Fatal(err) //TODO: fix... | ||
} | ||
fmt.Printf("Request:\n%s\n", dump) //TODO: fix... | ||
} | ||
|
||
func (t httpDebugTransport) debugResponse(res *http.Response) { | ||
if res != nil { | ||
dump, err := httputil.DumpResponse(res, t.httpDebugOption == "full") | ||
if err != nil { | ||
log.Fatal(err) //TODO: fix... | ||
} | ||
fmt.Printf("Response:\n%s\n", dump) //TODO: fix... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters