Пример #1
0
func initializeServer(logger lager.Logger, uploaderConfig config.UploaderConfig) ifrit.Runner {
	transport := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   ccUploadDialTimeout,
			KeepAlive: ccUploadKeepAlive,
		}).Dial,
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: uploaderConfig.SkipCertVerify,
		},
		TLSHandshakeTimeout: ccUploadTLSHandshakeTimeout,
	}

	pollerHttpClient := cfhttp.NewClient()
	pollerHttpClient.Transport = transport

	uploader := ccclient.NewUploader(logger, &http.Client{Transport: transport})
	poller := ccclient.NewPoller(logger, pollerHttpClient, time.Duration(uploaderConfig.CCJobPollingInterval))

	ccUploaderHandler, err := handlers.New(uploader, poller, logger)
	if err != nil {
		logger.Error("router-building-failed", err)
		os.Exit(1)
	}

	return http_server.New(uploaderConfig.ListenAddress, ccUploaderHandler)
}
Пример #2
0
		uploadedHeaders  http.Header
	)

	BeforeEach(func() {
		var err error

		logger = lagertest.NewTestLogger("test")

		buffer := bytes.NewBufferString("the file I'm uploading")
		incomingRequest, err = http.NewRequest("POST", "", buffer)
		Expect(err).NotTo(HaveOccurred())
		incomingRequest.Header.Set("Content-MD5", "the-md5")

		fakeCloudController = ghttp.NewServer()

		uploader := ccclient.NewUploader(logger, http.DefaultClient)
		poller := ccclient.NewPoller(logger, http.DefaultClient, 100*time.Millisecond)

		handler, err = handlers.New(uploader, poller, logger)
		Expect(err).NotTo(HaveOccurred())

		postStatusCode = http.StatusCreated
		uploadedBytes = nil
		uploadedFileName = ""
		uploadedHeaders = nil
	})

	AfterEach(func() {
		fakeCloudController.Close()
	})
Пример #3
0
			filename        string
			incomingRequest *http.Request
		)

		BeforeEach(func() {
			uploadURL, _ = url.Parse("http://example.com")
			filename = "filename"
			incomingRequest = createValidRequest()
		})

		Context("when not cancelling", func() {
			JustBeforeEach(func() {
				httpClient := &http.Client{
					Transport: transport,
				}
				u = ccclient.NewUploader(lagertest.NewTestLogger("test"), httpClient)
				response, uploadErr = u.Upload(uploadURL, filename, incomingRequest, make(chan struct{}))
			})

			Context("Validating the content length of the request", func() {
				BeforeEach(func() {
					transport = http.DefaultTransport
					filename = "filename"
					incomingRequest = &http.Request{}
				})

				It("fails early if the content length is 0", func() {
					Expect(response.StatusCode).To(Equal(http.StatusLengthRequired))

					Expect(uploadErr).To(HaveOccurred())
				})