@@ -53,7 +53,6 @@ func devHttpCmdRun(cmd *cobra.Command, args []string) {
5353 }
5454 }
5555
56-
5756 executors := executor .StartAllExecutors (cmd .Context (), store , plugins , nil )
5857 exec , err := executor .ExecutorByName (cmd .Flag ("executor" ).Value .String (), executors )
5958 if err != nil {
@@ -180,53 +179,40 @@ func (p *devHttpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
180179 URL : url ,
181180 }
182181
183- p .executor .HandleMessage (p .context , msg , func (rep * executor.Reply ) {
184- fields := log.Fields {
185- "subject" : msg .Subject ,
186- "url" : msg .URL ,
187- "method" : msg .Method ,
182+ res := p .executor .HandleMessage (p .context , msg , scr )
183+ if res .Error != "" {
184+ if res .Error == (& executor.NoScriptFoundError {}).Error () {
185+ w .WriteHeader (http .StatusNotFound )
186+ } else {
187+ w .WriteHeader (http .StatusInternalServerError )
188188 }
189- log .WithFields (fields ).Debugf ("Results: %s" , string (msg .Payload ))
190-
191- if rep .Error != "" {
192- if rep .Error == (& executor.NoScriptFoundError {}).Error () {
193- w .WriteHeader (http .StatusNotFound )
194- } else {
195- w .WriteHeader (http .StatusInternalServerError )
196- }
197-
198- _ , err = w .Write ([]byte ("Error: " + rep .Error ))
199- if err != nil {
200- log .WithFields (fields ).Errorf ("failed to write error to HTTP response: %v" , err )
201- }
202189
203- return
190+ _ , err = w .Write ([]byte ("Error: " + res .Error ))
191+ if err != nil {
192+ log .WithFields (fields ).Errorf ("failed to write error to HTTP response: %v" , err )
204193 }
205194
206- rep .Results .Range (func (key , value any ) bool {
207- sr := value .(* executor.ScriptResult )
208- if sr .IsHTML {
209- var hasContentType bool
210- for k , v := range sr .Headers {
211- if k == "Content-Type" {
212- hasContentType = true
213- }
214- w .Header ().Add (k , v )
215- }
216- if ! hasContentType {
217- w .Header ().Add ("Content-Type" , "text/html" )
218- }
219- w .WriteHeader (sr .Code )
220-
221- _ , err = w .Write (sr .Payload )
222- if err != nil {
223- log .WithFields (fields ).Errorf ("failed to write reply back to HTTP response: %v" , err )
224- }
195+ return
196+ }
197+
198+ if res .IsHTML {
199+ var hasContentType bool
200+ for k , v := range res .Headers {
201+ if k == "Content-Type" {
202+ hasContentType = true
225203 }
204+ w .Header ().Add (k , v )
205+ }
206+ if ! hasContentType {
207+ w .Header ().Add ("Content-Type" , "text/html" )
208+ }
209+ w .WriteHeader (res .Code )
226210
227- return true
228- })
229- })
211+ _ , err = w .Write (res .Payload )
212+ if err != nil {
213+ log .WithFields (fields ).Errorf ("failed to write reply back to HTTP response: %v" , err )
214+ }
215+ }
230216}
231217
232218func emptyStore (s store.ScriptStore , libraryDir string ) {
0 commit comments