http

package
v0.0.0-...-0fe5c75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2019 License: AGPL-3.0 Imports: 8 Imported by: 1

README

creamy-transcode/files/drivers/http

HTTP Driver that allows downloading from remote HTTP sources and uploading to remote HTTP destinations.

Usage

Download
err := driver.Download("https://albinodrought.com/", "hi.html")
Upload

Files are POSTed to the given URL under the FormData key file.

To change this, use the http_file_name query parameter.

// default formdata key
err := driver.Upload("hi.html", "https://albinodrought.com/")

// custom formdata key
err := driver.Upload("hi.html", "https://albinodrought.com/?http_file_name=encoded_video")

Example

package main

import (
	"log"

	"github.com/AlbinoDrought/creamy-transcode/files/drivers/http"
	"github.com/imroc/req"
)

func main() {
	req.Debug = true

	driver := http.Driver{}

	err := driver.Download("https://albinodrought.com/", "hi.html")
	if err != nil {
		log.Fatalf("failed to download: %v", err)
	}

	err = driver.Upload("hi.html", "https://albinodrought.com/")
	if err != nil {
		log.Fatalf("failed to upload: %v", err)
	}

	err = driver.Upload("hi.html", "https://albinodrought.com/?http_file_name=honey")
	if err != nil {
		log.Fatalf("failed to upload with different key: %v", err)
	}
}

// Output: (the 405 responses are because albinodrought.com doesn't accept POST requests)
/*
POST / HTTP/1.1
Host: albinodrought.com
User-Agent: Go-http-client/1.1
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=15c3dc206cd19609cb2c69111093795ae2ea8264593ec8685f62972b4d16
Accept-Encoding: gzip

--1ba46da54b9bdfa9c4ff22b04cb1d5058c13decedddf416ca11f301e1c20
Content-Disposition: form-data; name="file"; filename="hi.html"
Content-Type: application/octet-stream

******
--1ba46da54b9bdfa9c4ff22b04cb1d5058c13decedddf416ca11f301e1c20--


=================================

HTTP/1.1 405 Not Allowed
Content-Length: 157
Content-Type: text/html
Date: Thu, 28 Mar 2019 05:15:23 GMT
Server: nginx/1.15.9
Strict-Transport-Security: max-age=16000000

<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>

POST /?http_file_name=honey HTTP/1.1
Host: albinodrought.com
User-Agent: Go-http-client/1.1
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=1dd1a1cf77ff01136a184a55982a5603ffd8c7cffa202b616a47f3515995
Accept-Encoding: gzip

--2b37ce6cd7bcebacfed0a5c84b0d3a512a6516bd379db42656806a7c6dfb
Content-Disposition: form-data; name="honey"; filename="hi.html"
Content-Type: application/octet-stream

******
--2b37ce6cd7bcebacfed0a5c84b0d3a512a6516bd379db42656806a7c6dfb--


=================================

HTTP/1.1 405 Not Allowed
Content-Length: 157
Content-Type: text/html
Date: Thu, 28 Mar 2019 05:15:23 GMT
Server: nginx/1.15.9
Strict-Transport-Security: max-age=16000000

<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.15.9</center>
</body>
</html>
*/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct{}

Driver handles downloading of files from HTTP sources

func (Driver) Download

func (driver Driver) Download(source string, dest string) error

Download the file from some HTTP source to a local destination

func (Driver) Handles

func (driver Driver) Handles(path string) bool

Handles returns true if the path is an HTTP resource

func (Driver) Upload

func (driver Driver) Upload(source string, dest string) error

Upload the file from a local source to some HTTP destination

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL