zoukankan      html  css  js  c++  java
  • HTTP&Web Servers——Udacity

    HTTP response construction:

    1.status code 

    2.header

    3.response 

    --------------------------------------------

    url construction:

    scheme://hostname/path

    such as : http://example.net/google.com/ponies

    http->scheme;example.net->hostname ; /google.com/ponies ->path

    hostname ->DNS -> IP

    port  is  a part of hostname 

    ----------------------------------------------

    HTTP methods 

    GET , POST 

    PUT ,DELECT ,PATCH

    ----------------------------------------------

    python 

    lib : http.server 

    function:

    do_http-methods()->  client send you a http method (for example : GET) , the server use do_GET function to deal with the get request.

    HTTPServer(server_address  ,  BaseHTTPRequestHandler) ->  create a server.

    HTTPServer . serve_forever() -> run a HTTPServer Object   forever.

    .read()   ;   .write()  ; decode()  ;  encode()  ; str.format () ; send_header() ; send_response() ; parse_qs()

    #!/usr/bin/env python3
    #
    # An HTTP server that's a message board.
    
    from http.server import HTTPServer, BaseHTTPRequestHandler
    from urllib.parse import parse_qs
    
    memory = []
    
    form = '''<!DOCTYPE html>
      <title>Message Board</title>
      <form method="POST">
        <textarea name="message"></textarea>
        <br>
        <button type="submit">Post it!</button>
      </form>
      <pre>
    {}
      </pre>
    '''
    
    
    class MessageHandler(BaseHTTPRequestHandler):
        def do_POST(self):
            # How long was the message?
            length = int(self.headers.get('Content-length', 0))
    
            # Read and parse the message
            data = self.rfile.read(length).decode()
            message = parse_qs(data)["message"][0]
    
            # Escape HTML tags in the message so users can't break world+dog.
            message = message.replace("<", "&lt;")
    
            # Store it in memory.
            memory.append(message)
    
            # Send a 303 back to the root page
            self.send_response(303)  # redirect via GET
            self.send_header('Location', '/')
            self.end_headers()
    
        def do_GET(self):
            # First, send a 200 OK response.
            self.send_response(200)
    
            # Then send headers.
            self.send_header('Content-type', 'text/html; charset=utf-8')
            self.end_headers()
    
            # Send the form with the messages in it.
            mesg = form.format("
    ".join(memory))
            self.wfile.write(mesg.encode())
    
    if __name__ == '__main__':
        server_address = ('', 8000)
        httpd = HTTPServer(server_address, MessageHandler)
        httpd.serve_forever()

    ---------------------------------

    JSON  - >  dictionary 

    ----------------------------------

    cache 

    --------------------------

    cookies

    -----------------------------------------------------------------

    web  security  - >  https ->  http/1.1  - > http/2 

    -------------------------------------------------

    Other   :  TCP   TLS   SSL  

    cloud: 链接:https://pan.baidu.com/s/1snqiu4l 密码:dtnn

  • 相关阅读:
    信息安全系统设计基础第四周学习内容
    信息安全系统设计基础第三周学习总结
    第十二节 Linux下软件安装
    第十一节 正则表达式基础
    session的生命周期
    session对象
    什么是session
    请求重定向和请求转发的关系
    java web的response对象
    java web中request对象(下)
  • 原文地址:https://www.cnblogs.com/JewinH/p/8352511.html
Copyright © 2011-2022 走看看