<commit_before>package proxy

import (
	"net/http"
)

type startContainerInterceptor struct{ proxy *Proxy }

func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error {
	container, err := inspectContainerInPath(i.proxy.client, r.URL.Path)
	if err != nil {
		return err
	}

	if containerShouldAttach(container) && r.Header.Get("Content-Type") == "application/json" {
		hostConfig := map[string]interface{}{}
		if err := unmarshalRequestBody(r, &hostConfig); err != nil {
			return err
		}

		i.proxy.addWeaveWaitVolume(hostConfig)
		if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" {
			if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, dnsDomain); err != nil {
				return err
			}
		}

		if err := marshalRequestBody(r, hostConfig); err != nil {
			return err
		}
	}
	i.proxy.createWait(r, container.ID)
	return nil
}

func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
	defer i.proxy.removeWait(r.Request)
	if r.StatusCode < 200 || r.StatusCode >= 300 { // Docker didn't do the start
		return nil
	}
	i.proxy.waitForStart(r.Request)
	return nil
}<commit_msg>Don't create a HostConfig accidentally if none was passed in<commit_after>package proxy

import (
	"net/http"
)

type startContainerInterceptor struct{ proxy *Proxy }

func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error {
	container, err := inspectContainerInPath(i.proxy.client, r.URL.Path)
	if err != nil {
		return err
	}

	// If the client has sent some JSON which might be a HostConfig, add our
	// parameters back into it, otherwise Docker will consider them overwritten
	if containerShouldAttach(container) && r.Header.Get("Content-Type") == "application/json" {
		hostConfig := map[string]interface{}{}
		if err := unmarshalRequestBody(r, &hostConfig); err != nil {
			return err
		}
		if len(hostConfig) > 0 {
			i.proxy.addWeaveWaitVolume(hostConfig)
			if dnsDomain := i.proxy.getDNSDomain(); dnsDomain != "" {
				if err := i.proxy.setWeaveDNS(hostConfig, container.Config.Hostname, dnsDomain); err != nil {
					return err
				}
			}

			if err := marshalRequestBody(r, hostConfig); err != nil {
				return err
			}
		}
	}
	i.proxy.createWait(r, container.ID)
	return nil
}

func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error {
	defer i.proxy.removeWait(r.Request)
	if r.StatusCode < 200 || r.StatusCode >= 300 { // Docker didn't do the start
		return nil
	}
	i.proxy.waitForStart(r.Request)
	return nil
}
{'fraction_non_alphanumeric': 0.124750099960016, 'fraction_numerical': 0.005197920831667333, 'mean_word_length': 4.148148148148148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5883278', 'n_tokens_mistral': 899, 'n_tokens_neox': 822, 'n_words': 210}