Merge from develop

This commit is contained in:
swaits committed 2015-02-18 07:55:42 -08:00
commit 4baebdda93
4 files changed
+12 -12

No files matched your search

+1 -1
View File
@@ -116,7 +116,7 @@ func crawlWorker(txchan <-chan *httpItem, rxchan chan<- *httpItem) {
// read off the incoming item channel forever // read off the incoming item channel forever
for newJob := range txchan { for newJob := range txchan {
// perform the crawl // perform the crawl
crawlItem(newJob) newJob.crawlItem()
// return the result // return the result
rxchan <- newJob rxchan <- newJob
} }
+4 -4
View File
@@ -62,7 +62,7 @@ func TestSimpleFetch(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New httpItem struct") t.Error("problem creating New httpItem struct")
} }
body, err := fetchItem(page) body, err := page.fetchItem()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -161,7 +161,7 @@ func TestHeaderFetching(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New httpItem struct") t.Error("problem creating New httpItem struct")
} }
if err := fetchFiletype(basepage); err != nil || basepage.linkType != tHTMLPage { if err := basepage.fetchFiletype(); err != nil || basepage.linkType != tHTMLPage {
t.Error("problem fetching filetype") t.Error("problem fetching filetype")
} }
@@ -169,7 +169,7 @@ func TestHeaderFetching(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New httpItem struct") t.Error("problem creating New httpItem struct")
} }
if err := fetchFiletype(page); err != nil || page.linkType != tHTMLPage { if err := page.fetchFiletype(); err != nil || page.linkType != tHTMLPage {
t.Error("problem fetching filetype") t.Error("problem fetching filetype")
} }
@@ -177,7 +177,7 @@ func TestHeaderFetching(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New httpItem struct") t.Error("problem creating New httpItem struct")
} }
if err := fetchFiletype(page); err != nil || page.linkType != tAsset { if err := page.fetchFiletype(); err != nil || page.linkType != tAsset {
t.Logf("got %q, wanted %q", page.linkType, tAsset) t.Logf("got %q, wanted %q", page.linkType, tAsset)
t.Error("problem fetching filetype") t.Error("problem fetching filetype")
} }
+5 -5
View File
@@ -16,7 +16,7 @@ var (
// fetchFiletype performs an http HEAD to get the media type, and sets it // fetchFiletype performs an http HEAD to get the media type, and sets it
// directly in httpItem.mediaType // directly in httpItem.mediaType
func fetchFiletype(item *httpItem) error { func (item *httpItem) fetchFiletype() error {
resp, err := http.Head(item.url.String()) resp, err := http.Head(item.url.String())
if err != nil { if err != nil {
item.linkType = tBroken item.linkType = tBroken
@@ -54,9 +54,9 @@ func fetchFiletype(item *httpItem) error {
} }
// fetchPage takes a httpItem, GETs it, and returns the body as a string // fetchPage takes a httpItem, GETs it, and returns the body as a string
func fetchItem(item *httpItem) (string, error) { func (item *httpItem) fetchItem() (string, error) {
// figure out the file type // figure out the file type
err := fetchFiletype(item) err := item.fetchFiletype()
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -95,7 +95,7 @@ func fetchItem(item *httpItem) (string, error) {
// crawlItem crawls a single httpItem, fetching the header, hte page, parsing it, // crawlItem crawls a single httpItem, fetching the header, hte page, parsing it,
// and filling out its structure as much as possible // and filling out its structure as much as possible
func crawlItem(item *httpItem) { func (item *httpItem) crawlItem() {
// make sure this item is the same domain (i.e. URL "host part") as its referrer // make sure this item is the same domain (i.e. URL "host part") as its referrer
if item.refurl != nil && item.url.Host != item.refurl.Host { if item.refurl != nil && item.url.Host != item.refurl.Host {
// skip URLs associated with other Hosts // skip URLs associated with other Hosts
@@ -104,7 +104,7 @@ func crawlItem(item *httpItem) {
} }
// fetch page // fetch page
text, err := fetchItem(item) text, err := item.fetchItem()
if err != nil { if err != nil {
return return
} }
+2 -2
View File
@@ -10,7 +10,7 @@ func TestFailedHeaderFetching(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New Page struct") t.Error("problem creating New Page struct")
} }
if err := fetchFiletype(page); err == nil { if err := page.fetchFiletype(); err == nil {
t.Error("tired fetching bogus page but didn't get nil back from fetchFiletype") t.Error("tired fetching bogus page but didn't get nil back from fetchFiletype")
} }
} }
@@ -21,7 +21,7 @@ func TestFailedFetching(t *testing.T) {
if err != nil { if err != nil {
t.Error("problem creating New Page struct") t.Error("problem creating New Page struct")
} }
if _, err := fetchItem(page); err == nil { if _, err := page.fetchItem(); err == nil {
t.Error("tired fetching bogus page but didn't get nil back from fetchPage") t.Error("tired fetching bogus page but didn't get nil back from fetchPage")
} }
} }