【Python】打造自己的HTTP server

server/2025/2/26 0:59:06/
http://www.w3.org/2000/svg" style="display: none;">

词汇汇总

CRLF 指的是换行和回车\r\n

教程

./your_program.sh #启动自己的服务curl -v http://localhost:4221#开启另一个终端 测试
  • HTTP response
    An HTTP response is made up of three parts, each separated by a CRLF (\r\n):
    Status line.
    Zero or more headers, each ending with a CRLF.
    Optional response body.
    先来一个简单的,只包含状态行。
python">// Status line
HTTP/1.1  // HTTP version
200       // Status code
OK        // Optional reason phrase
\r\n      // CRLF that marks the end of the status line// Headers (empty)
\r\n      // CRLF that marks the end of the headers// Response body (empty)#main.py
import socket  # noqa: F401def main():# You can use print statements as follows for debugging, they'll be visible when running tests.print("Logs from your program will appear here!")# Uncomment this to pass the first stage#server_socket = socket.create_server(("localhost", 4221), reuse_port=True)server_socket.accept() # wait for clientserver_socket.accept()[0].sendall(b"HTTP/1.1 200 OK\r\n\r\n")if __name__ == "__main__":main()
#your_program.sh
#通过执行./your_program.sh执行这个文件
#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interfaceset -e # Exit early if any commands fail# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec pipenv run python3 -m app.main "$@"

http://www.ppmy.cn/server/170647.html

相关文章

大语言模型(LLM)微调技术笔记

图1:大模型进化树2 大模型微调 在预训练后,大模型可以获得解决各种任务的通用能力。然而,越来越多的研究表明,大语言模型的能力可以根据特定目标进一步调整。 这就是微调技术,目前主要有两种微调大模型的方法1&…

DeepSeek 全面分析报告

引言 DeepSeek 是一款由中国人工智能初创公司 DeepSeek 开发的大型语言模型 (LLM),于 2025 年 1 月发布,迅速成为全球人工智能领域的一匹黑马。DeepSeek 不仅在性能上可与 OpenAI、Google 等巨头的模型相媲美,而且其训练成本和运行效率都显著…

C++ 设计模式-模板方法模式

文件处理 #include <iostream>// 抽象基类&#xff1a;定义模板方法和抽象步骤 class DataProcessor { public:// 模板方法&#xff08;固定流程&#xff09;void Process() {OpenFile();ProcessData(); // 由子类实现CloseFile();}protected:virtual void ProcessData…

UE5网络通信架构解析

文章目录 前言一、客户端-服务器架构&#xff08;C/S Model&#xff09;二、对等网络架构&#xff08;P2P&#xff0c;非原生支持&#xff09;三、混合架构&#xff08;自定义扩展&#xff09;四、UE5网络核心机制 前言 UE5的网络通信主要基于客户端-服务器&#xff08;C/S&am…

KubeSphere平台安装

KubeSphere简介 KubeSphere 是一款功能强大的容器管理平台&#xff0c;以下是其简介&#xff1a; 1&#xff09;基本信息 开源项目&#xff1a;基于 Apache-2.0 授权协议开源&#xff0c;由 Google Go、Groovy、HTML/CSS 和 Shell 等多种编程语言开发。基础架构&#xff1a;…

如何查找 UBuntu的 arm版本

Ubuntu官网 https://ubuntu.com/ 如图&#xff1a; 点击 Tab栏的Download Ubuntu >> Server >> ARM >> 点击Download 24.04.2 LTS 即可 如果需要其他版本 点击 Alternative and previous releases 进入到如下页面选择想要的版本下载即可

【Linux】管道通信——命名管道

文章目录 命名管道什么是命名管道**命名管道 vs. 无名管道**如何创建命名管道 用命名管道实现进程间通信MakefileComm.hppServer.hppClient.hppServer.cppClient.cpp 效果总结 命名管道 什么是命名管道 命名管道&#xff0c;也称为 FIFO&#xff08;First In First Out&#…

PyTorch gather 方法详解:作用、应用场景与示例解析(中英双语)

PyTorch gather 方法详解&#xff1a;作用、应用场景与示例解析 在深度学习和自然语言处理&#xff08;NLP&#xff09;任务中&#xff0c;我们经常需要从高维张量中提取特定索引的数据。 PyTorch 提供的 torch.gather 方法可以高效地从张量的指定维度收集数据&#xff0c;广泛…