httpreserve

package module
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: GPL-3.0 Imports: 15 Imported by: 1

README

httpreserve

GoDoc Go Report Card

A tool to check the status of a weblink and also see whether it is archived in the Internet Archive.

Try it out here httpreserve.info

Default Server

The library comes with a default server mode that can be configured for POST and GET requests. POST by default. Default port is :2040 but this can also be selected at runtime.

Image of the in-built HTTPPreserve server

The default server can also be stood up as a web service. The API is documented below.

Client

The httpreserve client is a separate application offering a broader range of access methods. See: https://github.com/httpreserve/httpreserve-app

The client application is a work in progress. Stay tuned for more information about its capabilities.

API

Primary entry point when the server is running:

http://{httpreserve-ip-address}:{port}/httpreserve

or

http://{httpreserve-ip-address}:{port}/save

GET example:

POST example:

Same access point, but encode url and filename in a <i>application/x-www-form-urlencoded</i> form.

OPTIONS example:

`curl -X OPTIONS http://httpreserve.info | less`

RETURN value:

'application/json' struct to work with, e.g.

  {
     "FileName": "",
     "AnalysisVersionNumber": "0.0.0",
     "AnalysisVersionText": "exponentialDK-httpreserve/0.0.0",
     "Link": "http://www.bbc.co.uk/",
     "ResponseCode": 200,
     "ResponseText": "OK",
     "ScreenShot": "{base64 encoded data}",
     "InternetArchiveLinkLatest": "http://web.archive.org/web/20170326191259/http://www0.bbc.co.uk/",
     "InternetArchiveLinkEarliest": "http://web.archive.org/web/19961221203254/http://www0.bbc.co.uk/",
     "InternetArchiveSaveLink": "http://web.archive.org/save/http://www.bbc.co.uk/",
     "InternetArchiveResponseCode": 200,
     "InternetArchiveResponseText": "OK",
     "Archived": true,
     "Error": false,
     "ErrorMessage": "",
     "StatsCreationTime": "4.506728277s"
  }
License

GNU General Public License Version 3. Full Text

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenerateSnapshotErr = "error generating snapshot"

GenerateSnapshotErr tells us we've something else wrong

View Source
var ResponseIncorrect = "snapshots not created for response codes zero or greater than 400"

ResponseIncorrect tells us we haven't created a screenshot because the domain is no longer in existence...

View Source
var SnapshotNotEnabled = "snapshots are not currently enabled"

SnapshotNotEnabled helps end users verify server status

Functions

func Dedication

func Dedication() string

Dedication will return a dedication string for a colleague's dear brother who was lost on the day I first figured out this code.

func DefaultServer

func DefaultServer(port string, method string) error

DefaultServer is our call to standup a default server for the httpreserve resolver service to be queried by our other apps.

func GetDefaultServerPage

func GetDefaultServerPage(method string) string

GetDefaultServerPage will print an example server page with the template filled in using the given method. Useful for folk who want to learn about this app. A bit of Ajax and a pretty decent way of encoding Base64 data hyperlinks.

func GetLinkStatsHeader

func GetLinkStatsHeader(ls LinkStats) string

GetLinkStatsHeader allows us to do some debug on the information returned from the server. First it mocks a response, and then adds some of our own information to it to enable DumpResponse prettyprint. We will consider its use in future As two pretty printed responses have been added to the struct.

func GetLinkStatsURL

func GetLinkStatsURL(ls LinkStats) *url.URL

GetLinkStatsURL returns the originally parsed URL as was sent to the server for a response.

func GetPrettyRequest

func GetPrettyRequest(ls LinkStats) string

GetPrettyRequest returns the original request but pretty printed..

func GetPrettyResponse

func GetPrettyResponse(ls LinkStats) string

GetPrettyResponse returns the original response but pretty printed.

func MakeLinkStatsJSON

func MakeLinkStatsJSON(ls LinkStats) string

MakeLinkStatsJSON will output a LinkStats struct as a JSON object to be used in our applications...

func Version

func Version() string

Version will return a simple version number for the app.

func VersionNumber

func VersionNumber() string

VersionNumber is a synonym for Version()

func VersionText

func VersionText() string

VersionText will return the full text version information e.g. for the useragent to query our websites.

Types

type LinkStats

type LinkStats struct {
	FileName                    string `json:"FileName,omitempty"` // If a filename is provided
	AnalysisVersionNumber       string
	AnalysisVersionText         string
	SimpleRequestVersion        string
	Link                        string
	Title                       string
	ContentType                 string
	ResponseCode                int
	ResponseText                string
	SourceURL                   string // URL requested by the caller
	ScreenShot                  string // HREF to screenshot
	InternetArchiveLinkEarliest string `json:"InternetArchiveLinkEarliest,omitempty"`
	InternetArchiveEarliestDate string `json:"InternetArchiveEarliestDate,omitempty"`
	InternetArchiveLinkLatest   string
	InternetArchiveLatestDate   string `json:"InternetArchiveLatestDate,omitempty"`
	InternetArchiveSaveLink     string // Link to use to save from the Internet
	InternetArchiveResponseCode int
	InternetArchiveResponseText string
	RobustLinkEarliest          string `json:"RobustLinkEarliest,omitempty"` // A robust hyperlink snippet linking to a live url and a memento version
	RobustLinkLatest            string `json:"RobustLinkLatest,omitempty"`   // A robust hyperlink snippet linking to a live url and a memento version
	PWID                        string `json:PWID,omitempty`                 // Persistent Web Identifier DRAFT URN standard from Denmark.
	Archived                    bool   // Has the Internet Archive saved the page or not?
	Error                       bool
	ErrorMessage                string
	StatsCreationTime           string
	// contains filtered or unexported fields
}

LinkStats Table structure to be returned from our requests Can be fairly liberal in its expansion

func GenerateLinkStats

func GenerateLinkStats(link string, fileName string, screenGrab bool) (LinkStats, error)

GenerateLinkStats is used to return a JSON object for a URL specified in link variable passed to the function.

func GenerateLinkStatsEncoded

func GenerateLinkStatsEncoded(link string, fileName string, screenGrab bool) (LinkStats, error)

GenerateLinkStatsEncoded encodes LinkStat JSON with HTML entities for display online, e.g. on HTTPreserve.info.

func HTTPFromSimpleRequest

func HTTPFromSimpleRequest(sr simplerequest.SimpleRequest, sourceURL string) (LinkStats, error)

HTTPFromSimpleRequest is another mechanism we can use to retrieve some basic information out from a web resource. Call handlehttp from a SimpleRequest object instead of calling function directly...

Jump to

Keyboard shortcuts

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