Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
HTTP Basics node_girls @ ੨ࢁ G’s Cafe
Slide 2
Slide 2 text
Twitter: @yosuke_furukawa ϦΫϧʔτςΫϊϩδʔζॴଐ γχΞιϑτΣΞΤϯδχΞ
Slide 3
Slide 3 text
HTTP Basics
Slide 4
Slide 4 text
લͷ NodeSchool ͰݴΘΕͨ ͜ͱ
Slide 5
Slide 5 text
͕͍͜͜͠Node.js /PEFKTͬͯॻ͍ͯΔͱOHJOYͷઃఆॻ͍ͯΔ Έ͍ͨͳؾʹͳΔΜͰ͢ΑͶʔ
Slide 6
Slide 6 text
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'); });
Slide 7
Slide 7 text
ٯʹݴ͏ͱ /PEFKTͬͯॻ͍ͯΔͱOHJOYͷઃఆॻ͍ͯΔ Έ͍ͨͳؾʹͳΔΜͰ͢ΑͶʔ )551ͷϨΠϠΛֶͿνϟϯεʂʂʂʂ
Slide 8
Slide 8 text
Node HTTP Basics
Slide 9
Slide 9 text
ͦͦ 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
Slide 10
Slide 10 text
ͦͦ 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 ϦΫΤετʹର͢Δϝλใ
Slide 11
Slide 11 text
ͦͦ 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/ͳͲ͕Δ
Slide 12
Slide 12 text
HTTP TCP ͷ্ʹ͋ΔΞϓϦ έʔγϣϯϨΠϠͷϓϩτίϧ http://www.linuxacademy.ne.jp/lablog/infrastructure/155/
Slide 13
Slide 13 text
͡Ό͋TCPͷϨΠϠͰHTTP ࡞ͬͯΈͨΒ͏গ͠ཧղ͕ ਂ·ΔͷͰʁ
Slide 14
Slide 14 text
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'); });
Slide 15
Slide 15 text
ϒϥβͰݟͯΈΔ
Slide 16
Slide 16 text
Ͱ͖ͨ
Slide 17
Slide 17 text
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'); });
Slide 18
Slide 18 text
ϒϥβͰݟͯΈΔ
Slide 19
Slide 19 text
Ͱ͖ͨ
Slide 20
Slide 20 text
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ͷ༰
Slide 21
Slide 21 text
ϚδϨε͢Δͱ
Slide 22
Slide 22 text
ͦΜͳ͜ͱ͠ͳ͍ 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'); });
Slide 23
Slide 23 text
ͨͩ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.
Slide 24
Slide 24 text
ΞϓϦέʔγϣϯϨΠϠͰࣄ ͍ͯ͠ΔͱΕ͕ͪ
Slide 25
Slide 25 text
தͰಈ͍ͯΔ͕Θ͔Δͱɺ ͜͏͍͏͜ͱ͕Ͱ͖Δ DEMO
Slide 26
Slide 26 text
HTTPϨΠϠͷಈ͖webͷ ಈ͖ͦͷͷɺڵຯΛ࣋ͱ͏ɺ ωοτϫʔΫϨΠϠʹɻ
Slide 27
Slide 27 text
Thank you.
Slide 28
Slide 28 text
ൃച