Skip to content

Instantly share code, notes, and snippets.

@dekokun
dekokun / dekokun.md
Last active Jun 29, 2021
これがdekokun(ISUCONメンバー自己紹介)
View dekokun.md
View test.go
package main
import (
"fmt"
"github.com/marcw/cachecontrol"
"strings"
)
func main() {
ccs := []string{"public", "max-age=315360000"}
View LICENSE
Copyright (c) 2017 dekokun
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
@dekokun
dekokun / README.md
Last active Sep 2, 2016
Varnishのテストとかに使えるいい感じにオウム返しするサーバ
View README.md
  • proxy的な働きをするサーバが後段に対してどのようなヘッダでリクエストを行うかを知りたい
  • 後段のサーバからどのようなヘッダが返った際にproxy的な働きをするサーバはどのような動きをするかを知りたい

という調査が簡単になるために作った。

機能

  • リクエストのクエリストリングがHTTPヘッダになる
    • 後段のサーバに任意のHTTPヘッダを返させてproxyの挙動を見ることができる
  • リクエストのHTTPヘッダはjsonになる
View client
[pid 62] 11:58:47.197343 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 <0.000003>
[pid 62] 11:58:47.197384 mmap(NULL, 262144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2f700c2000 <0.000005>
[pid 62] 11:58:47.197487 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0 <0.000010>
[pid 62] 11:58:47.197868 mmap(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f2f6e971000 <0.000008>
[pid 62] 11:58:47.197930 mprotect(0x7f2f6e971000, 4096, PROT_NONE) = 0 <0.000007>
[pid 62] 11:58:47.197973 clone(child_stack=0x7f2f6f170fb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f2f6f1719d0, tls=0x7f2f6f171700, child_tidptr=0x7f2f6f1719d0) = 64 <0.000020>
[pid 62] 11:58:47.198337 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 <0.000004>
[pid 62] 11:58:47.198376 futex(0x680688, FUTEX_WAIT, 0, NULLProcess 64 attached
<unfinished ...>
[pid 64] 11:
View client
[pid 64] 11:51:55.425444 epoll_wait(4, {{EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP, {u32=992570104, u64=139634674330360}}, {EPOLLIN|EPOLLOUT|EPOLLRDHUP, {u32=992569912, u64=139634674330168}}}, 128, 0) = 2 <0.000026>
[pid 64] 11:51:55.426580 getsockopt(18, SOL_SOCKET, SO_ERROR, [0], [4]) = 0 <0.000135>
[pid 64] 11:51:55.427115 getsockname(18, {sa_family=AF_INET, sin_port=htons(37902), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 <0.000006>
[pid 64] 11:51:55.427175 getpeername(18, {sa_family=AF_INET, sin_port=htons(8001), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0 <0.000003>
[pid 64] 11:51:55.428044 setsockopt(18, SOL_TCP, TCP_NODELAY, [1], 4) = 0 <0.000092>
[pid 64] 11:51:55.428570 write(18, "HEAD / HTTP/1.0\r\n\r\n", 19) = 19 <0.000042>
[pid 64] 11:51:55.429533 read(18, "2016-06-15 11:51:55.420574555 +0"..., 512) = 48 <0.000008>
[pid 64] 11:51:55.430129 read(18, "", 1488) = 0 <0.000005>
[pid 64] 11:51:55.430187 write(2, "2016/06/15 11:51:55 main.go:66: "..., 812016/06/15 11:51:5
View goroutine
<unfinished ...>
[pid 27] <... epoll_wait resumed> {{EPOLLIN, {u32=555602640, u64=140299957293776}}}, 128, -1) = 1
[pid 27] futex(0x661e50, FUTEX_WAKE, 1 <unfinished ...>
[pid 28] <... futex resumed> ) = 0
[pid 27] <... futex resumed> ) = 1
[pid 28] sched_yield( <unfinished ...>
[pid 27] accept4(3, {sa_family=AF_INET6, sin6_port=htons(49356), inet_pton(AF_INET6, "::ffff:127.0.0.1", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28], SOCK_CLOEXEC|SOCK_NONBLOCK) = 5
[pid 28] <... sched_yield resumed> ) = 0
[pid 27] epoll_ctl(4, EPOLL_CTL_ADD, 5, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=555602448, u64=140299957293584}} <unfinished ...>
[pid 28] futex(0x661d90, FUTEX_WAKE, 1 <unfinished ...>
@dekokun
dekokun / parrot.go
Created Mar 28, 2016
http requestしたらheaderをjsonで返してくれるやつ
View parrot.go
package main
import (
"encoding/json"
"log"
"net/http"
)
func rootHandler(w http.ResponseWriter, r *http.Request, cache bool) {
@dekokun
dekokun / pcurl.sh
Last active Oct 5, 2017
curlのproxy protocol対応
View pcurl.sh
#!/bin/bash
# [nabeken/mikoi: mikoi is a HAProxy's proxy protocol enabler for command line tools.](https://github.com/nabeken/mikoi) のインストールが必要なので注意
# usage: curlの代わりにpcurlを使うだけで動くはずです
last_option=${@:$#}
# 最後のオプションを:で分割して最後のものからpathを取り除いたものがportっぽい
portlike=$(echo $last_option | awk -F":" '{print $NF }' | awk -F"/" '{print $1 }')
# 最後のオプションを:で分割して最初のものがschemeっぽい
@dekokun
dekokun / interfaces
Created Oct 22, 2015
ラズパイの無線LAN運用に成功したconfigファイル
View interfaces
# /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0