@@ -26,6 +26,7 @@ type HTTPServer struct {
26
26
headers []string
27
27
showClientHeaders bool
28
28
showServerHeaders bool
29
+ text bool
29
30
}
30
31
31
32
var HTTPServerFormUploadPage = []byte (`
@@ -53,6 +54,7 @@ func (m *HTTPServer) SetFlagSet(fs *pflag.FlagSet, args []string) {
53
54
fs .StringVar (& m .user , "user" , "" , "Specify the required user for basic auth" )
54
55
fs .StringVar (& m .password , "password" , "" , "Specify the required password for basic auth" )
55
56
fs .StringVar (& m .redirect , "redirect-to" , "" , "Redirect the request to where the download can begin" )
57
+ fs .BoolVar (& m .text , "text" , false , "Set headers to show the content as text/plain rather than as an attachment" )
56
58
}
57
59
58
60
func HTTPServerHandleResponse (m * HTTPServer , w http.ResponseWriter , req * http.Request , relay * HTTPServerRelayer ) {
@@ -107,8 +109,20 @@ func HTTPServerHandleResponse(m *HTTPServer, w http.ResponseWriter, req *http.Re
107
109
return
108
110
}
109
111
110
- w .Header ().Add ("Content-Type" , "application/octet-stream" )
111
- w .Header ().Add ("Content-Disposition" , "attachment;" )
112
+ if w .Header ().Get ("Content-Type" ) == "" {
113
+ w .Header ().Set ("Content-Type" , "application/octet-stream" )
114
+ }
115
+
116
+ if w .Header ().Get ("Content-Disposition" ) == "" {
117
+ w .Header ().Set ("Content-Disposition" , "attachment;" )
118
+ }
119
+
120
+ // Override headers if --text is set
121
+ if m .text {
122
+ w .Header ().Set ("Content-Type" , "text/plain" )
123
+ w .Header ().Set ("Content-Disposition" , "inline;" )
124
+ }
125
+
112
126
if m .showServerHeaders {
113
127
ShowHTTPServerHeaders (w .Header ())
114
128
}
0 commit comments