Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
http_basics
Search
Yosuke Furukawa
PRO
February 21, 2017
Programming
2
990
http_basics
Node girls で話したhttp basics の話です
Yosuke Furukawa
PRO
February 21, 2017
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
140
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
Other Decks in Programming
See All in Programming
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.9k
Better Code Design in PHP
afilina
PRO
0
130
flutterkaigi_2024.pdf
kyoheig3
0
170
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
720
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
290
デザインパターンで理解するLLMエージェントの作り方 / How to develop an LLM agent using agentic design patterns
rkaga
9
950
Amazon Qを使ってIaCを触ろう!
maruto
0
420
我々のデザインシステムは Chakra v3 にアップデートします
shunya078
2
100
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
Facilitating Awesome Meetings
lara
50
6.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
120
Measuring & Analyzing Core Web Vitals
bluesmoon
4
140
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Git: the NoSQL Database
bkeepers
PRO
427
64k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
What's in a price? How to price your products and services
michaelherold
243
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Transcript
HTTP Basics node_girls @ ੨ࢁ G’s Cafe
Twitter: @yosuke_furukawa ϦΫϧʔτςΫϊϩδʔζॴଐ γχΞιϑτΣΞΤϯδχΞ
HTTP Basics
લͷ NodeSchool ͰݴΘΕͨ ͜ͱ
͕͍͜͜͠Node.js /PEFKTͬͯॻ͍ͯΔͱOHJOYͷઃఆॻ͍ͯΔ Έ͍ͨͳؾʹͳΔΜͰ͢ΑͶʔ
yes !!! love http layer !!!! const http = require('http');
const server = http.createServer((req, res) => { res.writeHead(200); res.end('Hello World'); }); server.listen(3000, () => { console.log('listening'); });
ٯʹݴ͏ͱ /PEFKTͬͯॻ͍ͯΔͱOHJOYͷઃఆॻ͍ͯΔ Έ͍ͨͳؾʹͳΔΜͰ͢ΑͶʔ )551ͷϨΠϠΛֶͿνϟϯεʂʂʂʂ
Node HTTP Basics
ͦͦ HTTP ͱ?? GET /hello.txt HTTP/1.1 User-Agent: curl/7.16.3 Host: www.example.com
Accept-Language: en, mi HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Accept-Ranges: bytes Content-Length: 51 Vary: Accept-Encoding Content-Type: text/plain Hello World! My payload includes a trailing CRLF. 3FRVFTU 3FTQPOTF
ͦͦ HTTP ͱ?? GET /hello.txt HTTP/1.1 User-Agent: curl/7.16.3 Host: www.example.com
Accept-Language: en, mi HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Accept-Ranges: bytes Content-Length: 51 Vary: Accept-Encoding Content-Type: text/plain Hello World! My payload includes a trailing CRLF. 3FRVFTU 3FTQPOTF 3FRVFTU-JOF શͯͷݩɺϝιουɺύεɺϓϩτ ίϧόʔδϣϯͰهड़ 3FRVFTU)FBEFS ϦΫΤετʹର͢Δϝλใ
ͦͦ HTTP ͱ?? GET /hello.txt HTTP/1.1 User-Agent: curl/7.16.3 Host: www.example.com
Accept-Language: en, mi HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Accept-Ranges: bytes Content-Length: 51 Vary: Accept-Encoding Content-Type: text/plain Hello World! My payload includes a trailing CRLF. 3FRVFTU 3FTQPOTF 3FTQPOTF-JOF ϓϩτίϧόʔδϣϯͱTUBUVTDPEF 3FTQPOTF)FBEFS ϨεϙϯεͷϝλใɺαΠζΒ ίϯςϯτλΠϓΒɻ 3FTQPOTF#PEZ Ϩεϙϯεͷຊମɺ͜͜ʹ)5.- +40/ͳͲ͕Δ
HTTP TCP ͷ্ʹ͋ΔΞϓϦ έʔγϣϯϨΠϠͷϓϩτίϧ http://www.linuxacademy.ne.jp/lablog/infrastructure/155/
͡Ό͋TCPͷϨΠϠͰHTTP ࡞ͬͯΈͨΒ͏গ͠ཧղ͕ ਂ·ΔͷͰʁ
TCPͷϞδϡʔϧnetΛ͏ const net = require('net'); const CRLF = '\r\n'; const
server = net.createServer((connection) => { console.log('connect!!'); connection.write('HTTP/1.1 200 OK' + CRLF); connection.write('Set-Cookie: test=123' + CRLF); connection.write(CRLF); connection.write('Hello world'); connection.end(); }); server.listen(3000, () => { console.log('listen on 3000'); });
ϒϥβͰݟͯΈΔ
Ͱ͖ͨ
Response header Λฦͯ͠ΈΔ const net = require('net'); const CRLF =
'\r\n'; const server = net.createServer((connection) => { console.log('connect!!'); connection.write('HTTP/1.1 200 OK' + CRLF); connection.write('Set-Cookie: test=123' + CRLF); connection.write(CRLF); connection.write('Hello world'); connection.end(); }); server.listen(3000, () => { console.log('listen on 3000'); });
ϒϥβͰݟͯΈΔ
Ͱ͖ͨ
TCPͷϞδϡʔϧnetΛ͏ const net = require('net'); const CRLF = '\r\n'; const
server = net.createServer((connection) => { console.log('connect!!'); connection.write('HTTP/1.1 200 OK' + CRLF); connection.write('Set-Cookie: test=123' + CRLF); connection.write(CRLF); connection.write('Hello world'); connection.end(); }); server.listen(3000, () => { console.log('listen on 3000'); }); 3FTQPOTF-JOF ϓϩτίϧόʔδϣϯͱTUBUVTDPEF 3FTQPOTF)FBEFS SFTQPOTFͷϝλใ 3FTQPOTF#PEZ SFTQPOTFͷ༰
ϚδϨε͢Δͱ
ͦΜͳ͜ͱ͠ͳ͍ Use express !!!! const app = express(); app.use('/static', express.static());
app.use('/foo', (req, res, next) => { res.send('foo'); }); app.use('/bar', (req, res, next) => { res.send('foo'); });
ͨͩHTTP͕Ͳ͏ͳͬͯΔ͔Λ ͓ͬͯ͘͜ͱॏཁ GET /hello.txt HTTP/1.1 User-Agent: curl/7.16.3 Host: www.example.com Accept-Language:
en, mi HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: Apache Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT ETag: "34aa387-d-1568eb00" Accept-Ranges: bytes Content-Length: 51 Vary: Accept-Encoding Content-Type: text/plain Hello World! My payload includes a trailing CRLF.
ΞϓϦέʔγϣϯϨΠϠͰࣄ ͍ͯ͠ΔͱΕ͕ͪ
தͰಈ͍ͯΔ͕Θ͔Δͱɺ ͜͏͍͏͜ͱ͕Ͱ͖Δ DEMO
HTTPϨΠϠͷಈ͖webͷ ಈ͖ͦͷͷɺڵຯΛ࣋ͱ͏ɺ ωοτϫʔΫϨΠϠʹɻ
Thank you.
ൃച