-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Classe responsável por pegar as principais informações de um cabeçalh…
…o HTTP
- Loading branch information
0 parents
commit c0ace27
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
#!/usr/bin/env python | ||
|
||
import httplib | ||
import socket | ||
|
||
__author__ = 'Bruno Barbosa' | ||
|
||
|
||
class ChecaCabecalho: | ||
def __init__(self, *args): | ||
self._url = args | ||
|
||
def get_url(self): | ||
return self._url | ||
|
||
def get_error(self, num): | ||
erros = {1:"Falha na conexão: O host conectado não respondeu!"} | ||
return erros[num] | ||
|
||
|
||
def get_cabecalho(self): | ||
|
||
links = self.get_url() | ||
|
||
for link in links: | ||
|
||
conn = httplib.HTTPConnection(link) | ||
try: | ||
conn.request("GET", "/") | ||
except socket.error: | ||
return self.get_error(1) | ||
|
||
result = conn.getresponse() | ||
|
||
return result.status, result.reason | ||
|